emacs-devel
[Top][All Lists]
Advanced

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

Re: dash.el [was: Re: Imports / inclusion of s.el into Emacs]


From: Adrián Medraño Calvo
Subject: Re: dash.el [was: Re: Imports / inclusion of s.el into Emacs]
Date: Thu, 14 May 2020 09:26:23 +0200

> On 13. May 2020, at 23:03, Jonas Bernoulli <address@hidden> wrote:
> 
> Stefan Monnier <address@hidden> writes:
> 
>>> You said that there is a macro like this already in Emacs?
>> 
>> I don't think it's in Emacs, but I remember seeing something like
>> that somewhere.
> 
> You were probably thinking of Oleh Krehel's short-lambda package.
> 
> https://github.com/abo-abo/short-lambda

There’s also dollar.el, by Göktuğ Kayaalp (CC’d):

        https://github.com/cadadr/elisp/blob/devel/dollar.el

I find it very elegant: it’s just a macro.

;;; Commentary:
;; This package provides a macro named $ where in its body symbols in
;; the form $N where N is a positive integer are to stand for
;; positional arguments to the generated lambda.
;; If the car of the body is a vector though, that vector becomes the
;; argument list of the new lambda.

For example:

        ($ (+ $1 $2))

expands to:

        (lambda
          ($1 $2 &rest $_)
          (let
              (($*
                (cons
                 (vector $1 $2)
                 $_)))
            (+ $1 $2)))
        
                (funcall ($ + $1 $2) 4 6)
                10

Example usage:

        (seq-map ($ (* $1 $1)) '(1 2 3))
        (1 4 9)

Using named arguments:

        (seq-map ($ [n] (* n n)) '(1 2 3))
        (1 4 9)

At first glance, I’d do away with &rest $_ and collecting the arguments in the 
$* variable, for better performance.  The former could be left to the named 
arguments mechanism.

Göktuğ Kayaalp, would you be willing to include dollar.el in Emacs or GNU ELPA?

Thank you all and
best regards,
Adrián.


reply via email to

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