tags:

views:

161

answers:

3

I'm rather confused about this.

And what's their relationship(e.g., how one can be used in the context of the other)? Much thanks!!

A: 

The concept of symbols is a little bit hard to understand. (Even I'm not sure I got it :) )

You can look at symbols as special variables which behave like constants. There is only one instance in memory, no matter how often you used it.

The benefits are conserving memory and one can see if a value is used in a constant-like manner. (Improves code readability)

You can do similar things in C/C++ with typdef, in Java with static final or in Delphi/Pascal/VB with const, but be careful, in those and many other languages "symbol" means something different.

DR
+3  A: 

Is this what you are looking for ?

A symbol is basically just an object with four fields:

  • a name (a string),
  • a value (some Lisp object),
  • a function (some Lisp object), and
  • a property list (usually a list of alternating keyword/value pairs).

What makes symbols special is that there is usually only one symbol with a given name, and the symbol is referred to by name. This makes a symbol a convenient way of calling up data by name, i.e. of implementing variables. (The variable's value is stored in the value slot.)

Similarly, functions are referenced by name, and the definition of the function is stored in a symbol's function slot. This means that there can be a distinct function and variable with the same name.

The property list is used as a more general mechanism of associating additional values with particular names, and once again the namespace is independent of the function and variable namespaces.

VonC
+1  A: 

Simply put, a variable is a binding between a symbol and a value. The symbol is the name of the variable. When a bound symbol (ie. a variable name) is evaluated, the variable value is returned,

You can also use symbols which are not variables, ie. names which are not bound to a value. You cannot evaluate an unbound symbol though.

In Lisp-2's a symbol can be bound to both a value and a function at the same time, The context defines if the result of evaluating the symbol is the value or the function.

JacquesB