Question

Here is my little program:

(let-syntax ((alpha (lambda (x)
                      (list (syntax quote)
                            (list)))))
  (alpha))

And guile executes it, and returns (). But mit-scheme outputs the following:

;Syntactic binding value must be a keyword: alpha
;To continue, call RESTART with an option number:
; (RESTART 1) => Return to read-eval-print level 1.

Why?

(my version is: Release 9.1 || Microcode 15.3 || Runtime 15.7 || SF 4.41 || LIAR/i386 4.118 || Edwin 3.116)

Was it helpful?

Solution

MIT Scheme only provides syntax-rules, syntactic closures, and explicit renaming for defining syntax transformers. For the latter two, you want either sc-macro-transformer or the er-macro-transformer forms. If you want to use syntax objects, you'll need to use an implementation that supports syntax objects (which usually comes with syntax-case) such as Racket or Guile.

By the way, even in a language with syntax objects your macro definition may not work because you're returning a list from your transformer instead of syntax. Also, the web page you linked to is a pretty old standard. You might want to read a more recent source on macros, such as TSPL4.

OTHER TIPS

The documentation you linked to demonstrates explicitly that you absolutely must use syntax-rules with let-syntax. Here is the exact syntactic contract.

    <macro block> ==>
          (let-syntax (<syntax spec>*) <body>)
         | (letrec-syntax (<syntax spec>*) <body>)
    <syntax spec> ==> (<keyword> <transformer spec>)
    <transformer spec> ==>
          (syntax-rules (<identifier>*) <syntax rule>*)

In accordance with the specifications, using anything other than syntax-rules cannot be expected to run without error. The only reason this generates an error in MIT Scheme and not in Guile is because of MIT Scheme's more prolific application of exceptions (that is, MIT Scheme's let-syntax specifically looks to ensure you gave it syntax-rules). It is simply not valid R4RS code, and shouldn't work in any R4RS compatible Scheme implementation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top