Subject: Re: bug#11988: eval-case redefinition?

From: [email-masked] (Ludovic Courtès)
Date: Sat, 06 Oct 2012 23:24:19 +0200

Hi,

Sorry for the delay.

Daniel Llorens <[email-masked]> skribis:

> I was cleaning up an old script which goes like this:
>
> (define (eval-case ...)  ...  val)
>
> (define var (eval-case ...))
>
> This worked from the REPL, but when loading the file with (load
> "script"), var was always #<unspecified>. It turns out that (my)
> eval-case is never executed in this case.

It turns out that ‘eval-case’ is a macro, and it gets macro-expanded in
the RHS of ‘define var’ above.

This is the same situation as:

--8<---------------cut here---------------start------------->8---
(define-syntax-rule (foo x) (- x))
(define (foo x) x)

(pk 'foo (foo 42))  ; prints -42
--8<---------------cut here---------------end--------------->8---

“Expansion process” in R6RS seems to suggest that this is a bug:

  For the right-hand side of the definition of a variable, ex-
  pansion is deferred until after all of the definitions have
  been seen. Consequently, each keyword and variable refer-
  ence within the right-hand side resolves to the local bind-
  ing, if any.

Hmmm...  Thoughts?

Ludo’.