[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Improve `replace-regexp-in-string' ergonomics?
From: |
Lars Ingebrigtsen |
Subject: |
Re: Improve `replace-regexp-in-string' ergonomics? |
Date: |
Wed, 22 Sep 2021 22:06:41 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
Augusto Stoffel <arstoffel@gmail.com> writes:
> Clojure has a moderately useful named variant of the threading macro for
> this kind of situation:
>
> (as-> expr name & forms)
>
> Binds name to expr, evaluates the first form in the lexical context
> of that binding, then binds name to that result, repeating for each
> successive form, returning the result of the last form.
>
> (I guess I would have chosen the opposite order of the 'expr' and 'name'
> arguments, though.)
Yeah, you really need something like that to actually do threading in a
Lispish language. But it feels very hackish indeed. Example from the
man page:
(as-> owners $ (nth $ 0) (:pets $) (deref $) ($ 1) ($ :type))
It's like... revenge of the Perl.
Threading works a lot better in languages that are designed around it --
i.e., languages that have a consistent parameter placement, and doesn't
have optional parameters. (Instead they introduce new functions when a
Lispish language introduces an optional parameter.)
Threading feels more like a neat hack in Lispish languages than actually
useful.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
- Re: Improve `replace-regexp-in-string' ergonomics?, (continued)
- Re: Improve `replace-regexp-in-string' ergonomics?,
Lars Ingebrigtsen <=
Re: Improve `replace-regexp-in-string' ergonomics?, Dmitry Gutov, 2021/09/22
Re: Improve `replace-regexp-in-string' ergonomics?, Stefan Monnier, 2021/09/22