cisco / ChezScheme

Chez Scheme
Apache License 2.0
6.95k stars 982 forks source link

behavior of `eval-when` differs from description in CSUG #664

Open symingz opened 1 year ago

symingz commented 1 year ago

Given a file helloz.ss with the following content:

(eval-when (load)
  (define-syntax mx
    (let ()
      (display "hello from mx")
      (newline)
      (lambda (stx)
        (syntax-case stx ()
          [(_) #'1000])))))

Running (compile-file "helloz.ss") from a fresh ChezScheme (9.5.8) interactive top level gives the following output:

compiling helloz.ss with output to helloz.so
hello from mx

This indicates that the define-syntax form is evaluated during compilation despite the absence of compile in the situation list of eval-when, which contradicts the description of eval-when in CSUG.

melted commented 1 year ago

I believe this behavior is as described in the documentation of eval-when. It's a bit dense but as I understand it the difference between load and compile is what happens when the .so is subsequently loaded. Then eval-when with load will be evaluated, but not compile. But both will fire in the initial compilation.

symingz commented 1 year ago

I don't think so. Based on the precise description of eval-when on page 354 and 355, define-syntax, being a compile-time form, has {L, C} as its state set if it is not inside eval-when. Inside an eval-when with (load) as the situation list, the state set changes to {L/load, C/load}, which, according to the table on page 355, is {L, -}, or simply {L}. A form with a state set of {L} should not be evaluated at compile time.