olmu1944 · 2022-10-08 10:02
I want to find out what the value (here: 100) associated with `b` is
(defconst z '( ( a 100) (b a)))
(setq y (cl-second z)
I know that `a` in `(b a)` is a symbol, but `(symbol-value (cl-second y))` just gives me a `*** Eval error *** Symbol’s value as variable is void: a`. What's wrong with my thinking?
dsemy · 2022-10-08 10:30
The function `symbol-value` returns the contents of the variable cell of the symbol.
In your example, you’ve set the variable cell of symbol `z` the value `((a 100) (b a))`, a list containing two lists, one of which contains the symbol `a` followed by the number 100, and the second containing the symbol `b` followed by the symbol `a`.
You didn’t, however, assign any value to the variable cell of `a`, which is why `symbol-value` fails.
I encourage you to read the Emacs Lisp intro (which should be included with Emacs, and is accessible through the info system (`C-h i`)).
olmu1944 · 2022-10-08 14:17
Thanks, u/dsemy. With your help I was able to concoct this function that sets the values:
(defun set-color-symbols (colorlist)
(dolist (el colorlist)
(when (and (symbolp (cl-first el)) (stringp (cl-second el))))
(set (cl-first el) (cl-second el))
(when (and (symbolp (cl-first el)) (symbolp (cl-second el)))
(set (cl-first el) (symbol-value (cl-second el))))))