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

前端 未结 7 1516
时光说笑
时光说笑 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:46

    Symbol and variable are 2 different things. Like in mathematic symbol is a value. And variable have the same meaning than in mathematic.

    But your confusion came from the fact that symbol are the meta representation of a variable.

    That is if you do

    (setq a 42)
    

    You just define a variable a. Incidentally the way common lisp store it is throw the structure of a symbol.

    In common lips symbol is a structure withe different property. Each one can be access with function like symbol-name, symbol-function...

    In the case of variable you can access his value via ssymbol-value

    ? (symbol-value 'a)
    42
    

    This is not the common case of getting the value of a.

    ? a
    42
    

    Note that symbols are self evaluating that mean that if you ask a symbol you get the symbol not the symbol-value

    ? 'a
    A
    

提交回复
热议问题