diff --git a/dash.el b/dash.el index 053eabf..e1c9aca 100644 --- a/dash.el +++ b/dash.el @@ -2699,6 +2699,23 @@ The items for the comparator form are exposed as \"it\" and \"other\"." (declare (debug (form form))) `(-min-by (lambda (it other) ,form) ,list)) +(defun -iota (count &optional start step) + "Return a list containing COUNT numbers. +Starts from START and adds STEP each time. The default START is +zero, the default STEP is 1. +This function takes its name from the corresponding primitive in +the APL language." + (when (not (natnump count)) + (signal 'wrong-type-argument (list #'natnump count))) + (or start (setq start 0)) + (or step (setq step 1)) + (if (zerop step) (make-list count start) + (let (result) + (while (<= 0 (setq count (1- count))) + (push start result) + (setq start (+ start step))) + (nreverse result)))) + (defun -fix (fn list) "Compute the (least) fixpoint of FN with initial input LIST. diff --git a/dev/examples.el b/dev/examples.el index d83d282..a0f1975 100644 --- a/dev/examples.el +++ b/dev/examples.el @@ -879,6 +879,11 @@ value rather than consuming a list to produce a single value." (-interleave '(1 2 3) '("a" "b" "c" "d")) => '(1 "a" 2 "b" 3 "c") (-interleave) => nil) + (defexamples -iota + (-iota 6) => '(0 1 2 3 4 5) + (-iota 4 2.5 -2) => '(2.5 0.5 -1.5 -3.5) + (-iota -1) !!> wrong-type-argument) + (defexamples -zip-with (-zip-with '+ '(1 2 3) '(4 5 6)) => '(5 7 9) (-zip-with 'cons '(1 2 3) '(4 5 6)) => '((1 . 4) (2 . 5) (3 . 6))