From: Ted Zlatanov <tzz@lifelogs.com>
To: emacs-devel@gnu.org
Subject: Re: RFC: String interpolation
Date: Sat, 10 Dec 2016 21:53:59 -0500 [thread overview]
Message-ID: <87wpf7kwfs.fsf@lifelogs.com> (raw)
In-Reply-To: d428e876-1db3-b5bd-129f-34d8440f83dc@gmail.com
On Fri, 9 Dec 2016 17:45:16 -0500 Clément Pit--Claudel <clement.pit@gmail.com> wrote:
CP> On 2016-12-09 14:19, Ted Zlatanov wrote:
>> On Wed, 7 Dec 2016 20:13:41 -0500 Clément Pit--Claudel <clement.pit@gmail.com> wrote:
>> 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.
CP> Thanks for the feedback! Can you share concrete examples in which
CP> this makes maintenance harder?
Just imagine *any* Perl code "@{[ inside here ]}" and you're ready.
Things like embedded hash slices, in-place sorts or Schwarzian
transforms...
(let ((a 12) (b 15))
(format-spec "%a + %b = %u" (format-spec-make ?a a
?b b
?u (+ a b)))
CP> Thanks. Are there benefits of this over just (format "%s + %s = %s" a b (+ a
CP> b))? The names ?a and ?b seem redundant, and ?u doesn't carry specific meaning.
Yes, of course. It's the same as positional vs. named arguments to
functions. In (format "%s %s %s" x y z) you have to remember each
parameter, and if you want to repeat x twice you have to write it two
times.
To take a step back, imagine a spectrum. At one end is (format "%s %s
%s" ...) which is fast, easy to implement, familiar to those who know
sprintf, and anonymizes the template data, filtering it through a type
expression. This is extremely popular and is not going away.
The middle of the spectrum are things like Mustache {{ foo }} and
`format-spec' which separate the format from the data but have an alias
for each data item. And at the other end we see your approach and
Ansible+Jinja and Perl etc. which directly refer to the variables in
scope and basically try to reinvent the language in a "portable" format
that can be embedded in a string. If you're set on doing this, please
just fall through to the underlying language, e.g.
"$(format \"%3.2s\" myvar) $(myothervar)"
CP> Also: how does format-spec deal with formatting sequences, like %-3.2d?
It doesn't. You would convert that before passing it to the function.
You can consider that a deficiency (if you prefer the printf style) or
good (if you like the Mustache style).
>> 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.
CP> I have no strong feelings either way. I like the way Python is going, so it
CP> feels natural to suggest the same direction for Emacs. I view it as a convenient
CP> DSL for producing strings, just like the loop macro is a good DSL for iterating
CP> and accumulating results — and we're a Lisp, so we're good at DSLs :)
I think it's good to experiment. As currently proposed, I wouldn't want
to *maintain* code that used your approach. But I could be wrong about
it, and my advice was based on personal intuition and experience. So I
hope you found it useful rather than discouraging :)
Ted
next prev parent reply other threads:[~2016-12-11 2:53 UTC|newest]
Thread overview: 86+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-08 1:13 RFC: String interpolation Clément Pit--Claudel
2016-12-08 8:27 ` Andreas Schwab
2016-12-08 8:38 ` Joost Kremers
2016-12-08 9:05 ` Philippe Vaucher
2016-12-08 18:25 ` Clément Pit--Claudel
2016-12-08 9:02 ` Philippe Vaucher
2016-12-08 18:22 ` Clément Pit--Claudel
2016-12-08 14:43 ` Joost Kremers
2016-12-08 18:37 ` Clément Pit--Claudel
2016-12-08 20:04 ` Stefan Monnier
2016-12-09 8:57 ` Joost Kremers
2016-12-08 15:51 ` Drew Adams
2016-12-08 18:21 ` Clément Pit--Claudel
2016-12-08 20:38 ` Richard Stallman
[not found] ` <<E1cF5SK-0000HO-EL@fencepost.gnu.org>
2016-12-08 22:04 ` Drew Adams
2016-12-08 19:05 ` Stefan Monnier
2016-12-08 19:31 ` Clément Pit--Claudel
2016-12-08 21:31 ` Stefan Monnier
2016-12-10 16:01 ` Clément Pit--Claudel
2016-12-09 19:19 ` Ted Zlatanov
2016-12-09 22:45 ` Clément Pit--Claudel
2016-12-11 2:53 ` Ted Zlatanov [this message]
2016-12-11 18:46 ` Lars Ingebrigtsen
2016-12-11 18:56 ` Clément Pit--Claudel
2016-12-11 19:34 ` Lars Ingebrigtsen
2016-12-11 17:38 ` Stefan Monnier
2016-12-11 17:53 ` Clément Pit--Claudel
2016-12-10 14:11 ` Lars Ingebrigtsen
2016-12-10 14:25 ` Clément Pit--Claudel
2016-12-10 15:39 ` Lars Ingebrigtsen
2016-12-10 15:49 ` Clément Pit--Claudel
2016-12-10 16:01 ` Yuri Khan
2016-12-10 17:58 ` Clément Pit--Claudel
2016-12-11 17:47 ` Stefan Monnier
2016-12-11 19:31 ` Yuri Khan
2016-12-11 20:12 ` Stefan Monnier
2016-12-11 9:35 ` Richard Stallman
2016-12-11 16:29 ` Clément Pit--Claudel
2016-12-11 18:42 ` Lars Ingebrigtsen
2016-12-12 19:41 ` Richard Stallman
2016-12-11 18:41 ` Lars Ingebrigtsen
2016-12-11 21:05 ` Helmut Eller
2016-12-11 21:26 ` Lars Ingebrigtsen
2016-12-12 2:39 ` Stefan Monnier
2016-12-12 9:44 ` Lars Ingebrigtsen
2016-12-12 13:03 ` Stefan Monnier
2016-12-12 14:47 ` Lars Ingebrigtsen
2016-12-12 15:04 ` Stefan Monnier
2016-12-12 15:26 ` Lars Ingebrigtsen
2016-12-12 17:05 ` Stefan Monnier
2016-12-12 17:12 ` Lars Ingebrigtsen
2016-12-12 17:23 ` Stefan Monnier
2016-12-12 13:40 ` Clément Pit--Claudel
2016-12-12 14:43 ` Lars Ingebrigtsen
2016-12-12 14:54 ` Clément Pit--Claudel
2016-12-12 17:14 ` Stefan Monnier
2016-12-12 17:46 ` Paul Eggert
2016-12-12 18:33 ` Lars Ingebrigtsen
2016-12-12 19:51 ` Ted Zlatanov
2016-12-12 20:41 ` Paul Eggert
2016-12-12 23:40 ` Paul Eggert
2016-12-13 17:42 ` Richard Stallman
2016-12-13 18:05 ` Paul Eggert
2016-12-13 23:55 ` Lars Ingebrigtsen
2016-12-14 0:07 ` Paul Eggert
2016-12-14 0:10 ` John Wiegley
2016-12-14 0:14 ` Lars Ingebrigtsen
2016-12-14 0:17 ` Paul Eggert
2016-12-14 0:26 ` John Wiegley
2016-12-14 1:48 ` Drew Adams
2016-12-14 2:48 ` Elias Mårtenson
2016-12-14 3:33 ` Drew Adams
2016-12-14 3:52 ` Elias Mårtenson
2016-12-14 13:52 ` Lars Brinkhoff
2016-12-14 13:57 ` Lars Brinkhoff
2016-12-14 0:24 ` Drew Adams
2016-12-14 0:21 ` Clément Pit--Claudel
2016-12-14 14:10 ` Lars Ingebrigtsen
2016-12-14 17:00 ` Richard Stallman
2016-12-12 19:43 ` Richard Stallman
2016-12-12 21:11 ` Lars Ingebrigtsen
2016-12-13 17:41 ` Richard Stallman
2016-12-13 17:43 ` Lars Ingebrigtsen
2016-12-14 17:01 ` Richard Stallman
2016-12-13 1:04 ` Ted Zlatanov
2016-12-12 16:39 ` Helmut Eller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87wpf7kwfs.fsf@lifelogs.com \
--to=tzz@lifelogs.com \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.