I am trying to figure out how to use a macro. I know there are other ways to solve this problem and a macro may or may not be the best answer, but I want to understand the technical problem here vs. solve it some other way.
(setq model-names (list "goat" "alpaca" "llama"))
(defun some-fn (model tag)
(message "Great news: %s %s" model tag))
(defmacro make-my-defun(model)
`(defun ,(intern (concat "my-defun-" (eval model))) (tag)
"Do a thing"
(interactive "sTag: ")
(some-fn ,(eval model) tag)))
(macroexpand-1 '(make-my-defun "goat"))
(macroexpand-1 '(make-my-defun (car model-names)))
(cl-loop for name in model-names
do
;; (insert (format "%s" name)))
(make-my-defun name))
This almost works. I get that things passed into a macro are just sexprs, not evaluated code. However, when I try to create these functions in a loop, it simply doesn't work. With the above code...
(make-my-defun "goat")
(make-my-defun (car model-names))
Both of these work. Without the eval it obviously would not work as it would be getting the raw car expr on the second statement.
So what is going on? Why is name a void variable in my cl-loop as far as make-my-defun is concerned? I read the docs on macros and several other resources, but, I am lacking some fundamental insight here.