Fix -repeat

master
vemv 13 years ago
parent e4521af667
commit a196ac1166
  1. 12
      README.md
  2. 13
      dash.el
  3. 6
      dev/examples.el

@ -57,6 +57,7 @@ Or you can just dump `dash.el` in your load path somewhere.
* [-->](#---x-form-rest-more) `(x form &rest more)`
* [!cons](#-cons-car-cdr) `(car cdr)`
* [!cdr](#-cdr-list) `(list)`
* [-repeat](#-repeat-n-x) `(n x)`
There are also anaphoric versions of these functions where that makes sense,
prefixed with two dashes instead of one.
@ -586,6 +587,17 @@ Destructive: Sets `list` to the cdr of `list`.
(let ((l '(3 5))) (!cdr l) l) ;; => '(5)
```
### -repeat `(n x)`
Return a list of `n` Xs.
Attempts of retrieving a non-positive amount of Xs will return nil.
```cl
(-repeat 3 :a) ;; => '(:a :a :a)
(-repeat 1 :a) ;; => '(:a)
(-repeat 0 :a) ;; => nil
```
## Contribute

@ -587,15 +587,16 @@ or with `-compare-fn' if that's non-nil."
(setq lst (cdr lst)))
lst))))))
(defalias '-contains-p '-contains?)
(defun -repeat (n x)
"Return a list of N Xs."
"Return a list of N Xs.
Attempts of retrieving a non-positive amount of Xs will return nil."
(let ((ret nil))
(loop for i from 0 to (dec n) do
(setq ret (cons x ret)))
(while (not (minusp (setq n (1- n))))
(!cons x ret))
ret))
(defalias '-contains-p '-contains?)
(eval-after-load "lisp-mode"
'(progn
(let ((new-keywords '(
@ -678,7 +679,7 @@ or with `-compare-fn' if that's non-nil."
"-difference"
"-contains?"
"-contains-p"
))
"-repeat"))
(special-variables '(
"it"
"it-index"

@ -239,3 +239,9 @@
(defexamples !cdr
(let ((l '(3))) (!cdr l) l) => '()
(let ((l '(3 5))) (!cdr l) l) => '(5))
(defexamples -repeat
(-repeat 3 :a) => '(:a :a :a)
(-repeat 1 :a) => '(:a)
(-repeat 0 :a) => nil
(-repeat -1 :a) => nil)

Loading…
Cancel
Save