[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash 47f8b2b 214/316: Clean up -doto
From: |
ELPA Syncer |
Subject: |
[elpa] externals/dash 47f8b2b 214/316: Clean up -doto |
Date: |
Mon, 15 Feb 2021 15:58:03 -0500 (EST) |
branch: externals/dash
commit 47f8b2b7239637638b99051842ea124bc6596987
Author: Basil L. Contovounesios <contovob@tcd.ie>
Commit: Basil L. Contovounesios <contovob@tcd.ie>
Clean up -doto
* dash.el (-doto): Fix docstring and simplify slightly.
(--doto): Clarify docstring.
* dev/examples.el (--doto): Move from here...
(-doto): ...to here, simplifying in the process. Fix tests to avoid
destructive modification of immutable literals.
* README.md:
* dash.texi: Regenerate docs.
---
README.md | 26 ++++++++------------------
dash.el | 17 ++++++++---------
dash.texi | 26 ++++++++------------------
dev/examples.el | 11 ++++-------
4 files changed, 28 insertions(+), 52 deletions(-)
diff --git a/README.md b/README.md
index 78e3b68..1b50586 100644
--- a/README.md
+++ b/README.md
@@ -325,8 +325,7 @@ Functions iterating over lists for side-effect only.
* [-each-r](#-each-r-list-fn) `(list fn)`
* [-each-r-while](#-each-r-while-list-pred-fn) `(list pred fn)`
* [-dotimes](#-dotimes-num-fn) `(num fn)`
-* [-doto](#-doto-eval-initial-value-rest-forms) `(eval-initial-value &rest
forms)`
-* [--doto](#--doto-eval-initial-value-rest-forms) `(eval-initial-value &rest
forms)`
+* [-doto](#-doto-init-rest-forms) `(init &rest forms)`
### Destructive operations
@@ -2649,25 +2648,16 @@ if `num` is less than 1.
(let (s) (--dotimes 5 (push it s)) s) ;; => '(4 3 2 1 0)
```
-#### -doto `(eval-initial-value &rest forms)`
+#### -doto `(init &rest forms)`
-Eval a form, then insert that form as the 2nd argument to other forms.
-The `eval-initial-value` form is evaluated once. Its result is
-passed to `forms`, which are then evaluated sequentially. Returns
-the target form.
+Evaluate `init` and thread the result as the 2nd argument to other forms.
+`init` is evaluated once. Its result is passed to `forms`, which are
+then evaluated sequentially. Returns the target form.
```el
-(-doto '(1 2 3) (!cdr) (!cdr)) ;; => '(3)
-(-doto '(1 . 2) (setcar 3) (setcdr 4)) ;; => '(3 . 4)
-```
-
-#### --doto `(eval-initial-value &rest forms)`
-
-Anaphoric form of [`-doto`](#-doto-eval-initial-value-rest-forms).
-Note: `it` is not required in each form.
-
-```el
-(gethash "key" (--doto (make-hash-table :test 'equal) (puthash "key" "value"
it))) ;; => "value"
+(-doto (list 1 2 3) (pop) (pop)) ;; => '(3)
+(-doto (cons 1 2) (setcar 3) (setcdr 4)) ;; => '(3 . 4)
+(gethash 'k (--doto (make-hash-table) (puthash 'k 'v it))) ;; => 'v
```
diff --git a/dash.el b/dash.el
index 06e01b0..7e8d39e 100644
--- a/dash.el
+++ b/dash.el
@@ -62,24 +62,23 @@
(setq it-index (1+ it-index))
(!cdr ,l)))))
-(defmacro -doto (eval-initial-value &rest forms)
- "Eval a form, then insert that form as the 2nd argument to other forms.
-The EVAL-INITIAL-VALUE form is evaluated once. Its result is
-passed to FORMS, which are then evaluated sequentially. Returns
-the target form."
+(defmacro -doto (init &rest forms)
+ "Evaluate INIT and thread the result as the 2nd argument to other forms.
+INIT is evaluated once. Its result is passed to FORMS, which are
+then evaluated sequentially. Returns the target form."
(declare (indent 1))
(let ((retval (make-symbol "value")))
- `(let ((,retval ,eval-initial-value))
+ `(let ((,retval ,init))
,@(mapcar (lambda (form)
- (if (sequencep form)
- `(,(-first-item form) ,retval ,@(cdr form))
+ (if (listp form)
+ `(,(car form) ,retval ,@(cdr form))
`(funcall form ,retval)))
forms)
,retval)))
(defmacro --doto (eval-initial-value &rest forms)
"Anaphoric form of `-doto'.
-Note: `it' is not required in each form."
+Note: `it' need not be used in each form."
(declare (indent 1))
`(let ((it ,eval-initial-value))
,@forms
diff --git a/dash.texi b/dash.texi
index e847455..f70a68d 100644
--- a/dash.texi
+++ b/dash.texi
@@ -4025,33 +4025,23 @@ if @var{num} is less than 1.
@end defun
@anchor{-doto}
-@defmac -doto (eval-initial-value &rest forms)
-Eval a form, then insert that form as the 2nd argument to other forms.
-The @var{eval-initial-value} form is evaluated once. Its result is
-passed to @var{forms}, which are then evaluated sequentially. Returns
-the target form.
+@defmac -doto (init &rest forms)
+Evaluate @var{init} and thread the result as the 2nd argument to other forms.
+@var{init} is evaluated once. Its result is passed to @var{forms}, which are
+then evaluated sequentially. Returns the target form.
@example
@group
-(-doto '(1 2 3) (!cdr) (!cdr))
+(-doto (list 1 2 3) (pop) (pop))
@result{} '(3)
@end group
@group
-(-doto '(1 . 2) (setcar 3) (setcdr 4))
+(-doto (cons 1 2) (setcar 3) (setcdr 4))
@result{} '(3 . 4)
@end group
-@end example
-@end defmac
-
-@anchor{--doto}
-@defmac --doto (eval-initial-value &rest forms)
-Anaphoric form of @code{-doto} (@pxref{-doto}).
-Note: @code{it} is not required in each form.
-
-@example
@group
-(gethash "key" (--doto (make-hash-table :test 'equal) (puthash "key" "value"
it)))
- @result{} "value"
+(gethash 'k (--doto (make-hash-table) (puthash 'k 'v it)))
+ @result{} 'v
@end group
@end example
@end defmac
diff --git a/dev/examples.el b/dev/examples.el
index d16e504..01a7ce1 100644
--- a/dev/examples.el
+++ b/dev/examples.el
@@ -1365,13 +1365,10 @@ consuming a list to produce a single value."
(let (s) (--dotimes 3 (push it s) (setq it -1)) s) => '(2 1 0))
(defexamples -doto
- (-doto '(1 2 3) (!cdr) (!cdr)) => '(3)
- (-doto '(1 . 2) (setcar 3) (setcdr 4)) => '(3 . 4))
-
- (defexamples --doto
- (gethash "key"
- (--doto (make-hash-table :test 'equal)
- (puthash "key" "value" it))) => "value"))
+ (-doto (list 1 2 3) (pop) (pop)) => '(3)
+ (-doto (cons 1 2) (setcar 3) (setcdr 4)) => '(3 . 4)
+ (gethash 'k (--doto (make-hash-table) (puthash 'k 'v it))) => 'v
+ (-doto (cons 1 2)) => '(1 . 2)))
(def-example-group "Destructive operations" nil
(defexamples !cons
- [elpa] externals/dash 770121b 195/316: Update copyright notices with HTTPS links, (continued)
- [elpa] externals/dash 770121b 195/316: Update copyright notices with HTTPS links, ELPA Syncer, 2021/02/15
- [elpa] externals/dash b4ab366 194/316: Merge pull request #355 from blc/info, ELPA Syncer, 2021/02/15
- [elpa] externals/dash e8ed3d6 196/316: * watch-tests.watchr: Remove file., ELPA Syncer, 2021/02/15
- [elpa] externals/dash 814c407 198/316: * dev/.nosearch: Document file's purpose., ELPA Syncer, 2021/02/15
- [elpa] externals/dash 018d30c 200/316: Update all library headers for 2021, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 2200db0 204/316: Various Texinfo manual improvements, ELPA Syncer, 2021/02/15
- [elpa] externals/dash e8cc2ec 205/316: Merge pull request #358 from blc/texi, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 2a94ea5 209/316: Remove unnecessary helper function, ELPA Syncer, 2021/02/15
- [elpa] externals/dash adf3a0d 208/316: Merge pull request #359 from blc/make, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 1d58249 212/316: Write -iterate in terms of --iterate, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 47f8b2b 214/316: Clean up -doto,
ELPA Syncer <=
- [elpa] externals/dash 794bf8c 219/316: ; Fix omission in last change, ELPA Syncer, 2021/02/15
- [elpa] externals/dash f9d67ae 223/316: Merge pull request #314 from blc/reductions, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 31a655b 224/316: Fix -cons* with no arguments, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 3423be4 227/316: Merge pull request #364 from blc/info-look, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 558cd95 230/316: Fix take/drop splits (again), ELPA Syncer, 2021/02/15
- [elpa] externals/dash f975634 233/316: Merge pull request #235, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 8248997 234/316: Merge pull request #207 from holomorph/iota, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 3694ae9 236/316: * dash.el (-iota): Simplify and purify., ELPA Syncer, 2021/02/15
- [elpa] externals/dash ca36c57 239/316: Allow -lambda with no arguments, ELPA Syncer, 2021/02/15
- [elpa] externals/dash bf8a462 243/316: Partially revert last change, ELPA Syncer, 2021/02/15