[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: RFC: String interpolation
From: |
Ted Zlatanov |
Subject: |
Re: RFC: String interpolation |
Date: |
Fri, 09 Dec 2016 14:19:37 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) |
On Wed, 7 Dec 2016 20:13:41 -0500 Clément Pit--Claudel <address@hidden> wrote:
CP> With the attached fmt.el, you can write things like this:
CP> (let ((a 12) (b 15))
CP> (fmt "$a + $b = $(+ a b)"))
CP> ⇒ "12 + 15 = 27"
...
CP> (fmt "Welcome to Emacs! "
CP> "Press $[where-is]{'help-with-tutorial} to open the tutorial.")
CP> ⇒ "Welcome to Emacs! Press C-h t to open the tutorial."
I'd rather see either something like Mustache templates or simply using
the format-spec.el that comes with Emacs. The advantage in my opinion
(informed by many years of using Perl, where string interpolation is a
way of life) is that clarity is improved by separating the format spec
from the data that fills it out, and it's very tempting to stuff logic
into strings but maintenance is unpleasant.
format-spec examples of the two usages quoted:
(let ((a 12) (b 15))
(format-spec "%a + %b = %u" (format-spec-make ?a a
?b b
?u (+ a b)))
(format-spec "Welcome to Emacs! Press %w to open the tutorial"
(format-spec-make ?w (with-temp-buffer
(where-is 'help-with-tutorial t)
(buffer-string))))
CP> (fmt "Today is $[date|%Y-%m-%d](current-time).")
CP> ⇒ "Today is 2016-12-07."
I see no advantage to this versus `format-time-string'. It's ambiguous
and the time zone can't be specified without making it more complicated.
This one in particular is heading in the direction of the way Ansible
integrates Jinja templates, which I think is not great compared to a
more Lispy approach.
Ted
Re: RFC: String interpolation, Lars Ingebrigtsen, 2016/12/10