From ... Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.esat.net!nslave.kpnqwest.net!nloc.kpnqwest.net!nmaster.kpnqwest.net!nreader3.kpnqwest.net.POSTED!not-for-mail Newsgroups: comp.lang.lisp Subject: Re: understanding destructuring-bind References: Mail-Copies-To: never From: Erik Naggum Message-ID: <3223810531213034@naggum.net> Organization: Naggum Software, Oslo, Norway Lines: 60 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.1 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Wed, 27 Feb 2002 14:55:26 GMT X-Complaints-To: newsmaster@KPNQwest.no X-Trace: nreader3.kpnqwest.net 1014821726 193.71.199.50 (Wed, 27 Feb 2002 15:55:26 MET) NNTP-Posting-Date: Wed, 27 Feb 2002 15:55:26 MET Xref: archiver1.google.com comp.lang.lisp:27506 * Jordan Katz | I've read both Graham's explanation and the Hyperspec's of | destructuring-bind, but it still makes no sense. : | Can someone explain? Let me start with the simplest example there is, a single variable: (destructuring-bind () ) destructuring-bind hacks up suck that the first (and probably only) element in that list becomes the value of in , almost exactly like (let (( (car ))) ) Now, suppose you make this a tad more complex, with a list of variables and a list of values: (destructuring-bind ( ) ) (let (( (car )) ( (cadr )) ( (caddr ))) ) Finally, let us try with this "tree" notion, not just with a list of variables: (destructuring-bind ( ( )) ) (let (( (car )) ( (cadr )) ( (caddr )) ( (car (cadddr )) ( (cadr (cadddr ))) ) So far, I have only mimicked the results of macroexpand on the destructuring-bind form, but to macroexpand is intimately tied with the function of destructuring-bind. There is another construct that uses destructuring-bind in Common Lisp and that is macros, so if we do (defmacro foo ( ( )) ) we get exactly the same kind of destructuring when you evaluate the form with a equal to (1 2 3 (4 5)) as when you invoke (foo 1 2 3 (4 5)). I hope this made it somewhat clearer what this binding form does and why it is available to you as a Common Lisp programmer. /// -- In a fight against something, the fight has value, victory has none. In a fight for something, the fight is a loss, victory merely relief.