函数是一种变量吗? [英] Is function a sort of variable?

查看:420
本文介绍了函数是一种变量吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾经认为变量是数据和函数的数据映射,它们在一般意义上是不同的。但是,在阅读某些语言标准(即Haskell)时,我发现标准似乎​​将它们组合在一起(请参阅2.4和10.5以及这个问题)。



所以,我有几个关于变量和函数的问题(除问题标题外):


  1. 它们的语言特定含义(例如在Haskell中)也符合它们在一般意义上的含义?

    (即前者是后者的一个子集)或者一个含义具有一些其他的补集?


  2. 变量的定义是什么?

    有一个类型是否定义了一个是一个变量?

  3. 我认为函数的概念具有以下(结构化)方面。

    其中一个子方面确实有一个类型,做它使函数变量?

    函数(具有方面:)


    • 函数说明符/标识符:指定哪个函数参考

    • 功能/映射:指定该功能的功能,即将哪些数据映射到哪些数据。 (具有以下方面:)


      • 映射类型:例如在Haskell中,一个函数可能具有(a - > b)类型。


    • >




      编辑

      / p>

      读完所有答案后(他们真的很棒),我意识到我的疑惑是由于操作符和函数之间的混淆所致:我错误地混合了这两件事向上。
      正确的理解应该是:运营商只是一个指向功能的符号



      允许我借用E-Lisp Intro的解释,我发现它非常有用:


      我们可以根据我们讨论的内容阐述Lisp的另一个特性,即
      远 - 一个重要的特性:象+这样的符号本身不是计算机携带的指令集
      出。相反,这个符号可能被用作
      作为查找定义或指令集的一种方式。我们看到的是名称
      ,通过它可以找到说明。人们的名字以相同的方式工作。
      我可以称为'鲍勃';然而,我不是字母'B','o','b',而是,或者是,
      是一种始终与特定生命形式相关的意识。名称是
      不是我,但它可以用来指我。

      不,函数不是一个变量。函数是一个值(在Haskell,Python,JavaScript,Clojure和许多其他语言中,但不是所有语言)。变量(或符号,标识符)可以引用或绑定为值。因此,变量/符号/标识符可以引用一个函数。

      您的子问题:


      1. 恕我直言,是的。例如,数学中有更高阶的逻辑。数学中也有常用的高阶函数,如衍生物,积分和求和。恕我直言,变量不是由拥有一个类型来定义的 - 值也有类型,尽管可能有不同的含义 - 而是由它们的类型代表(代表,指代,指向)别的东西的能力。

        什么是变数?应该被视为一个单独的问题,因为根据我的理解,一个确切的答案令人惊讶地很复杂,根源于数学史。

      2. 不,事实上,函数具有类型并不意味着它们是变量。

      仔细阅读您的问题,我认为有两个单独的问题这里:1)什么是什么? 2)不同事物之间的相似性。因此,尽管您已经确定了变量和函数之间的相似性,但这并不意味着函数是变量,反之亦然。假设你有一个带有两个类的Java程序, Variable 函数,并且您想知道如何在它们之间创建继承关系。我的回答是,我不认为有一个 - 既没有一个从另一个继承 - 但你不需要一个,因为你可以创建捕获你感兴趣的方面的接口,然后实现这些接口为这两个类。


      I used to think variable as data and function as data mappings, and they are distinct things in general sense. However, when reading some language standard (namely, Haskell), I found that the standard appears to group them together (see 2.4, and 10.5, and this question ).

      So, I have a few questions regarding variable and function (in addition to the question title):

      1. Does their language-specific meaning (e.g. in Haskell) also conform to their meaning in general sense?
        (i.e. The former is a subset of the latter.) Or one meaning has some complements set of the other?
        (By "in general sense" I mean in mathematics.)
      2. What is the definition of "variable"?
        Does "having a type" define one thing to "be a variable"?
      3. I thought the concept "function" has below (structured) aspects.
        One of its sub-aspects does have a type, so, does it makes "function" a variable?
        Function (has aspects of:)
        • Function specifier / identifier: specifies which function to refer
        • Functionality / mapping : specifies what the function does, i.e. it maps what data to what. (has aspects of:)
          • Mapping type: e.g. in Haskell, a function may has the type of (a -> b)


      Edits:

      Summary

      After reading all the answers (they are really great), I realized that my doubts was due to confusion between "operator" and "function": I wrongly mixed the two things up. The correct understanding should be: an "operator" is just a symbol that refers to a "function".

      Allow me to borrow the explanation from E-Lisp Intro that I found very helpful:

      We can articulate another characteristic of Lisp based on what we have discussed so far—an important characteristic: a symbol, like +, is not itself the set of instructions for the computer to carry out. Instead, the symbol is used, perhaps temporarily, as a way of locating the definition or set of instructions. What we see is the name through which the instructions can be found. Names of people work the same way. I can be referred to as ‘Bob’; however, I am not the letters ‘B’, ‘o’, ‘b’ but am, or was, the consciousness consistently associated with a particular life-form. The name is not me, but it can be used to refer to me.

      解决方案

      No, a function is not a variable. A function is a value (in Haskell, Python, JavaScript, Clojure, and many other languages, but not in all languages). A variable (or symbol, identifier) can refer or be bound to a value. Therefore, a variable/symbol/identifier can refer to a function.

      Your sub-questions:

      1. IMHO, yes. There are higher-order logics in mathematics, for example. There are also common higher-order functions used in mathematics such as derivatives, integrals, and summation.

      2. IMHO, variables aren't defined by "having a type" -- values also have types, albeit possibly in a different sense -- but rather by their ability to represent (stand in for, refer to, point to) something else.

        "What is a variable?" should probably be asked as a separate question, because a precise answer is surprisingly complicated and rooted in the history of mathematics, from what I understand.

      3. No, the fact that functions have types does not mean that they are variables.

      Reading your question more carefully, I think there are two separate issues here: 1) what "is" something? and 2) similarities between different things. So while you've identified similarities between variables and functions, that doesn't mean that functions "are" variables or vice versa. I'll try to illustrate this with a Java example (bear with me here!): suppose you have a Java program with two classes, Variable and Function, and you want to know how to create an inheritance relationship between them. My answer is that I don't think there is one -- neither one inherits from the other -- but you don't need one because you can instead create interfaces capturing the aspects that you're interested in, and then implement those interfaces for both classes.

      这篇关于函数是一种变量吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆