Elisp: Destructure Binding (seq-setq, seq-let)
seq-setq-
new in emacs 28.3 Emacs 28 (date 2022) (Add macro seq-setq. Earl Hyatt and larsmagne committed on 2021-08-14)
bind a Sequence of values to several variables.
- If there are more values, they are ignored.
- If there are more variables, they get
nil.
(let (x1 x2) (seq-setq (x1 x2) [3 4]) (message "%s %s" x1 x2)) ;; 3 4 (let (x1 x2) (seq-setq (x1 x2) (list 3 4)) (message "%s %s" x1 x2)) ;; 3 4 seq-let-
bind a Sequence of values to several local variables.
- If there are more values, they are ignored.
- If there are more variables, they get
nil.
;; example of using seq-let ;; if there are more variables than in sequence, the rest has value of nil (seq-let (xa xb xc) [1 2] (vector xa xb xc)) ;; [1 2 nil] ;; if there are less variables than in sequence, the rest sequence is ignored (seq-let (xa xb) [1 2 3 4 5] (vector xa xb)) ;; [1 2]