diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2016-11-01 20:42:30 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2016-11-01 20:42:30 -0700 |
commit | f055854198a7857ce9b54109504a387eba29fae0 (patch) | |
tree | 79863849121486f20a940f635903aa86aa993dfa | |
parent | 49c0178f68ac54d15a0f019c3b5884e6953b0367 (diff) | |
parent | 5e8ae421a2198ed30022c2e8596f175799d36015 (diff) |
Merge tag '2.19'
Upstream version 2.19
# gpg: Signature made Tue 01 Nov 2016 08:42:23 PM MST
# gpg: using RSA key 0x695B7AE4BF066240
# gpg: issuer "spwhitton@spwhitton.name"
# gpg: Good signature from "Sean Whitton <spwhitton@spwhitton.name>" [ultimate]
# Primary key fingerprint: 8DC2 487E 51AB DD90 B5C4 753F 0F56 D055 3B6D 411B
# Subkey fingerprint: 9B91 7007 AE03 0E36 E4FC 248B 695B 7AE4 BF06 6240
-rw-r--r-- | ChangeLog | 24 | ||||
-rw-r--r-- | seq-24.el | 11 | ||||
-rw-r--r-- | seq-25.el | 11 | ||||
-rw-r--r-- | seq-pkg.el | 2 | ||||
-rw-r--r-- | seq.el | 2 | ||||
-rw-r--r-- | tests/seq-tests.el | 16 |
6 files changed, 60 insertions, 6 deletions
@@ -1,3 +1,27 @@ +2016-10-25 Nicolas Petton <nicolas@petton.fr> + + Fix seq-random-elt docstring + + * packages/seq/seq-24.el: + * packages/seq/seq-25.el (seq-random-elt): Fix the docstring. + +2016-10-25 Nicolas Petton <nicolas@petton.fr> + + Backport seq.el changes from Emacs master + + * packages/seq/seq-24.el: + * packages/seq/seq-25.el (seq-random-elt): New function. + * packages/seq/seq.el: Bump version to 2.19. + * packages/seq/tests/seq-tests.el: Add tests for seq-random-elt. + +2016-09-02 Clément Pit--Claudel <clement.pitclaudel@live.com> + + ; Fix documentation of seq-subseq + +2016-08-28 Nicolas Petton <nicolas@petton.fr> + + * packages/seq/seq-24.el: Rename seq-p to seqp + 2016-06-12 Nicolas Petton <nicolas@petton.fr> Update seq.el to 2.16 @@ -371,6 +371,13 @@ SEQUENCE must be a sequence of numbers or markers." SEQUENCE must be a sequence of numbers or markers." (apply #'max (seq-into sequence 'list))) +(defun seq-random-elt (sequence) + "Return a random element from SEQUENCE. +Signal an error if SEQUENCE is empty." + (if (seq-empty-p sequence) + (error "Sequence cannot be empty") + (seq-elt sequence (random (seq-length sequence))))) + (defun seq--drop-list (list n) "Return a list from LIST without its first N elements. This is an optimization for lists in `seq-drop'." @@ -420,7 +427,7 @@ BINDINGS." (seq-doseq (name args) (unless rest-marker (pcase name - ((pred seq-p) + ((pred seqp) (setq bindings (seq--make-bindings (seq--elt-safe args index) `(seq--elt-safe ,sequence ,index) bindings))) @@ -453,7 +460,7 @@ If no element is found, return nil." (defalias 'seq-do #'mapc) (defalias 'seq-each #'seq-do) (defalias 'seq-map #'mapcar) -(defalias 'seq-p #'sequencep) +(defalias 'seqp #'sequencep) (unless (fboundp 'elisp--font-lock-flush-elisp-buffers) ;; In Emacs≥25, (via elisp--font-lock-flush-elisp-buffers and a few others) @@ -91,7 +91,7 @@ given, and the match does not fail." ARGS can also include the `&rest' marker followed by a variable name to be bound to the rest of SEQUENCE." - (declare (indent 2) (debug t)) + (declare (indent 2) (debug (sexp form body))) `(pcase-let ((,(seq--make-pcase-patterns args) ,sequence)) ,@body)) @@ -131,7 +131,7 @@ Return SEQUENCE." (cl-defgeneric seq-subseq (sequence start &optional end) "Return the sequence of elements of SEQUENCE from START to END. -END is inclusive. +END is exclusive. If END is omitted, it defaults to the length of the sequence. If START or END is negative, it counts from the end. Signal an @@ -494,5 +494,12 @@ SEQUENCE must be a sequence of numbers or markers." If no element is found, return nil." (ignore-errors (seq-elt sequence n)))) +(cl-defgeneric seq-random-elt (sequence) + "Return a random element from SEQUENCE. +Signal an error if SEQUENCE is empty." + (if (seq-empty-p sequence) + (error "Sequence cannot be empty") + (seq-elt sequence (random (seq-length sequence))))) + (provide 'seq-25) ;;; seq-25.el ends here @@ -1,2 +1,2 @@ ;; Generated package description from seq.el -(define-package "seq" "2.16" "Sequence manipulation functions" 'nil :url "http://elpa.gnu.org/packages/seq.html" :keywords '("sequences")) +(define-package "seq" "2.19" "Sequence manipulation functions" 'nil :url "http://elpa.gnu.org/packages/seq.html" :keywords '("sequences")) @@ -4,7 +4,7 @@ ;; Author: Nicolas Petton <nicolas@petton.fr> ;; Keywords: sequences -;; Version: 2.16 +;; Version: 2.19 ;; Package: seq ;; Maintainer: emacs-devel@gnu.org diff --git a/tests/seq-tests.el b/tests/seq-tests.el index cf3da78..53930fa 100644 --- a/tests/seq-tests.el +++ b/tests/seq-tests.el @@ -350,5 +350,21 @@ Evaluate BODY for each created sequence. (should (equal (seq-sort-by #'seq-length #'> seq) ["xxx" "xx" "x"])))) +(ert-deftest test-seq-random-elt-take-all () + (let ((seq '(a b c d e)) + (count '())) + (should (= 0 (map-length count))) + (dotimes (_ 1000) + (let ((random-elt (seq-random-elt seq))) + (map-put count + random-elt + (map-elt count random-elt 0)))) + (should (= 5 (map-length count))))) + +(ert-deftest test-seq-random-elt-signal-on-empty () + (should-error (seq-random-elt nil)) + (should-error (seq-random-elt [])) + (should-error (seq-random-elt ""))) + (provide 'seq-tests) ;;; seq-tests.el ends here |