I was reading up on Trees and such in the book "Practical Common Lisp"
but I dont exactly understand what DESTRUCTURING-BIND does exactly? but it seems to be used in alot of tree's when dealing with lisp? can someone give me a very simple layout of what exactly this function does?
(remember its my first time with lisp)
What exactly does DESTRUCTURING-BIND Do?
Re: What exactly does DESTRUCTURING-BIND Do?
Here's the CLHS spec.
The basic idea is to bind variables (assign values to them) by performing a simple pattern match (the destructuring part).
The "destructuring lambda list" is very similar to the "lambda list" (argument prototype) used by normal functions or macros. It specifies the pattern to match.
As an example,
Sometimes its easier to use destructuring-bind than to write a bunch of code using car and cdr and the like.
The basic idea is to bind variables (assign values to them) by performing a simple pattern match (the destructuring part).
The "destructuring lambda list" is very similar to the "lambda list" (argument prototype) used by normal functions or macros. It specifies the pattern to match.
As an example,
Code: Select all
;; normal macro binding
(defmacro f1 (x &key y (z 5))
(list x y z))
(f1 1 :y 2 :z 3)
;; equivalent destructuring-bind
(destructuring-bind
(x &key y (z 5))
'(1 :y 2 :z 3)
(list x y z))
Re: What exactly does DESTRUCTURING-BIND Do?
Oh ok I think I understand, so it's a way of matching.
I've noticed it's used in "Tree's" alot. maybe simply a way of binding values to nodes perhaps
I've noticed it's used in "Tree's" alot. maybe simply a way of binding values to nodes perhaps