[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
On keywords, symbols, and reader options
From: |
Matthias Koeppe |
Subject: |
On keywords, symbols, and reader options |
Date: |
15 Jun 2001 16:41:15 +0200 |
User-agent: |
Gnus/5.0808 (Gnus v5.8.8) Emacs/20.6 |
I find Guile's treatment of keywords confusing and counter-productive.
In this article, I first discuss a few issues; then I propose a
change.
There are two ways the reader can be configured with respect to
keywords. Normally, ":IDENTIFIER" is read as a symbol; if (read-set!
keywords 'prefix) is in force, it is read as a keyword. "#:IDENTIFIER"
is always read as a keyword.
The macro systems of Scheme systems are powerful enough to define new
syntaxes: In just a few lines, for instance, I can make other Scheme
systems understand Guile's module system syntax, define-module et al.
However, the reader is typically not as flexible: MzScheme, for
instance, cannot read #:IDENTIFIER, signalling a reader error; the
reader cannot be extended from Scheme to understand this notation.
Thus, in my project, I avoid the non-portable #:IDENTIFIER syntax and
stick to the :IDENTIFIER syntax. (Since those are ordinary symbols in
MzScheme, I make them self-evaluating and do everything else using
macros.) In Guile, I use (read-set! keywords 'prefix).
However, this breaks a lot of code on the Guile side. Earlier, I sent
patches against SRFI-19.scm because it tried to use :OPTIONAL as an
ordinary symbol which breaks when (read-set! keywords 'prefix) is in
force.
SRFI-9 also breaks because it expects an ordinary symbol as the first
argument to the DEFINE-RECORD-TYPE macro. (I have a workaround here,
but I refrain from sending a patch at the moment.)
boot-9.scm also includes code for DEFINE-MODULE that handles the two
ways the :IDENTIFIER syntax can be read, depending on the user's
setting.
Another thing: If I choose to use the :IDENTIFIER syntax in my Scheme
code for the above portability issues and distribute some of my
modules as a package, I have two choices:
* Either tell the user to (read-set! keywords 'prefix) before loading
my sources or using my modules (yuck!)
* Or, temporarily set the reader options so that Guile can parse my
code. That is, get the 'keywords setting, then (read-set! keywords
'prefix) at the beginning and restore the setting at the end. If
the load fails, the setting won't be restored.
I don't really understand why keywords need to be different from
symbols; this is causing all the trouble, all the extra code. So here
is my suggestion:
1. Remove the notion of keywords; just make them symbols with a
leading colon.
2. Introduce a module variable KEYWORD-STYLE, which can be one of #f
and 'prefix. If set to prefix, all symbols starting with a colon
are self-evaluating.
3. Add a DEFINE-MODULE keyword argument :KEYWORD-STYLE which sets the
module variable.
4. For backwards compatibility, make a reader macro #: which
constructs a symbol with a leading colon.
5. Advertise the use of the :IDENTIFIER syntax, rather than
#:IDENTIFIER.
What do you think?
--
Matthias Köppe -- http://www.math.uni-magdeburg.de/~mkoeppe
- On keywords, symbols, and reader options,
Matthias Koeppe <=