0

I am trying to define a macro in LISP, such as this caller function in a different file

(set_name name My name is Timmy)

(set_name occupation I am a doctor )

(defmacro set_name (list)
   (print list)
)
5
  • 1
    Macros are supposed to return new code to be executed in place of the macro call, not execute something immediately. Commented Apr 16, 2020 at 20:45
  • Can you give me an example ? sorry I am new to LISP, I just don't how to pass those arguments into define macro. Commented Apr 16, 2020 at 20:46
  • Why do you think this should be a macro in the first place, not a function? Commented Apr 16, 2020 at 20:49
  • The name suggests that it's supposed to set the variable, not print something. What do you really want to do? Commented Apr 16, 2020 at 20:50
  • I would suggest you read chapter 7 and 8 to get an understanding of CL’s macros gigamonkeys.com/book/macros-standard-control-constructs.html Commented Apr 16, 2020 at 20:51

1 Answer 1

6

Just like in ordinary functions, use &rest to collect all the remaining arguments into a list.

(defmacro set_name (name &rest list) 
  `(setq ,name ',list))
(set_name occupation I am a doctor)
(print occupation)

This will print (I AM A DOCTOR)

You need to quote ,list in the expansion so it won't try to evaluate all the symbols as variables.

Sign up to request clarification or add additional context in comments.

Comments

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.