Hi,
I've been writing some simple test cases for one of my assignments, and have built up a bit of a test suite using macros. I have run-test
and run-test-section
and so on.
I'd like run-test-section
to take a number of parameters which are run-test
invocations and count up the number of PASSes and FAILs.
run-test
returns T on PASS, and NIL on FAIL.
What I'm looking to do right now is write a macro that takes a &REST
parameter, and invokes each of the elements of this list, finally returning the number of TRUE values.
This is what I currently have:
(defmacro count-true (&rest forms)
`(cond
((null ,forms)
0)
((car ,forms)
(1+ (count-true (cdr ,forms))))
(T
(count-true (cdr ,forms)))))
However this puts my REPL into an infinite loop. Might someone be able to point out how I can more effectively manipulate the arguments. Is this even a good idea? Is there a better approach?
edit:
As is noted in responses, a macro is not needed in this case. Using the inbuilt COUNT
will suffice. There is useful information in the responses on recursive macro calls, however.