[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash d983d4f 217/316: Fix -doto
From: |
ELPA Syncer |
Subject: |
[elpa] externals/dash d983d4f 217/316: Fix -doto |
Date: |
Mon, 15 Feb 2021 15:58:03 -0500 (EST) |
branch: externals/dash
commit d983d4fea036b422149e13c473ecead2f7b8e4a8
Author: Basil L. Contovounesios <contovob@tcd.ie>
Commit: Basil L. Contovounesios <contovob@tcd.ie>
Fix -doto
The macro was broken until now for anything other than list forms,
due to a mistake in quoting. Use this as an opportunity to rethink
the macro's behavior in this case. Instead of using funcall, which
is unusual for a macro, thread the value using ->. Suggested by
Zach Shaftel <zshaftel@gmail.com>.
* dash.el (-doto): Rewrite in terms of ->. Fix docstring. Add
Edebug spec.
(--doto): Rename argument for consistency with -doto. Expand
docstring. Add Edebug spec.
* dev/examples.el (-doto): Test fixed behavior of -doto.
* README.md:
* dash.texi: Regenerate docs.
Fixes #333.
---
README.md | 9 +++++----
dash.el | 25 ++++++++++++-------------
dash.texi | 9 +++++----
dev/examples.el | 2 +-
4 files changed, 23 insertions(+), 22 deletions(-)
diff --git a/README.md b/README.md
index 85d7d44..929860c 100644
--- a/README.md
+++ b/README.md
@@ -2650,12 +2650,13 @@ if `num` is less than 1.
#### -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.
+Evaluate `init` and pass it as argument to `forms` with
[`->`](#--x-optional-form-rest-more).
+The `result` of evaluating `init` is threaded through each of `forms`
+individually using [`->`](#--x-optional-form-rest-more), which see. The
return value is `result`,
+which `forms` may have modified by side effect.
```el
-(-doto (list 1 2 3) (pop) (pop)) ;; => '(3)
+(-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 6548f8d..be4fd4b 100644
--- a/dash.el
+++ b/dash.el
@@ -63,24 +63,23 @@
(!cdr ,l)))))
(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")))
+ "Evaluate INIT and pass it as argument to FORMS with `->'.
+The RESULT of evaluating INIT is threaded through each of FORMS
+individually using `->', which see. The return value is RESULT,
+which FORMS may have modified by side effect."
+ (declare (debug (form body)) (indent 1))
+ (let ((retval (make-symbol "result")))
`(let ((,retval ,init))
- ,@(mapcar (lambda (form)
- (if (listp form)
- `(,(car form) ,retval ,@(cdr form))
- `(funcall form ,retval)))
- forms)
+ ,@(mapcar (lambda (form) `(-> ,retval ,form)) forms)
,retval)))
-(defmacro --doto (eval-initial-value &rest forms)
+(defmacro --doto (init &rest forms)
"Anaphoric form of `-doto'.
+This just evaluates INIT, binds the result to `it', evaluates
+FORMS, and returns the final value of `it'.
Note: `it' need not be used in each form."
- (declare (indent 1))
- `(let ((it ,eval-initial-value))
+ (declare (debug (form body)) (indent 1))
+ `(let ((it ,init))
,@forms
it))
diff --git a/dash.texi b/dash.texi
index 899fbb8..0e5aa86 100644
--- a/dash.texi
+++ b/dash.texi
@@ -4026,13 +4026,14 @@ if @var{num} is less than 1.
@anchor{-doto}
@defmac -doto (init &rest forms)
-Evaluate @var{init} and thread the result as the 2nd argument to other
@var{forms}.
-@var{init} is evaluated once. Its result is passed to @var{forms}, which are
-then evaluated sequentially. Returns the target form.
+Evaluate @var{init} and pass it as argument to @var{forms} with @code{->}
(@pxref{->}).
+The @var{result} of evaluating @var{init} is threaded through each of
@var{forms}
+individually using @code{->} (@pxref{->}), which see. The return value is
@var{result},
+which @var{forms} may have modified by side effect.
@example
@group
-(-doto (list 1 2 3) (pop) (pop))
+(-doto (list 1 2 3) pop pop)
@result{} '(3)
@end group
@group
diff --git a/dev/examples.el b/dev/examples.el
index 01a7ce1..067ef47 100644
--- a/dev/examples.el
+++ b/dev/examples.el
@@ -1365,7 +1365,7 @@ 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 (list 1 2 3) (pop) (pop)) => '(3)
+ (-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)))
- [elpa] externals/dash bbf8016 138/316: Remove dependecy `cl-lib` in tests., (continued)
- [elpa] externals/dash bbf8016 138/316: Remove dependecy `cl-lib` in tests., ELPA Syncer, 2021/02/15
- [elpa] externals/dash f3e9cd2 151/316: Fix doc and test harnesses (#309), ELPA Syncer, 2021/02/15
- [elpa] externals/dash 070b569 156/316: Add missing indent declaration for ‘-some->’ and siblings, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 800c25d 166/316: feat(docs): simplify (function x) to #'x, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 53323ec 169/316: Fix typo and its copies, ELPA Syncer, 2021/02/15
- [elpa] externals/dash fe9bbc2 170/316: Merge pull request #334 from tarsiiformes/typo, ELPA Syncer, 2021/02/15
- [elpa] externals/dash e4e5269 180/316: Finish last change to package keywords, ELPA Syncer, 2021/02/15
- [elpa] externals/dash b329938 182/316: Update CI configuration, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 7629dae 183/316: Add dir-locals-file with useful settings, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 84721fc 206/316: Optimize -repeat a bit, ELPA Syncer, 2021/02/15
- [elpa] externals/dash d983d4f 217/316: Fix -doto,
ELPA Syncer <=
- [elpa] externals/dash 66e3e94 079/316: Define -second-item through to -fifth-item, ELPA Syncer, 2021/02/15
- [elpa] externals/dash dd30a1f 047/316: [Feature #196] Add -powerset and -permutations (#203), ELPA Syncer, 2021/02/15
- [elpa] externals/dash 5f7f2d6 056/316: Add example for an iota error condition, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 524e6fe 057/316: Fix -map-last docs (#220), ELPA Syncer, 2021/02/15
- [elpa] externals/dash a3b40f8 058/316: Make --> bind IT for use anywhere in FORMS, and add -as->., ELPA Syncer, 2021/02/15
- [elpa] externals/dash 13f9ece 060/316: add tests for nesting anaphoric macros., ELPA Syncer, 2021/02/15
- [elpa] externals/dash d7b769b 065/316: Use standard Emacs quoting for bound symbols, ELPA Syncer, 2021/02/15
- [elpa] externals/dash b4faa93 066/316: Merge pull request #224 from Wilfred/when-let-docstring, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 0df0ff1 067/316: Merge pull request #222 from zck/partition-before-after, ELPA Syncer, 2021/02/15
- [elpa] externals/dash dcb0ec1 069/316: Merge pull request #232 from Wilfred/improve_docs_wording, ELPA Syncer, 2021/02/15