What is the difference between a variable and a symbol in LISP?

前端 未结 7 1528
时光说笑
时光说笑 2021-01-31 09:59

In terms of scope? Actual implementation in memory? The syntax? For eg, if (let a 1) Is \'a\' a variable or a symbol?

7条回答
  •  爱一瞬间的悲伤
    2021-01-31 10:36

    A symbol is a name for a thing. A variable is a mutable pointer to a mutable storage location.

    In the code snippet you showed, both let and a are symbols. Within the scope of the let block, the symbol a denotes a variable which is currently bound to the value 1.

    But the name of the thing is not the thing itself. The symbol a is not a variable. It is a name for a variable. But only in this specific context. In a different context, the name a can refer to a completely different thing.

    Example: the symbol jaguar may, depending on context, denote

    • OSX 10.2
    • a gaming console
    • a car manufacturer
    • a ground attack military jet airplane
    • another military jet airplane
    • a supercomputer
    • an electric guitar
    • and a whole lot of other things
    • oh, did I forget something?

提交回复
热议问题