Closed sirherrbatka closed 1 year ago
For just a list of places, I don't see a big advantage here over (setf (values ....) (values-list ...))
. Although it is stricter.
It might be more interesting to do at least lambda-list destructuring, so one could write (destructuring-into (&key x y z) ...)
. This could use alexandria:parse-ordinary-lambda-list
.
E.g.
(defmacro destructuring-into (lambda-list expr)
(multiple-value-bind (req opt rest? kws aok? aux key?)
(parse-ordinary-lambda-list lambda-list)
(declare (ignore aok? key?))
(let ((opt (mapcar #'car opt))
(kws (mapcar #'cadar kws))
(aux (mapcar #'car aux)))
`(setf (values ,@req
,@opt
,@(and rest? (list rest?))
,@kws
,@aux)
(apply (lambda ,lambda-list
(values ,@req
,@opt
,@(and rest? (list rest?))
,@kws
,@aux))
,expr)))))
(let (x y z)
(destructuring-into (&key x y z)
(list :z 1 :y 2 :x 3))
(list x y z))
=> 3 2 1
Well, I personally had in mind something that can be used like:
(let (x y z)
(destructuring-into ((x) y z) '((1) 2 3))
(list x y z))
=> 1 2 3
And that's won't be handled by values-list as far as i can tell.
It sounds like you want iterate:dsetq
:
(let (x y z)
(iterate:dsetq ((x) y z) '((1) 2 3))
(list x y z))
=> (1 2 3)
Huh. It never occurred to me to even think about iterate outside ITER:ITERATE scope.
Having said that, yes, this is exactly what I would want. Thanks, I learned something new.
I was thinking that it is slightly odd that such macro was not included in Alexandria, I write something to that effect pretty often.
What is your opinion? (note that the pasted code is wrong)