Discussion:
playing with destructuring
(too old to reply)
Bigos
2020-10-22 16:47:21 UTC
Permalink
I am familiar with destricturing-bind, but I wonder how I could make it more coscise for this specific case. Any suggestions?


(defparameter zzz '(1 2 3 4 5))

(defun uncons (l) (list (car l) (cdr l)))

(destructuring-bind (a b) (uncons zzz)
(format t "~A === ~A~%" a b ))

;;; how do I do the following or similar
(let (((a b) (uncons zzz)))
(format t "~A === ~A~%" a b ))
Siebe de Vos
2020-10-22 16:55:52 UTC
Permalink
Post by Bigos
I am familiar with destricturing-bind, but I wonder how I could make it more coscise for this specific case. Any suggestions?
(defparameter zzz '(1 2 3 4 5))
(defun uncons (l) (list (car l) (cdr l)))
(destructuring-bind (a b) (uncons zzz)
(format t "~A === ~A~%" a b ))
;;; how do I do the following or similar
(let (((a b) (uncons zzz)))
(format t "~A === ~A~%" a b ))
Did you mean this?

(destructuring-bind (a &rest b) zzz
(format t "~A === ~A~%" a b ))
1 === (2 3 4 5)
Kaz Kylheku
2020-10-23 16:14:54 UTC
Permalink
Post by Bigos
I am familiar with destricturing-bind, but I wonder how I could make it more coscise for this specific case. Any suggestions?
(defparameter zzz '(1 2 3 4 5))
(defun uncons (l) (list (car l) (cdr l)))
(destructuring-bind (a b) (uncons zzz)
(format t "~A === ~A~%" a b ))
(destructuring-bind (a . b) zzz
...)
--
TXR Programming Language: http://nongnu.org/txr
Music DIY Mailing List: http://www.kylheku.com/diy
ADA MP-1 Mailing List: http://www.kylheku.com/mp1
Loading...