Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

What am I doing wrong here by putting in &body in a macro?

39 views
Skip to first unread message

Yves S. Garret

unread,
Sep 12, 2012, 9:46:47 AM9/12/12
to
This is the code that I made while following this chapter in gigamonkeys:

http://gigamonkeys.com/book/practical-building-a-unit-test-framework.html

The code:

(defun test-+()
; in here we are doing some funky format magic. The general idea here
; is that if the test fails (produces a NIL), then we print "FAIL".
; If there is a pass, then we print "pass". More information on this
; to follow!
(check
(= (+ 1 2) 3)
(= (+ 1 2 3) 6)
(= (+ -1 -3) -4)))

(defun report-result (result from)
(format t "~:[FAIL~;pass~] ... ~a~%" result from))

(defmacro check (&body forms)
`(progn
,@(loop for f in forms collect `(report-result ,f ',f))))

And this is the error that I'm getting:


[26]> (:cl "hello-world.lisp")
;; Compiling file /home/ashvets/Documents/Development/Lisp/hello-world/hello-world.lisp ...
*** - The macro CHECK may not be called with 3 arguments: (CHECK (= (+ 1 2) 3) (= (+ 1 2 3) 6) (= (+ -1 -3) -4))
The following restarts are available:
ABORT :R1 Abort main loop
Break 1 [27]> :q
0 errors, 0 warnings

I'm using Common Lisp. But why is it saying that I can't put in 3 arguments into check? I used &body.

Pascal J. Bourguignon

unread,
Sep 12, 2012, 9:57:03 AM9/12/12
to
Macros must be defined before they're used.


(defun report-result (result from)
(format t "~:[FAIL~;pass~] ... ~a~%" result from))

(defmacro check (&body forms)
`(progn
,@(loop for f in forms collect `(report-result ,f ',f))))


(defun test-+()
; in here we are doing some funky format magic. The general idea here
; is that if the test fails (produces a NIL), then we print "FAIL".
; If there is a pass, then we print "pass". More information on this
; to follow!
(check
(= (+ 1 2) 3)
(= (+ 1 2 3) 6)
(= (+ -1 -3) -4)))

CL-USER> (test-+)
pass ... (= (+ 1 2) 3)
pass ... (= (+ 1 2 3) 6)
pass ... (= (+ -1 -3) -4)
NIL
CL-USER>


--
__Pascal Bourguignon__ http://www.informatimago.com/
A bad day in () is better than a good day in {}.

Yves S. Garret

unread,
Sep 12, 2012, 10:08:23 AM9/12/12
to
Aaaaaaah, ok, works now. Thank you.
0 new messages