其结果仅取决于其参数的函数的名称是什么?
我正在编写一个玩具编译器,如果结果仅取决于参数的值,它可以优化函数调用。因此,像 xor 和 concatenate 这样的函数仅依赖于它们的输入,使用相同的输入调用它们总是会给出相同的输出。但是像 time 和 rand 这样的函数依赖于“隐藏”的程序状态,并且使用相同的输入调用它们可能会给出不同的输出。我只是想弄清楚区分这两种类型的函数的形容词是什么,比如“同构”或“可重入”之类的。有人可以告诉我我要找的词吗?
I'm writing a toy compiler thingy which can optimise function calls if the result depends only on the values of the arguments. So functions like xor and concatenate depend only on their inputs, calling them with the same input always gives the same output. But functions like time and rand depend on "hidden" program state, and calling them with the same input may give different output. I'm just trying to figure out what the adjective is that distinguishes these two types of function, like "isomorphic" or "re-entrant" or something. Can someone tell me the word I'm looking for?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您要查找的术语是Pure
The term you are looking for is Pure
我认为它被称为纯函数:
I think it's called Pure Function:
我想如果你用“纯函数”的话,你可以说这个形容词是“纯”。
我总是了解到,当参数始终相同时输出始终相同的函数称为“确定性”。就我个人而言,我认为这是一个更具描述性的术语。我猜想“纯函数”根据定义是确定性的,并且似乎纯函数也需要没有任何副作用。我认为并非所有确定性函数都是如此(只要相同参数的返回值始终相同)。
维基百科链接:http://en.wikipedia.org/wiki/Deterministic_algorithm
引用:
I guess you could say the adjective is "pure" if you go by "pure function".
I always learnt that a function whose output is always the same when the arguments are always the same is called "deterministic". Personally, I feel that that is a more descriptive term. I guess a "pure function" is by definition deterministic, and it seems a pure function is also required to not have any side-effects. I assume that that need not be the case for all deterministic functions (as long as the return value is always the same for the same arguments).
Wikipedia link: http://en.wikipedia.org/wiki/Deterministic_algorithm
Quote: