Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Is SBCL retarded?

Name: Anonymous 2013-02-09 13:25

or am i just doing something wrong?


(defmacro test (&body c)
  `(progn ,(test2 c)))

(defmacro test2 (&body c)
  (format t "~A~%" c)
  `(progn (car ,c) ,@c))


test2 compiles just fine
upon trying to compile test i get:

; in: DEFMACRO TEST
;     COMMON-LISP::C
;
; caught STYLE-WARNING:
;   undefined function: C
;
; compilation unit finished
;   Undefined function:
;     C
;   caught 1 STYLE-WARNING condition



How the fuck does it see C as a function when it's clearly in the argument position for test2?

Name: Anonymous 2013-02-09 13:55

>>1
Because C in `(progn ,(test2 c))) isn't bound to outer's C value, but passed as symbol C.

Name: Anonymous 2013-02-09 13:57

think about what a macro does.

- It takes input
- It turns that input into S-expressions
- Returns the output
- Compiler then evals the output

test is basically doing:

(eval (progn (eval (progn (car c) ,@c))))
=>(eval (progn ,@c))
=>,@c


and in the manner you're calling test2,
c = ( (exps...) )

thus the final result would be interpreting the first expression in c as a function.



tl;dr: test2 should be a defun, not defmacro

Name: Anonymous 2013-02-09 13:57

>>2
i.e. macros never evaluate their params - that is whole point of them. OP should define test2 as (defun test2 (&body c)

Name: Anonymous 2013-02-09 13:58

I order to say what you are doing wrong, we need to know what you are trying to do.

Name: Anonymous 2013-02-09 14:01

>>4
>>3

(defun test2 (&body c)
  (format t "~A~%" c)
  `(progn (car ,c) ,@c))

now errors:


; caught ERROR:
;   Bad lambda list keyword &BODY in: (&BODY C)
;
; compilation unit finished
;   caught 1 ERROR condition

Name: Anonymous 2013-02-09 14:03

>>6
use &rest instead of &body

Name: Anonymous 2013-02-09 14:16

OP all you need is:

(defmacro test (&body c)
  `(progn (test2 ,@c)))


SBCL will automatically expand test2 when compiling, you don't need to invoke it manually like that

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List