chicken-users
[Top][All Lists]
Advanced

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

[Chicken-users] Explicit renaming macros behavior during interpretation


From: Jeronimo Pellegrini
Subject: [Chicken-users] Explicit renaming macros behavior during interpretation and compilation
Date: Thu, 15 Apr 2010 09:49:33 -0300
User-agent: Mutt/1.5.20 (2009-06-14)

Hello,

I understand syntax-rules and Common Lisp's defmacro, but I'm
still getting acquainted with Chicken's implementation of
explicitly renaming macros. So far I have had success in writing
simple macros, but there's one thing I don't understand.

This program seems to work fine when loaded from csi, but csc
complains that a procedure used inside the renaming procedure
is unbound (even though it was defined shortly before the
macro definition):

/---
;; macro.scm (a silly artificial example)

;; swaps the two first elements of a list
(define change-sexp
  (lambda (sexp)
    (append (list (cadr sexp)
                  (car sexp))
            (cddr sexp))))

;; swaps the two first arguments of a procedure call
(define-syntax swap-args
  (lambda (expr ren cmp)
    `(,(caadr expr)
       ,@(change-sexp (cdadr expr)))))

(display (expand '(swap-args (/ 1 2 3))))
(newline)
(display (swap-args (/ 1 2 3)))
(newline)
\---


$ csi -q
#;1> (load "macro.scm")
; loading macro.scm ...
(/ 2 1 3)
0.666666666666667
#;2> 

$ csc macro.scm 

Error: during expansion of (swap-args ...) - unbound variable: change-sexp

    Call history:

    <syntax>        (##core#begin (display (swap-args (/ 1 2 3))))
    <syntax>        (display (swap-args (/ 1 2 3)))
    <syntax>        (swap-args (/ 1 2 3))
    <eval>      (##sys#cons (caadr expr) (##sys#append (change-sexp (cdadr 
expr)) (##core#quote ())))
    <eval>      (caadr expr)
    <eval>      (##sys#append (change-sexp (cdadr expr)) (##core#quote ()))
    <eval>      (change-sexp (cdadr expr))  <--

Error: shell command terminated with non-zero exit status 17920: 
/usr/local/bin/chicken macro.scm -output-file macro.c


Is it not possible to use auxiliary procedures when defining renaming
macros in compiled code?

Thanks,
J.





reply via email to

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