[Top][All Lists]

[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: Mon, 18 May 2020 20:29:26 +0200

> On 18. May 2020, at 06:42, Stefan Monnier <address@hidden> wrote:
>> However, we could implement both syntaxes, use the $ syntax in the
>> short term, and convert external packages to the # syntax in a few
>> years.
>> Let's see what Eli thinks about it.
> FWIW, I'm not too fond of such shorthand syntax.  The benefit is not
> very high and it makes the language that much more difficult to learn
> for newcomers.
> For a programming language like Closure, it might make sense, since
> most/all people writing Closure programs are actual programmers that
> have to be proficient in Clojure.  But Elisp lambdas are very common in
> .emacs files, so this additional complexity will be exposed to some of
> our users who aren't programmers or aren't proficient in Elisp.

I understand your argument, particularly as it applies to the
reader syntax.  On the other hand, dollar.el is just a macro: it
does not complicate the syntax (for some definition of syntax);
although it does complicate understanding when first presented.
Being just a macro entails:

It’s highlighted in Emacs, just like lambda.
Its documentation can be queried on the spot with C-h f RET.
It can be macroexpanded, in order to inspect its effect.

In any case, I have no experience helping beginners, so I’m
not sure whether the above would help them or not.

> [ Yes, I know it may sound strange coming from me, since I'm to blame
>  for a lot of complexity in Elisp :-(
>  But to my defense, `pcase` and `cl-defmethod` aren't nearly as often
>  needed in .emacs as lambdas.  ]

(You’ve done much good, thank you.)

> I can already see the discussions in forums about "what's the difference
> between #(f % 1) and (lambda (x) (f x 1))", "when should I use which",
> ...
> If we want to shorten anonymous functions we could start with something
> like (λ (x) (f x 1)), which you can get with
> prettify-symbols-mode already.

Something like this is supported by dollar.el, when using the named variables
syntax (substituting λ for $):

        ($ [x] (f x 1))

though the usual way would be:

        ($ (f $1 1))

Would prettifying lambda to λ lead to visually unexpected indentation?
(I think not, for the uses…)  Typing λ is a no-go, in my opinion.

I’m not entirely sold on the symbol $ for the macro name, but its use
for the variables is genius, in my opinion, which makes the combination
“click”.  Variable names starting with $ ($1, $2, etc.) are familiar for
people with experience with in Bash, Tcl or PHP.  For people familiar
with Haskell, $ is another form of function application, which would
remind of the $ macro.

Going with % and %1, %2, etc. would be fine, and would be intuitive
for people with Clojure backgrounds.  But % is taken.

Other symbol might be more intuitive or “lispy”, though I can’t
think of any, especially that is easy to type, “familiar” (subjective) and
intuitive (also subjective).

[… This alternative occurred to me meanwhile:

        (\ (f \1 1))

\ is used by Haskell for its lambda expressions (it’s supposed to remind
of λ).  \1, \2, etc is used in regular expressions to refer to capture
groups.  It’s somewhat ugly, but makes sense.]

Best regards,

reply via email to

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