I want to write an emacs macro via defmacro
that takes a parameter which could either be (1) a constant string or (2) a symbol whose value is a string.
Within the macro definition I want to be able to distinghish between alternatives (1) and (2) above but I am finding this difficult to do.
My first attempt is:
(defmacro my-macro (x)
`(message (if (stringp ,x) "given input is a string" "given input is not a string")))
When I run it with a constant string as input I get
(my-macro "this is s atring")
⇒ "given input is a string"
which is what I expected, since we are under situation (1), however
(progn
(setq s "this is s atring")
(my-macro s)
)
⇒ "given input is a string"
which is not what I expected as we are under situation (2). I then tried:
(defmacro my-macro-2 (x)
`(message (if (symbolp ,x) "given input is a symbol" "given input is not a symbol")))
When I run it with a constant string input I get
(my-macro-2 "this is s atring")
⇒ "given input is not a symbol"
which is OK but
(progn
(setq s "this is s atring")
(my-macro-2 s)
)
⇒ "given input is not a symbol"
which is not OK.
So the question is then:
Question. How to distinguish from within a macro definition whether a parameter is a constant string, as opposed to a symbol whose value is a string?