Scheme question

symbols are symbols. tokens, abstract unique objects. why you think to them as pointers? they are objects. I think you make confusion with variables. symbols are used to identify variables in an environment. One could use numbers or strings to do the same thing but symbols are more convenient. C/Python do not have similar entities. I guess what is nearer would be some Python singleton class, a symbol is something which is uniquely identified by its printed form, so there can only be one symbol with a given representation, while strings a priori can be different, in the sense that “abc” and “abc” while being equal in some sense, could be just two strings allocated in different parts of memory, so represented by different pointers (in C). the symbol 'abc and the symbols 'abc are the same symbol in every sense. They are useful as keys in maps, and in particular to retrieve values in an environment. They are the “names” of certain variables, i.e. certain mutable container for other scheme objects.

Note that in scheme every expression has a value. An expression is a list made of other lists or atoms, atoms are symbols, strings, chars, numbers, booleans. Booleans, chars, integers, string are self-evaluating, meaning that the value of an expression consisting only of one of them is itself. The value of a symbol is defined from the environment (it is looked up in a table and its value is the associated object, i.e. it acts as the name of a variable). The value of a list expression is the result of calling the function which is the value of the expression corresponding to the first element with parameters which are the values of the expressions corresponding to the other elements of the list. If you want a symbol as a value, you have to avoid it to be interpreted as the location of a variable, for this we use quote, i.e. the symbol value abc is expressed with the expression 'abc. The same for lists: if you want a list then you have to quote a list expression '(a b c), in this case a list of symbols, while this: '("a" "b" "c") is a list of strings and this: (a b c) is evaluated as the function a called with parameters b and c. This is essentially all that Scheme is (apart from macros).

1 Like