emacs-devel
[Top][All Lists]
Advanced

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

Re: [PATCH] Clojure-like syntactic sugar for an anonymous function liter


From: Tassilo Horn
Subject: Re: [PATCH] Clojure-like syntactic sugar for an anonymous function literal
Date: Thu, 22 Jan 2015 11:56:22 +0100
User-agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/25.0.50 (gnu/linux)

Oleh <address@hidden> writes:

>>  > The most popular library in MELPA, https://github.com/magnars/dash.el,
>>  > implements it (for a long time) like this:
>>  >
>>  >     (--map (* it it) '(1 2 3))
>>  >     ;; => (1 4 9)
>>  >
>>  > With my approach, it's:
>>  >
>>  >     (mapcar #(* % %) '(1 2 3))
>>  >     ;; => (1 4 9)
>>
>> That looks almost like Perl!  Now I'm -2.  Just require dash.
>
> How is `dash' better? `--map' is a macro:
>
>     (defmacro --map (form list)
>       "Anaphoric form of `-map'."
>       (declare (debug (form form)))
>       `(mapcar (lambda (it) ,form) ,list))
>
> `dash' also gives other ~40 macros that look like this, littered all
> over the code in the MELPA, so it's impossible to go on without
> understanding what `dash' does.

FWIW, I favor your Clojure-like syntax over anaphoric macros.  And one
benefit is that you're not restricted to one list to map over as in
--map.  E.g., your approach works out of the box with

  (cl-mapcar #(- %5 %4 %3 %2 %1) list1 list2 list3 list4 list5)

for which there is no dash equivalent.  Of course, --map could be
extended to create args (it1 ... itN) if more than one list is given.

BTW, do you also support %& to declare that the lambda has a &rest arg
so that you can do

  (apply #'cl-mapcar #(apply #'- (reverse %&)) list-of-lists)

?

So basically I like that syntax (or maybe #l(...) or #fn(...)) and would
consider using it where it makes sense.  But as others already
mentioned, those places are much fewer than in an almost purely
functional language like Clojure.

Bye,
Tassilo



reply via email to

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