Is it possible to assign multiple return values directly to variables without going through a temporary variable in Emacs Lisp?
For example, let's say I have a function that returns a list of two lists:
(defun test-func ()
(setq a '(a b))
(setq b '(c d))
`(,a ,b))
If I want to assign the first return value to list-a and the second return value to list-b, I can do this by using a temporary variable temp, for example:
(let* ((temp (test-func)) (list-a (car temp)) (list-b (cadr temp)))
(message-box (prin1-to-string list-a))
(message-box (prin1-to-string list-b)))
Is it possible to do this more simply? (I am used to Perl and Python where you do not have to specify a temporary variable)
cl-destructuring-bindmacro. Also, did you really intend to usesetqinside adefun?setqcreates a "special" (globally accessible) variable, something you'd typically put outside a function (because there's little meaning in declaring the same variable more than once, while functions are intended to be run more than once). – wvxvw Jan 26 '15 at 10:54letinside the function.. I did not plan to set any global variables :) – Håkon Hægland Jan 26 '15 at 11:23