[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Issue: IN-SYNTAX (Version 1)
- To: CL-Cleanup@SAIL.Stanford.EDU
- Subject: Issue: IN-SYNTAX (Version 1)
- From: Kent M Pitman <KMP@STONY-BROOK.SCRC.Symbolics.COM>
- Date: Fri, 21 Oct 88 14:01 EDT
From my list of "pending issues" distributed at the last X3J13 meeting...
-----
Issue: IN-SYNTAX
References: None
Category: ADDITION
Edit history: 21-Oct-88, Version 1 by Pitman
Status: For Internal Discussion
Problem Description:
There is no way to bind read syntax within a file.
As a result, applications which require extended syntax of some sort
tend to globally modify the lisp readtable at compile and load time,
sometimes interfering with other modules and/or user interaction.
Conscientious developers often avoid the creation of any stylized
syntax because of its likely effect on parts of the environment which
don't really belong to the application developer. This need for
paranoia is probably contrived and the result of what amounts to
an oversight in the design of Common Lisp.
Proposal (IN-SYNTAX:NEW-FUNCTION):
Define that COMPILE-FILE and LOAD bind *READTABLE* to its current
value.
Introduce a new function IN-SYNTAX described as follows:
IN-SYNTAX readtable [Function]
Assigns *READTABLE* to the value of its argument, which must
be a readtable.
Like IN-PACKAGE, this function is specially recognized by the
compiler, and has the implicit effect of being within
(EVAL-WHEN (EVAL COMPILE LOAD) ...).
Rationale:
IN-SYNTAX would make it possible to select a particular syntax for the
remainder of a file, radically increasing the usefulness of readtables
in Common Lisp by localizing their effect.
Proposal (IN-SYNTAX:NEW-MACRO):
Define that COMPILE-FILE and LOAD bind *READTABLE* to its current
value.
Define a new macro IN-SYNTAX which has the effect of:
(DEFMACRO IN-SYNTAX (READTABLE)
`(EVAL-WHEN (EVAL COMPILE LOAD)
(SETQ *READTABLE* ,READTABLE)))
Incompatibly change the status of IN-PACKAGE from Function to Macro,
and describe it as:
(DEFMACRO IN-PACKAGE (PACKAGE-NAME)
`(EVAL-WHEN (EVAL COMPILE LOAD)
(SETQ *PACKAGE* (FIND-PACKAGE ,PACKAGE-NAME))))
Rationale:
IN-PACKAGE is intended as a declarative form anyway. Making it a macro
makes it unnecessary for the compiler to treat it specially.
IN-SYNTAX would make it possible to select a particular syntax for the
remainder of a file, radically increasing the usefulness of readtables
in Common Lisp by localizing their effect.
Proposal (IN-SYNTAX:MINIMAL):
Define that COMPILE-FILE and LOAD bind *READTABLE* to its current
value at the time
Rationale:
This is enough of a foothold to implement a more elaborate facility
for using readtables in a localized way.
Test Case:
-----File A-----
(DEFPACKAGE ACME ...)
(DEFVAR *ACME-SYNTAX* (COPY-READTABLE *READTABLE*))
----------------
-----File B-----
(IN-PACKAGE 'ACME)
(IN-SYNTAX *ACME-SYNTAX*)
(SET-MACRO-CHARACTER #\! ...)
(... !... ...)
----------------
(COMPILE-FILE "A")
(LOAD "A")
(COMPILE-FILE "B")
(LOAD "B")
At this point, "!" would still have its normal syntax globally,
although it was used locally within B in a different way.
Current Practice:
Presumably no one does this yet.
Cost to Implementors:
Very small.
Cost to Users:
None. This change is upward compatible.
Cost of Non-Adoption:
Readtables would continue to be hard to use in a clean way.
Benefits:
If people could use readtables safely, we might see more interesting
experimentation with read syntax.
Aesthetics:
A slight improvement to aesthetics by controlling what was formerly
an unbounded side-effect (modification to the global readtable).
Discussion:
Pitman supports (in order of decreasing preference) NEW-MACRO,
NEW-FUNCTION, and MINIMAL.