mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2024-11-29 07:58:28 +00:00
Add macro seq-setq
.
* doc/lispref/sequences.texi (seq-setq): Document this macro. * test/lisp/emacs-lisp/seq-tests.el (test-seq-setq): Test this macro (bug#50053).
This commit is contained in:
parent
c58f8dda2b
commit
a8a3fd8f8e
@ -1128,6 +1128,23 @@ assigned to variables as if by @code{setq} instead of as in a
|
||||
@end example
|
||||
@end defmac
|
||||
|
||||
@defmac seq-setq var-sequence val-sequence
|
||||
@cindex sequence destructuring
|
||||
This macro works similarly to @code{seq-let}, except that values are
|
||||
assigned to variables as if by @code{setq} instead of as in a
|
||||
@code{let} binding.
|
||||
|
||||
@example
|
||||
@group
|
||||
(let ((a nil)
|
||||
(b nil))
|
||||
(seq-setq (_ a _ b) '(1 2 3 4))
|
||||
(list a b))
|
||||
@result{} (2 4)
|
||||
@end group
|
||||
@end example
|
||||
@end defmac
|
||||
|
||||
@defun seq-random-elt sequence
|
||||
This function returns an element of @var{sequence} taken at random.
|
||||
|
||||
|
@ -407,6 +407,30 @@ Evaluate BODY for each created sequence.
|
||||
(should (null b))
|
||||
(should (null c))))
|
||||
|
||||
(ert-deftest test-seq-setq ()
|
||||
(with-test-sequences (seq '(1 2 3 4))
|
||||
(let (a b c d e)
|
||||
(seq-setq (a b c d e) seq)
|
||||
(should (= a 1))
|
||||
(should (= b 2))
|
||||
(should (= c 3))
|
||||
(should (= d 4))
|
||||
(should (null e)))
|
||||
(let (a b others)
|
||||
(seq-setq (a b &rest others) seq)
|
||||
(should (= a 1))
|
||||
(should (= b 2))
|
||||
(should (same-contents-p others (seq-drop seq 2)))))
|
||||
(let ((a)
|
||||
(seq '(1 (2 (3 (4))))))
|
||||
(seq-setq (_ (_ (_ (a)))) seq)
|
||||
(should (= a 4)))
|
||||
(let (seq a b c)
|
||||
(seq-setq (a b c) seq)
|
||||
(should (null a))
|
||||
(should (null b))
|
||||
(should (null c))))
|
||||
|
||||
(ert-deftest test-seq-min-max ()
|
||||
(with-test-sequences (seq '(4 5 3 2 0 4))
|
||||
(should (= (seq-min seq) 0))
|
||||
|
Loading…
Reference in New Issue
Block a user