[plt-scheme] macro in modules

From: Ivanyi Peter (pivanyi at freemail.hu)
Date: Tue Jul 25 04:37:40 EDT 2006

Hi,

I still have my little defun macro. :-) I would like to have
it in a module,
however it works differently inside the module and outside.

When I execute the module and require it then I get:

(begin (define (a w) (let* ((q nil) (e nil)) (+ w 1))) 'a)

which is correct, but if I try out the last line after
requiring the module 
it does not work as it gives me:

(begin (define (a w / q e) (let* () (+ w 1))) 'a)

The parameter list is not processed any more. (?)
Is there any way to ensure that this macro will work in the
same way
inside and outside the module?

Thanks for any help.

Best regards,

Peter Ivanyi

; ----------------------------------- def.scm
--------------------------------------

(module def mzscheme
  (provide defun)

(define-syntax defun
  (letrec
      ((get-args
        (lambda (args)
          (syntax-case args (/)
            (() (syntax ()))
            ((/ a1 ...) (syntax ()))
            ((a2 a3 ...) (cons (syntax a2) (get-args (syntax
(a3 ...))))))))
       (get-local-init
        (lambda (args)
          (syntax-case args ()
            (() (syntax ()))
            ((a2 a3 ...) (cons (list (syntax a2) 'nil)
                               (get-local-init (syntax (a3
...)))))
            ((a1 ...) (list (list (syntax (a1 ...)) 'nil))))))
       (get-locals
        (lambda (args)
          (syntax-case args (/)
            (() (syntax ()))
            ((/ a1 ...) (get-local-init (syntax (a1 ...))))
            ((a2 a3 ...) (get-locals (syntax (a3 ...))))))))
    (lambda (x)
      (syntax-case x ()
        ((_ n1 (args ...) e1 e2 ...)
         (with-syntax
             (((new-args ...)   (get-args (syntax (args ...))))
              ((new-locals ...) (get-locals (syntax (args
...)))))
           ; I could check whether new-locals are empty, 
           ; but probably not worth it
           (syntax (begin
                     (define (n1 new-args ...)
                       (let* (new-locals ...)
                         e1 e2 ...))
                     'n1 ; return the name of the function
                   )))))))
)

(display (syntax-object->datum (expand-once #'(defun a (w /
q e) (+ w 1)))))

) ; end of module




_____________________________________________________________________
Ön lemondana évi 72 ezer forint támogatásról? http://lakaskassza.origo.hu/index.html



Posted on the users mailing list.