سؤال

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))

(destructuring-bind
    ((a b) (c d)) '((1 2) (3 4))
  `(,b ,d))
هل كانت مفيدة؟

المحلول

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)
     expression
   (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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top