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

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

[elpa] externals/dash ca36c57 239/316: Allow -lambda with no arguments


From: ELPA Syncer
Subject: [elpa] externals/dash ca36c57 239/316: Allow -lambda with no arguments
Date: Mon, 15 Feb 2021 15:58:09 -0500 (EST)

branch: externals/dash
commit ca36c573a4c099f5b7d8589c07c567561339fe51
Author: Basil L. Contovounesios <contovob@tcd.ie>
Commit: Basil L. Contovounesios <contovob@tcd.ie>

    Allow -lambda with no arguments
    
    * dash.el (-lambda): Allow empty arglist.  Fix error data signaled.
    * dev/examples.el (-lambda): Add tests for this.
    
    * README.md:
    * dash.texi: Regenerate docs.
---
 README.md       |  4 ++--
 dash.el         | 23 ++++++++++++-----------
 dash.texi       |  4 ++--
 dev/examples.el |  5 ++++-
 4 files changed, 20 insertions(+), 16 deletions(-)

diff --git a/README.md b/README.md
index e4b262b..b59a5fd 100644
--- a/README.md
+++ b/README.md
@@ -2616,10 +2616,10 @@ such that:
     (-lambda (x y ...) body)
 
 has the usual semantics of `lambda`.  Furthermore, these get
-translated into normal lambda, so there is no performance
+translated into normal `lambda`, so there is no performance
 penalty.
 
-See [`-let`](#-let-varlist-rest-body) for the description of destructuring 
mechanism.
+See [`-let`](#-let-varlist-rest-body) for a description of the destructuring 
mechanism.
 
 ```el
 (-map (-lambda ((x y)) (+ x y)) '((1 2) (3 4) (5 6))) ;; => '(3 7 11)
diff --git a/dash.el b/dash.el
index 6903b42..052a9b0 100644
--- a/dash.el
+++ b/dash.el
@@ -2294,27 +2294,28 @@ such that:
   (-lambda (x y ...) body)
 
 has the usual semantics of `lambda'.  Furthermore, these get
-translated into normal lambda, so there is no performance
+translated into normal `lambda', so there is no performance
 penalty.
 
-See `-let' for the description of destructuring mechanism."
+See `-let' for a description of the destructuring mechanism."
   (declare (doc-string 2) (indent defun)
            (debug (&define sexp
                            [&optional stringp]
                            [&optional ("interactive" interactive)]
                            def-body)))
   (cond
-   ((not (consp match-form))
-    (signal 'wrong-type-argument "match-form must be a list"))
-   ;; no destructuring, so just return regular lambda to make things faster
-   ((-all? 'symbolp match-form)
+   ((nlistp match-form)
+    (signal 'wrong-type-argument (list #'listp match-form)))
+   ;; No destructuring, so just return regular `lambda' for speed.
+   ((-all? #'symbolp match-form)
     `(lambda ,match-form ,@body))
-   (t
-    (let* ((inputs (--map-indexed (list it (make-symbol (format "input%d" 
it-index))) match-form)))
-      ;; TODO: because inputs to the lambda are evaluated only once,
-      ;; -let* need not to create the extra bindings to ensure that.
+   ((let ((inputs (--map-indexed
+                   (list it (make-symbol (format "input%d" it-index)))
+                   match-form)))
+      ;; TODO: because inputs to the `lambda' are evaluated only once,
+      ;; `-let*' need not create the extra bindings to ensure that.
       ;; We should find a way to optimize that.  Not critical however.
-      `(lambda ,(--map (cadr it) inputs)
+      `(lambda ,(mapcar #'cadr inputs)
          (-let* ,inputs ,@body))))))
 
 (defmacro -setq (&rest forms)
diff --git a/dash.texi b/dash.texi
index 1ec69fb..2547c89 100644
--- a/dash.texi
+++ b/dash.texi
@@ -3950,10 +3950,10 @@ such that:
     (-lambda (x y @dots{}) body)
 
 has the usual semantics of @code{lambda}.  Furthermore, these get
-translated into normal lambda, so there is no performance
+translated into normal @code{lambda}, so there is no performance
 penalty.
 
-See @code{-let} (@pxref{-let}) for the description of destructuring mechanism.
+See @code{-let} (@pxref{-let}) for a description of the destructuring 
mechanism.
 
 @example
 @group
diff --git a/dev/examples.el b/dev/examples.el
index 4dbc38c..d8ba79a 100644
--- a/dev/examples.el
+++ b/dev/examples.el
@@ -1416,7 +1416,10 @@ value rather than consuming a list to produce a single 
value."
     (funcall (-lambda ((a) (b)) (+ a b)) '(1 2 3) '(4 5 6)) => 5
     (-lambda a t) !!> wrong-type-argument
     (funcall (-lambda (a b) (+ a b)) 1 2) => 3
-    (funcall (-lambda (a (b c)) (+ a b c)) 1 (list 2 3)) => 6)
+    (funcall (-lambda (a (b c)) (+ a b c)) 1 (list 2 3)) => 6
+    (funcall (-lambda () 1)) => 1
+    (let* ((x 0) (f (-lambda () (setq x (1+ x))))) (--dotimes 3 (funcall f)) x)
+    => 3)
 
   (defexamples -setq
     (progn (-setq a 1) a) => 1



reply via email to

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