0

Let's assume that I got the following macro:

(defmacro my-check (number)
  `(> 3  ,(apply #'+ number)))

How can I call this macro in a function?

I tried,for example, the following function:

(defun do-test (my-object)
  (my-check my-object))) 

but I get the following error when compiling:

during macroexpansion of (MY-CHECK MY-OBJECT). Use *BREAK-ON-SIGNALS* to
intercept.
The value MY-OBJECT is not of type LIST.

1 Answer 1

4

The comma in your macro is in the wrong place. It is trying to evaluate the entire (apply ...) during macroexpansion, which of course fails since number is a symbol rather than a list. Remember that macros are expanded during compilation, not at run-time.

The correct version would be:

(defmacro my-check (number)
  `(> 3  (apply #'+ ,number)))
Sign up to request clarification or add additional context in comments.

4 Comments

thank you. ´Suppose I could not modify the macro. How could I do a function call instead of re-working the macro?
The only way you can use the original macro is by giving it a literal list as argument, for example (my-check (1 1)). It can't be used with variables.
Tank you. Could you elaborate a little bit on how you came to this conclusion?
I'm not sure what you mean. That the original macro won't work with variables? That follows from the fact that macros are expanded once when you first compile or load the code. At that point the variable is just a symbol; it will only have a value attached to it at run-time (probably a different value every time you call the function).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.