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.
master
Basil L. Contovounesios 5 years ago
parent bf8d8767f6
commit ca36c573a4
No known key found for this signature in database
GPG Key ID: 205AB54A5D5D8CFF
  1. 4
      README.md
  2. 23
      dash.el
  3. 4
      dash.texi
  4. 5
      dev/examples.el

@ -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)

@ -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)

@ -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

@ -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

Loading…
Cancel
Save