3
votes

In Chibi and CHICKEN, the following syntax-rules expression evaluates to a procedure:

(syntax-rules () ((_) #f))

Is this just an artifact of how these particular implementations are written? The Scheme language specs do not seem to call out syntax-rules as being able to evaluate to a value.


Update

It seems this may depend upon the version of Scheme?

From the R6RS Spec:

Semantics: An instance of syntax-rules evaluates, at macro-expansion time, to a new macro transformer by specifying a sequence of hygienic rewrite rules. A use of a macro whose keyword is associated with a transformer specified by syntax-rules is matched against the patterns contained in the s, beginning with the leftmost . When a match is found, the macro use is transcribed hygienically according to the template. It is a syntax violation when no match is found.

From the R5RS Spec and the R7RS Spec:

Semantics: An instance of syntax-rules produces a new macro transformer by specifying a sequence of hygienic rewrite rules. A use of a macro whose keyword is associated with a transformer specified by syntax-rules is matched against the patterns contained in the syntax rules, beginning with the leftmost syntax rule. When a match is found, the macro use is transcribed hygienically according to the template.

1
Where do you see the difference? In both specs, it evaluates to a transformer.uselpa
@uselpa - I think you're right, though it's curious that r6rs explicitly states it evaluates whereas r5rs and r7rs are more ambiguous.Justin Ethier
I see you changed the title (and a little bit the sense) of the question... in Scheme a procedure is a value, so yes, syntax-rules evaluates to a value, specifically a procedure.uselpa
It never occurred to me that I can write syntax-rules that are not within a define-syntax. ((syntax-rules () ((_) #f)) #'(x)) actually produces a value in #!racket :)Sylwester
@Sylwester - I'm not sure it's a good idea to write code that takes advantage of this, but I agree it's nice to know :)Justin Ethier

1 Answers

4
votes

syntax-rules returns a transformer, which is a procedure used by the expander to transform a syntactic extension into another syntactic extension. See also here.

So no, it's not a special form (this has disappeared from your question in the meantime), and yes, it evaluates to a value, since Scheme has first-class procedures and therefore procedures are values.

This is Scheme standard behaviour and not an implementation detail of Chicken or Chibi.