From 5e8ae421a2198ed30022c2e8596f175799d36015 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Tue, 1 Nov 2016 20:42:23 -0700 Subject: New upstream version 2.19 --- ChangeLog | 24 ++++++++++++++++++++++++ seq-24.el | 11 +++++++++-- seq-25.el | 11 +++++++++-- seq-pkg.el | 2 +- seq.el | 2 +- tests/seq-tests.el | 16 ++++++++++++++++ 6 files changed, 60 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 88f8e8c..10f8464 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,27 @@ +2016-10-25 Nicolas Petton + + 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 + + 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 + + ; Fix documentation of seq-subseq + +2016-08-28 Nicolas Petton + + * packages/seq/seq-24.el: Rename seq-p to seqp + 2016-06-12 Nicolas Petton Update seq.el to 2.16 diff --git a/seq-24.el b/seq-24.el index d0aa618..3f9cd88 100644 --- a/seq-24.el +++ b/seq-24.el @@ -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) diff --git a/seq-25.el b/seq-25.el index b2f5c98..c2268dd 100644 --- a/seq-25.el +++ b/seq-25.el @@ -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 diff --git a/seq-pkg.el b/seq-pkg.el index 0a19486..5afa589 100644 --- a/seq-pkg.el +++ b/seq-pkg.el @@ -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")) diff --git a/seq.el b/seq.el index 9f96ec8..6bbb307 100644 --- a/seq.el +++ b/seq.el @@ -4,7 +4,7 @@ ;; Author: Nicolas Petton ;; 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 -- cgit v1.2.3