emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: RFC: String interpolation


From: Clément Pit--Claudel
Subject: Re: RFC: String interpolation
Date: Fri, 9 Dec 2016 17:45:16 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1

On 2016-12-09 14:19, Ted Zlatanov wrote:
> On Wed, 7 Dec 2016 20:13:41 -0500 Clément Pit--Claudel <address@hidden> 
> 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.

Thanks for the feedback! Can you share concrete examples in which this makes 
maintenance harder?

The approach I outlined is significantly influenced by the direction that 
Python is taking (see the PEP I linked to in the original message).

> (let ((a 12) (b 15))
>   (format-spec "%a + %b = %u" (format-spec-make ?a a
>                                                 ?b b
>                                                 ?u (+ a b)))

Thanks.  Are there benefits of this over just (format "%s + %s = %s" a b (+ a 
b))? The names ?a and ?b seem redundant, and ?u doesn't carry specific meaning. 
(FWIW, Python has template strings for that purpose, but virtually no one uses 
them, AFAICT).

Also: how does format-spec deal with formatting sequences, like %-3.2d?

> 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.

Yup; it's unfortunate that ELisp's notion of date doesn't come with a timezone.

> 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.

I have no strong feelings either way.  I like the way Python is going, so it 
feels natural to suggest the same direction for Emacs.  I view it as a 
convenient DSL for producing strings, just like the loop macro is a good DSL 
for iterating and accumulating results — and we're a Lisp, so we're good at 
DSLs :)

Clément.

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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