TAGS :Viewed: 4 - Published at: a few seconds ago

[ Can destructuring-setq be defined using destructuring-bind? ]

There is destructuring-bind but it seems there is no destructuring-setq. Is it possible to define it using destructuring-bind?

(let (a b c d)
  (destructuring-setq ((a b) (c d)) '((1 2) (3 4)))
  `(,b ,d))

    ((a b) (c d)) '((1 2) (3 4))
  `(,b ,d))

Answer 1

This would be a highly nontrivial endeavor.

What you would have to do is write a lambda-list analyzer which would

  1. Find all variables to be bound
  2. Replace them with gensyms (or use copy-symbol for total unreadability of the macroexpansion :-) and keep a map from the old symbols to the new ones.

Return something like

(destructuring-bind (new-lambda-list)
   (setq old-var-1 new-gensym-1 ...))

The analyser is present in any Common Lisp implementation (see, e.g., the link above) and it is not simple.

I suggest that you ask yourself whether destructuring-bind is really not enough.