chicken-hackers
[Top][All Lists]
Advanced

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

Fwd: Comments on draft #3


From: John Cowan
Subject: Fwd: Comments on draft #3
Date: Sun, 3 May 2020 12:57:00 -0400

This is the second of two patches that allow macros to be expanded when they appear in operand position.  It allows a syntax-rules pattern to be a single variable rather than a list; this rule will be used when the macro keyword is in operand position.

---------- Forwarded message ---------
From: Marc Nieper-Wißkirchen <address@hidden>
Date: Sun, May 3, 2020 at 12:10 PM
Subject: Re: Comments on draft #3
To: John Cowan <address@hidden>
Cc: <address@hidden>, Lassi Kortela <address@hidden>


With the attached patch, SYNTAX-RULES macros now allow a single identifier as a top-level pattern, which matches the whole form:

(define-syntax foo
  (syntax-rules ()
    (x (begin (display 'x) (newline)))))

foo ;Expands into code that displays "foo".

Am So., 3. Mai 2020 um 17:51 Uhr schrieb Marc Nieper-Wißkirchen <address@hidden>:
Am So., 3. Mai 2020 um 11:06 Uhr schrieb Marc Nieper-Wißkirchen <address@hidden>:

[...]
 
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).

To prove that my bet is not insubstantial, I have attached a patch for the Chicken implementation of Scheme. With the patch (it may need to be polished by the maintainers of Chicken), transformers associated with keywords are now also invoked when the keyword is not in head position.

The following example will expand `foo' into #f and display "foo" on the console.

(define-syntax foo
  (er-macro-transformer
    (lambda (x r c)
      (display x)
      (newline)
      #f))

foo

Although I have just installed the Chicken source code, which is still alien to me, it took me less than two hours to get the thing done.  I shouldn't be a hurdle for other implementations as well.

Marc

Attachment: 0002-Add-a-single-identifier-top-level-pattern-to-syntax-.patch
Description: Source code patch


reply via email to

[Prev in Thread] Current Thread [Next in Thread]