Is it possible to write e.g. a Vector literal which uses a variable inside so that the variable gets evaluated correctly and the resulting Vector doesn't just contain the name/symbol of the variable?
For example:
(setq inner ["d" "e"])
["a" "b" inner]
Results into:
["a" "b" inner]
But what I would want is:
["a" "b" ["d" "e"]]
I've done some Clojure coding before Elisp, there it works as I expected:
(def inner ["d" "e"])
user=> ["a" "b" inner]
["a" "b" ["d" "e"]]
What's the fundamental thing I don't understand about Elisp here? I can of course work around this, but I'd like to understand what's going on.
When using the vector syntax, the elements are considered constant. From the Emacs Lisp Reference Manual 6.4:
A vector, like a string or a number, is considered a constant for evaluation: the result of evaluating it is the same vector. This does not evaluate or even examine the elements of the vector.
On the other hand, you could use the vector
function to create a vector where the elements are evaluated:
(setq inner ["d" "e"])
(vector "a" "b" inner)
=> ["a" "b" ["d" "e"]]
use backquote literal. It's possible to use as same as for list.
(setq inner ["d" "e"])
`["a" "b" ,inner]
=> ["a" "b" ["d" "e"]]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With