[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

2 namespaces & a complement to #' notation



The recent article by Kers (Christopher Dollin) concerning the two-namespace
issue and Pop gives me an excuse for bringing up a related item.  I'll be
surprised if this idea has not been discussed before, but I've only been on
this list for a year, so I haven't seen it.  Like Kers, I recently
read "Issues of Separation in Function Cells and Value Cells" by Gabriel &
Pitman.  I have been unable to resolve my personal preferences on this
issue.  I like the elegance and notational simplicity of a single
namespace, but I also find it convenient that I needn't worry much about
selecting names for lexical variables in Common Lisp.  I might find a
single namespace easier to accept were it not for a mere handful of very
useful functions whose names happen to be very useful variable names (e.g.,
COUNT, LIST, STRING, and GET-SETF-METHOD-MULTIPLE-VALUE :-).

But perhaps it is too late to change Common Lisp to a single-namespace Lisp
dialect.  If so, we should look for ways to mitigate the problems of having
two namespaces.  One problem is the awkwardness of having to use FUNCALL to
invoke a function which is the (ordinary) value of a variable or other
form.  This is illustrated by Gabriel & Pitman with definitions of the Y
operator (or paradoxical combinator) of lambda calculus.  For a language
with a single namespace, the definition given is

   (defun y (f)
    ((lambda (g) (lambda (h) ((f (g g)) h)))
     (lambda (g) (lambda (h) ((f (g g)) h)))))

For a language with separate function and value namespaces, the definition
is more complex:

   (defun y (f)
    ((lambda (g) #'(lambda (h) (funcall (funcall f (funcall g g)) h)))
     #'(lambda (g) #'(lambda (h) (funcall (funcall f (funcall g g)) h)))))

(Note: My copy of the Gabriel & Pitman paper omits the second #', but it is
needed to prevent attempted evaluation of the lambda expression.)

To simplify the notation of this definition, we could alter the evaluation
of forms to allow the definition a macro character, perhaps #@, to
complement the #' syntax.  A form preceded by #@ in the function position
would have its ordinary value used as the function to be applied.  The
definition of Y would then be shorter, if not prettier:

   (defun y (f)
    ((lambda (g) #'(lambda (h) (#@(#@f (#@g g)) h)))
     #'(lambda (g) #'(lambda (h) (#@(#@f (#@g g)) h)))))

The effect of this change can be obtained in Common Lisp by the following
inelegant technique.  Define ORDINARY-FUNCTION-VALUE-READER to convert a #@
form into a lambda-expression which applies the value of the form to its
arguments, and install this function to handle the #@ macro character:

   (defun ordinary-function-value-reader (stream subchar arg)
     (declare (ignore subchar arg))
     `(lambda (&rest args) (apply ,(read stream t nil t) args)))

   (set-dispatch-macro-character #\# #\@ #'ordinary-function-value-reader)

This works, but a better implementation would allow some new expression
such as (ordinary-value <form>) to be used in the function position,
analogous to the current use of lambda expressions.

Has this approach been considered?  Is it just too ugly to get much
support?  Or am I missing a serious problem?

Jim Hassett