In Python, I can do something like this:
t = (1, 2)
a, b = t
...and a will be 1 and b will be 2. Suppose I have a list \'(1 2)
in
The general term for what you're looking for (at least in Lisp-world) is destructuring and a macro that implements it is known as destructuring-bind. In Common Lisp, it works like this:
(destructuring-bind (a b c) '(1 2 3)
(list a b c)) ;; (1 2 3)
it also works for multiple "levels" of nesting:
(destructuring-bind (a (b c) d) '(1 (2 3) 4)
(list a b c d)) ;; (1 2 3 4)
It looks like there's a nice implementation of destructuring-bind as a scheme macro.