I have a question about how to use
interactive to allow the user to identify a desired list element to output.
Let's say I have a variable
x assigned to a list structured like this:
(setq x '((y ("y1") ("y2") ("y3")) (z ("z1") ("z2") ("z3"))))
If I want to retrieve the text "(y1)" from this structure and show it to the user, I know that I can do so by using:
(message (format "%s" (nth 1 (assoc 'y x))))
The problem comes when I try to do the same thing interactively. Let's say I want to write a function that asks the user for the variable name and the desired list (y or z), then retrieves the first associated element:
(defun find-first-associated-value (varname listname) (interactive "sWhich variable? : sWhich list? :") (message (format "%s" (nth 1 (assoc listname varname)))))
If I try to call this function and fill in the right values, I get the error
Wrong type argument: listp, "y".
I can tell the reason this isn't working is that I'm passing strings (
assoc, which expects a KEY and then VALUE. The problem is that I can't figure out how to convert the user-inputted strings collected by
interactive to those forms so that they can be understood by
assoc. How can I fix this? I'd be very grateful for any help, and I apologize if the question is poorly worded--I'm new to programming in Lisp.