joke vest amount (jkndrkn) wrote in lisp,
joke vest amount
jkndrkn
lisp

Macro Trouble

Hello Friends

Lisp newbie here running into a bit of trouble when using Macros.

(defun fun (args)
  (mapcar #'(lambda (x) (print x)) args))

(defmacro macro (&rest args)
  `(progn ,@(fun args)))

(defun test ()
  (macro 'a 'b '(c d)))


Trouble is, I can't get this code to compile. It seems that the compiler can't recognize that the function FUN is defined on line 1. When it attempts to compile the function TEST, SBCL/Slime throws the following error:

CL-USER> (load (compile-file "macro.lisp"))

; compiling file "/home/jde/CAP5635/proj/numbrix/macro.lisp" (written 08 SEP 2008 08:38:21 PM):
; compiling (DEFUN FUN ...)
; compiling (DEFMACRO MACRO ...)
; compiling (DEFUN TEST ...)

; file: /home/jde/CAP5635/proj/numbrix/macro.lisp
; in: DEFUN TEST
;     (MACRO 'A 'B '(C D))
; 
; caught ERROR:
;   (in macroexpansion of (MACRO # # ...))
;   (hint: For more precise location, try *BREAK-ON-SIGNALS*.)
;   The function FUN is undefined.
; 
; compilation unit finished
;   caught 1 ERROR condition

; /home/jde/CAP5635/proj/numbrix/macro.fasl written
; compilation finished in 0:00:00
T


The same test was causing clisp to abort with a stack overflow error!

Got any ideas? Is there a fallacy in my approach? How do I convince the compiler that FUN really is defined before test is compiled?

Thanks!
Subscribe
  • Post a new comment

    Error

    default userpic

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 4 comments