[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug in define-syntax



MzScheme 103
Windows NT 4.0, sp4
Pentium 200

------------------------

    I was testing define-syntax (imported from
"synrule.ss"  in collects\mzlib).  It seems that
"hygienic" property does not quite work for define-syntax.

    I define "newlet" the way "let" is defined in R5RS's
appendix.  (see way below for code) at MzScheme's command
prompt.

    Similarly, I define "cond2" using define-syntax,
in accordance with R5RS's appendix's description
of cond, excep that I replace all occurences of "let" in its syntax-rule
 with "newlet", which I just defined (see way below for code).

    Then I run

    (newlet ((=> #f)) (cond (=> #t 'ok)))

    This generates invalid procedure error.
According to R5RS, it should produce 
the following:

    => ok.

On Petite Chez Scheme, the preceding produces the
desired result.

    If I run the following on MzScheme,

    (let ((=> #f)) (cond (=> #t 'ok)))

    I get 

    => ok.

    which is the desired result.

    Is define-syntax implemented
completely?  I was looking at 
synruler.ss, and it seems that the
pattern matching is not using lexical
information (that is, no binding information
is used).

---------------------------------------------------------------------------
---------------------------------------------------------------------------

    Here is the code used to test define-syntax.
(this is just right out of R5RS, with "newlet" replacing
let, and cond2 replacing cond.).


(define-syntax newlet
  (syntax-rules ()
    ((newlet ((name val) ...) b1 b2 ...)
     ((lambda (name ...) b1 b2 ...)
      val ...))))

(define-syntax cond2
   (syntax-rules (else =>)
      ((cond2 (else r1 r2 ...))
       (begin r1 r2 ...))
      ((cond2 (test => result))
       (newlet ((temp test))
        (if temp (result temp))))
      ((cond2 (test => result) c1 c2 ...)
       (newlet ((temp test))
        (if temp
     (result temp)
     (cond2 c1 c2 ...))))
      ((cond2 (test)) test)
      ((cond2 (test) c1 c2 ...)
       (newlet ((temp test))
          (if temp
       temp
              (cond2 c1 c2 ...))))
      ((cond2 (test r1 r2 ...))
       (if test (begin r1 r2 ...)))
      ((cond2 (test r1 r2 ...) c1 c2 ...)
       (if test
    (begin r1 r2 ...)
    (cond2 c1 c2 ...)))))