chicken-users
[Top][All Lists]
Advanced

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

[Chicken-users] define-compilter-syntax / define-syntax -- a quastion //


From: Jörg F . Wittenberger
Subject: [Chicken-users] define-compilter-syntax / define-syntax -- a quastion // posibly a bug
Date: 26 Sep 2011 20:16:02 +0200

Hi,

I've got a question wrt. the scope of definitions in chicken core units:

How does it come that some definitions are visible at top level eventually,
while some are used in the compilation unit only?

E.g., SRFI-1.  It lives in it's own file.  irregex defines some simplified
versions too.  How does it come that those do not end up in the global envt?


So much for the question.  While I tried to answer that to myself, I've
got this monkey-typing-idea: "make sure it does not" -> don't define e.g.
"fold" as a procedure in irregex.  So I commented it out in irregex-core.scm
and wrote this into irregex.scm:

(define-compiler-syntax fold
 (syntax-rules ()
   ((_ kons knil lst)
    (let lp ((ls ls) (res knil))
      (if (null? ls)
           res
           (lp (cdr ls) (kons (car ls) res)))))))


This results in a strange error message hinting towards an expansion problem:


        (let2940 lp2941 (((cdr sre) (cdr sre))
                        (res2942 (+ sum (case (car sre)
(($ submatch => submatch-named) 1) ((dsm) (+ (cadr sre) (caddr sre))) ((posix-string) (sre-count-submatches (string->sre (cadr sre)))) (else 0))))) (if2943 (null?2944 (cdr sre)) res2942 (lp2941 (cdr2945 (cdr sre)) (count (car2946 (cdr sre)) res2942))))


Resulting from:


(define (sre-count-submatches sre)
 (let count ((sre sre) (sum 0))
   (if (pair? sre)
       (fold count
             (+ sum (case (car sre)
                      (($ submatch => submatch-named) 1)
                      ((dsm) (+ (cadr sre) (caddr sre)))
                      ((posix-string)
                       (sre-count-submatches (string->sre (cadr sre))))
                      (else 0)))
             (cdr sre))
       sum)))


Given the expansion in the error message I tried changing my syntax slightly:


(define-compiler-syntax fold
 (syntax-rules ()
   ((_ kons knil lst)
    (let lp ((ls lst) (res knil))
      (if (null? ls)
           res
           (lp (cdr ls) (kons (car ls) res)))))))


This one compiles and runs.

But it looks as if the macro expansion where not hygienic.
Otherwise those two definitions would IMHO be equivalent.

Bet regards

/Jerry
....



reply via email to

[Prev in Thread] Current Thread [Next in Thread]