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: Joost Kremers
Subject: Re: dash.el [was: Re: Imports / inclusion of s.el into Emacs]
Date: Tue, 12 May 2020 09:03:39 +0200
User-agent: mu4e 1.4.4; emacs 27.0.91


On Tue, May 12 2020, Richard Stallman wrote:
  > (map #(/ % 2) '(2 4 6 8))

> It's quite neat (the % being the equivalent of dash.el's > `it`).

In Lisp we have always preferred to write things in the more general
form where you specify the arg names.  But a shorter construct
which avoid the need to specify the arg names might be ok.

In Clojure, they're called function literals and the Clojure docs say "[...] idiomatic use would be for very short one-off mapping/filter fns and the like." So basically just what you said.

What could that kind of abbreviated lambda-expression look like?

In Clojure, a function literal is written with `#(...)`, and it supports `%n` for arguments, where n=1,2,3... (Actually, I don't know if Clojure supports `%10` and up or if it just goes up to `%9`, but I guess that doesn't matter much). A single `%` is synonymous with `%1`, which is used when there's only one argument. Also supported is `%&`, which is similar to `&rest <var>` in Elisp, being bound to a list containing the remaining arguments.

That's all there is to it (the official doc is ever shorter: fourth bullet point under <https://clojure.org/reference/reader#_dispatch>).

--
Joost Kremers
Life has its moments



reply via email to

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