emacs-devel
[Top][All Lists]
Advanced

[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: Sat, 10 Dec 2016 15:11:17 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux)

Ted Zlatanov <address@hidden> writes:

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

Yeah, I'm similarly unenthusiastic about string interpolation.  It's not
that I love format strings -- first adding a %d somewhere in the string
and then figuring out where in the argument list to put the thing to be
output there isn't a great interface, either.

So I see the charms: Just write

  "This number is $variable".

But then you get to all the niggling little details involved: Well, how
about if I wanted an "s" after $variable...  Uhm, OK, then the syntax is

  "This number is ${variable}s".

Ok, but variable is a floating point number, and I only wanted two
decimals, so...  er...

  (let ((pvar (format "%.2f" variable)))
    "This number is ${pvar}s"

(You see the equivalent type of code in all languages that have "simple"
string interpolation, like PHP, all the time.)

Ok, but perhaps we can just allow random expressions instead of just
variables, so we have

  "This number is ${(format \"%.2f\" (/ variable 0.3))}s"

BEHOLD THE PRETTY!

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



reply via email to

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