From mboxrd@z Thu Jan  1 00:00:00 1970
Path: news.gmane.org!.POSTED!not-for-mail
From: Lars Ingebrigtsen <larsi@gnus.org>
Newsgroups: gmane.emacs.devel
Subject: Re: RFC: String interpolation
Date: Sat, 10 Dec 2016 15:11:17 +0100
Message-ID: <m34m2bj2m2.fsf@gnus.org>
References: <51825111-ace4-f750-4077-026a3b648d27@gmail.com>
	<8737hwnc52.fsf@lifelogs.com>
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: blaine.gmane.org 1481379103 15120 195.159.176.226 (10 Dec 2016 14:11:43 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Sat, 10 Dec 2016 14:11:43 +0000 (UTC)
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux)
To: emacs-devel@gnu.org
Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Dec 10 15:11:39 2016
Return-path: <emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org>
Envelope-to: ged-emacs-devel@m.gmane.org
Original-Received: from lists.gnu.org ([208.118.235.17])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org>)
	id 1cFiNG-000373-9i
	for ged-emacs-devel@m.gmane.org; Sat, 10 Dec 2016 15:11:38 +0100
Original-Received: from localhost ([::1]:51904 helo=lists.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org>)
	id 1cFiNK-0003vK-BR
	for ged-emacs-devel@m.gmane.org; Sat, 10 Dec 2016 09:11:42 -0500
Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:48656)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <larsi@gnus.org>) id 1cFiND-0003uj-1p
	for emacs-devel@gnu.org; Sat, 10 Dec 2016 09:11:36 -0500
Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <larsi@gnus.org>) id 1cFiN9-0004df-3L
	for emacs-devel@gnu.org; Sat, 10 Dec 2016 09:11:35 -0500
Original-Received: from hermes.netfonds.no ([80.91.224.195]:42199)
	by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)
	(Exim 4.71) (envelope-from <larsi@gnus.org>) id 1cFiN8-0004aI-Ry
	for emacs-devel@gnu.org; Sat, 10 Dec 2016 09:11:31 -0500
Original-Received: from cm-84.215.1.64.getinternet.no ([84.215.1.64] helo=stories)
	by hermes.netfonds.no with esmtpsa
	(TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2)
	(envelope-from <larsi@gnus.org>) id 1cFiMv-00007L-7h
	for emacs-devel@gnu.org; Sat, 10 Dec 2016 15:11:19 +0100
Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAIVBMVEWzAACwAAC5Gxy1AACy
	AACvAAD25ub////+//60AACxAABxG9DcAAACWUlEQVQ4jYWUMW/bMBCFmYRD5amHmh042kGaMTCB
	ANzk4Fqg3FSUS0YHiDNncDwnRbwSlRd2MgG6A39lj5Jsy8nQGwSBn47veHpHtnraxeEtB/s/WN7P
	Rvfz92AxkokVp/dvweI8iYRlMbk4BouxMyIy5vTp/AjMWJm2EZl39e9VDyzOMUmB+L3Qtbo8gOXM
	YwKxwaLwhZ+s9mAxZhGnAnl5pr1qUxrwrByWBkiCsVrp6z24U5olhKFj3rMzNZl3YDFW2q8N0Dmi
	p62avTJ4VqpgZgBhGrHI4LoDd7owJqGAAKZ0BCYtWN6RtoStraywsUmZt2Cs1j5FYa0IMmJd6w4s
	lHKcI9gqBIml10p96UCtEWOwt8Ow4XSQpiwCz6r2nCfSkBDZptBNWQQeCQzkljRskpEXjtXXXYZz
	CWwOGdNJxLIDL8q70KxX1oIUJXOTBvxSnn21u6gsteamBYz1AADI2IIX7fi0qjoQDuBRM9wDkFMI
	H/8eAFCfqkYBqC8doB5GCARyzZWcVvCta8maI21dwZYeAuiLDy24YozTkgUR6Dw57bJru/NskIFM
	KWtZMe/+oNLrJAOdjCJn/NyBWg1waGxVJfIjffBjZwZd/4nSkHCClLf6vLMPmUfeCitkksa22q3h
	xnpAsrcAwxRp/dN8b1G9QbJ7AGnC9ER87pn6qhyakAxSWUM4mJoKVp6TQPZEvDmMQXaQ8iY6hxji
	RW+iljMivKSxYfy0P2rZ8IoXjOapfjge51ciihyl34xzJnnK9mPeuzJeZ6PRxcPqPXhaHt0zPXAc
	/wA7eacPCFSlIgAAAABJRU5ErkJggg==
In-Reply-To: <8737hwnc52.fsf@lifelogs.com> (Ted Zlatanov's message of "Fri, 09
	Dec 2016 14:19:37 -0500")
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
	[fuzzy]
X-Received-From: 80.91.224.195
X-BeenThere: emacs-devel@gnu.org
X-Mailman-Version: 2.1.21
Precedence: list
List-Id: "Emacs development discussions." <emacs-devel.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/emacs-devel>,
	<mailto:emacs-devel-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/emacs-devel/>
List-Post: <mailto:emacs-devel@gnu.org>
List-Help: <mailto:emacs-devel-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/emacs-devel>,
	<mailto:emacs-devel-request@gnu.org?subject=subscribe>
Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org
Original-Sender: "Emacs-devel" <emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org>
Xref: news.gmane.org gmane.emacs.devel:210229
Archived-At: <http://permalink.gmane.org/gmane.emacs.devel/210229>

Ted Zlatanov <tzz@lifelogs.com> 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