From: William G. Dubuque
Subject: redefining meaning of colon in symbols [was:  syntax of Re: keywords in Common Lisp and (MIT) Scheme]
Date: 
Message-ID: <WGD.95Jan26103414@martigny.ai.mit.edu>
References: <·····················@naggum.no>
Distribution: 

  From: Erik Naggum <····@naggum.no>
  Date: 25 Jan 1995 07:05:19 UT

  is there a reasonable way I can convince the Lisp reader that a trailing
  colon is not really a major disaster, but largely equivalent to a keyword?

Yes, this can be accomplished while still preserving the
efficiency of the built-in CL tokenizer and reader, but it is not
simple (in spite of Steele's comment on p. 510 of CLtL2 that "The
reader is also parameterized in such a way that it can be used as
a lexical analyzer for a more general user-written parser.").

First, define ':' as a terminating macro char that returns a
single value that is a unique object of your choice that will be
used to denote the occurrence of colons in objects that have been
read.

Next, you must redefine every macro character in your language
that may read objects containing your new style symbols.

For example, for the '(' macro char, you must wrap its definition
so that you recursively walk the list that it reads and scan for
the unique colon markers, and do whatever you desire to them and
any preceding symbol. You can optimize this so that the walk
need only be done if a colon was actually encountered.

For quote, backquote and comma macro chars: if they read a
symbol, you need to peek ahead for a possible ':'.

And similarly for any other macro chars in your language.

The only performance hit you take is the cost of the above macro
char wrappers, which should be negligibile since in all cases you
can call the built-in macro char and then perform a quick
analysis on its result.

Its unfortunate that there is no clean way to do this in CL.
With a little more parameterization, the reader could have been
much more general.

-Bill