emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/dash 43dcd37 295/426: Only eval NUM in --dotimes once


From: Phillip Lord
Subject: [elpa] externals/dash 43dcd37 295/426: Only eval NUM in --dotimes once
Date: Tue, 04 Aug 2015 19:38:23 +0000

branch: externals/dash
commit 43dcd37d4705b5559eef22635045ab4283ffb2e2
Author: Matus Goljer <address@hidden>
Commit: Matus Goljer <address@hidden>

    Only eval NUM in --dotimes once
---
 README.md |    2 +-
 dash.el   |   14 ++++++++------
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/README.md b/README.md
index 7aba5dc..445c41e 100644
--- a/README.md
+++ b/README.md
@@ -1371,7 +1371,7 @@ Returns nil, used for side-effects only.
 
 #### -dotimes `(num fn)`
 
-Repeatedly calls `fn` (presumably for side-effects) passing in integers from 0 
through n-1.
+Repeatedly calls `fn` (presumably for side-effects) passing in integers from 0 
through `num-1`.
 
 ```cl
 (let (s) (-dotimes 3 (lambda (n) (!cons n s))) s) ;; => '(2 1 0)
diff --git a/dash.el b/dash.el
index b38c1d3..9c2a928 100644
--- a/dash.el
+++ b/dash.el
@@ -92,16 +92,18 @@ Returns nil, used for side-effects only."
 (put '-each-while 'lisp-indent-function 2)
 
 (defmacro --dotimes (num &rest body)
-  "Repeatedly executes BODY (presumably for side-effects) with `it` bound to 
integers from 0 through n-1."
+  "Repeatedly executes BODY (presumably for side-effects) with `it` bound to 
integers from 0 through NUM-1."
   (declare (debug (form body))
            (indent 1))
-  `(let ((it 0))
-     (while (< it ,num)
-       ,@body
-       (setq it (1+ it)))))
+  (let ((n (make-symbol "num")))
+    `(let ((,n ,num)
+           (it 0))
+       (while (< it ,n)
+         ,@body
+         (setq it (1+ it))))))
 
 (defun -dotimes (num fn)
-  "Repeatedly calls FN (presumably for side-effects) passing in integers from 
0 through n-1."
+  "Repeatedly calls FN (presumably for side-effects) passing in integers from 
0 through NUM-1."
   (--dotimes num (funcall fn it)))
 
 (put '-dotimes 'lisp-indent-function 1)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]