Re: Comments on draft #3 Marc Nieper-Wißkirchen 03 May 2020 09:06 UTC

Am So., 3. Mai 2020 um 00:11 Uhr schrieb John Cowan <xxxxxx@ccil.org>:

> I would be happy to see this macro.  I did a little investigation, and found that identifier-syntax is supported iff syntax-case is.  I had hoped that at least some Schemes supported it separately from syntax-case.

I bet that implementing identifier macros in any Scheme system is a
work of less than one day each. Already now every Scheme system
handles macro keywords, which are not in head position, (usually by
throwing an error). To make it usable in systems without
ER-MACRO-TRANSFORMER and SYNTAX-CASE, a top-level pattern in
SYNTAX-RULES, which just consists of an identifier has to be allowed
(as all other patterns won't match).

Supporting variable transformers (identifier macros that can be used
as an argument to SET!) may be more complicated, but these are not
necessary for the use cases discussed here.

IDENTIIFIER-SYNTAX is a syntax transformer, which, in the absence of
variable transformers, is just:

(define-syntax identifier-syntax
  (syntax-rules ()
    ((_ e)
     (syntax-rules ()
       ((_ x (... ...)) (e x (... ...)))
       (_ e)))))

The last rule of the inner SYNTAX-RULES is an example of the extended
top-level pattern I mentioned above.

Then you can do, say,

(define-syntax π (identifier-syntax 3.14159))

and without any help from the optimizer or the linker, π will behave
as the numerical constant.

Marc