On Wed, 4 May 2011, Andrzej wrote:

On Wed, May 4, 2011 at 12:07 PM, Andre van Tonder <[email protected]> wrote:

Be that as it may, let me give another example. ?I am pretty sure that the
the spec requires the following to evaluate to 1.

(define-syntax nonfalse-identity
?(syntax-rules ()
? ?((_ x)
? ? (cond (x => (lambda (x) x))))))

(let ((else 1))
?(nonfalse-identity else)) ?====> 1

but I think your implementation will give the wrong result here (or an
error).

You're right. An implementation conforming to R5RS should fail here.
'=>' is not allowed in the 'else' clause.

No, I claimed that a correct implementation must sucxceed and give 1. Macro hygiene reequires it to. See the explanation below.

Here is anotehr example, which evaluates a given expression (in case it has
side effects) and returns 1. ?It is a silly way of doing this, but there is
no doubt that the spec requires the answer to be 1.

(define-syntax map-to-identity
?(syntax-rules ()
? ?((_ exp)
? ? (cond (#t exp 1)))))

(let ((=> 0))
?(map-to-identity =>)) ? ======> 1

Ditto. A clause with '=>' must contain a single operand procedure (not '1').

Again, I calim that teh spec requires the answer to be 1, again because of macro hygiene. I would suggest that you reread the section on macro expansion:

   If a macro transformer inserts a binding for an identifier (variable or
   keyword), the identifier will in effect be renamed throughout its scope to
   avoid conflicts with other identifiers.

In other words, the => in

   (let ((=> 0))
     (map-to-identity =>))

is renamed during expansion to become (a lambda expression) equivalent to

   (let ((g0 0))
     (map-to-identity g0)

where g0 is a generated identifier, all before MAP-TO-IDENTITY is even encountered. This then expands to the equivalent of

   (let ((g0 0))
     (cond (#t g0 1)))

which evaluates to 1.

So the relevant part of the spec that you were missinbg had to do with the expansion algorithm.
_______________________________________________
Scheme-reports mailing list
[email protected]
http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports

Reply via email to