[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: RFC: String interpolation
From: |
Lars Ingebrigtsen |
Subject: |
Re: RFC: String interpolation |
Date: |
Mon, 12 Dec 2016 10:44:30 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) |
Stefan Monnier <address@hidden> writes:
>>> Keyword paramaters are also an option:
>>> (fmt "This is %{thing}.2f and %{zot}ss" :thing (funcall '+ 3.42423 4))
>> Yeah, that's prettier.
>
> FWIW, I don't see why that's preferable to
>
> (let ((thing (funcall '+ 3.45453 4)))
> (preformat "This is %[2f]{thing} and %{zot}ss"))
I think it's preferable in a code life cycle perspective. You frequently
start out with
(fmt "This is %{thing}.2f")
because you have something in a variable you want to output. But then
you see that you have to alter it before display, so then you have
(let ((thing-formatted (replace-regexp-in-string " +" " " thing)))
(fmt "This is %{thing-formatted}.2f"))
That is, you're forced to both name and introduce a new temporary
variable, and you have to alter the format statement itself. (This is
what PHP programmers do all the time, and it kinda sucks.)
With the optional keyword arguments, you just add it:
(fmt "This is %{thing}.2f"
:thing (replace-regexp-in-string " +" " " thing))
This sucks slightly less, in my opinion.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
- Re: RFC: String interpolation, (continued)
- Re: RFC: String interpolation, Richard Stallman, 2016/12/11
- Re: RFC: String interpolation, Clément Pit--Claudel, 2016/12/11
- Re: RFC: String interpolation, Lars Ingebrigtsen, 2016/12/11
- Re: RFC: String interpolation, Richard Stallman, 2016/12/12
- Re: RFC: String interpolation, Lars Ingebrigtsen, 2016/12/11
- Re: RFC: String interpolation, Helmut Eller, 2016/12/11
- Re: RFC: String interpolation, Lars Ingebrigtsen, 2016/12/11
- Re: RFC: String interpolation, Stefan Monnier, 2016/12/11
- Re: RFC: String interpolation,
Lars Ingebrigtsen <=
- Re: RFC: String interpolation, Stefan Monnier, 2016/12/12
- Re: RFC: String interpolation, Lars Ingebrigtsen, 2016/12/12
- Re: RFC: String interpolation, Stefan Monnier, 2016/12/12
- Re: RFC: String interpolation, Lars Ingebrigtsen, 2016/12/12
- Re: RFC: String interpolation, Lars Ingebrigtsen, 2016/12/12
- Re: RFC: String interpolation, Stefan Monnier, 2016/12/12
- Re: RFC: String interpolation, Stefan Monnier, 2016/12/12
- Re: RFC: String interpolation, Clément Pit--Claudel, 2016/12/12
- Re: RFC: String interpolation, Lars Ingebrigtsen, 2016/12/12
- Re: RFC: String interpolation, Clément Pit--Claudel, 2016/12/12