Scheme uses a single namespace for all variables, regardless of whether they are bound to functions or other types of values. Common Lisp separates the two, such that the identifier "hello" may refer to a function in one context, and a string in another.
(Note 1: This question needs an example of the above; feel free to edit it and add one, or e-mail the original author with it and I will do so.)
However, in some contexts, such as passing functions as parameters to other functions, the programmer must explicitly distinguish that he's specifying a function variable, rather than a non-function variable, by using #'
, as in:
(sort (list '(9 A) '(3 B) '(4 C)) #'< :key #'first)
I have always considered this to be a bit of a wart, but I've recently run across an argument that this is actually a feature:
...the important distinction actually lies in the syntax of forms, not in the type of objects. Without knowing anything about the runtime values involved, it is quite clear that the first element of a function form must be a function. CL takes this fact and makes it a part of the language, along with macro and special forms which also can (and must) be determined statically. So my question is: why would you want the names of functions and the names of variables to be in the same namespace, when the primary use of function names is to appear where a variable name would rarely want to appear?
Consider the case of class names: why should a class named FOO prevent the use of variables named FOO? The only time I would be referring the class by the name FOO is in contexts which expect a class name. If, on the rare occasion I need to get the class object which is bound to the class name FOO, there is FIND-CLASS.
This argument does make some sense to me from experience; there is a similar case in Haskell with field names, which are also functions used to access the fields. This is a bit awkward:
data Point = Point { x, y :: Double {- lots of other fields as well --} }
isOrigin p = (x p == 0) && (y p == 0)
This is solved by a bit of extra syntax, made especially nice by the NamedFieldPuns
extension:
isOrigin2 Point{x,y} = (x == 0) && (y == 0)
So, to the question, beyond consistency, what are the advantages and disadvantages, both for Common Lisp vs. Scheme and in general, of a single namespace for all values versus separate ones for functions and non-function values?