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: Mon, 12 Dec 2016 10:44:30 +0100
Message-ID: <m3r35dcwht.fsf@gnus.org>
References: <51825111-ace4-f750-4077-026a3b648d27@gmail.com>
	<8737hwnc52.fsf@lifelogs.com> <m34m2bj2m2.fsf@gnus.org>
	<8c117f5c-209a-97d8-79ce-a78f707f0545@gmail.com>
	<m3wpf7hjzf.fsf@gnus.org>
	<76c9c475-0180-aa49-3d4a-006d4e3f943c@gmail.com>
	<m3oa0ifgvd.fsf@gnus.org> <m2k2b6rxaj.fsf@gmail.com>
	<m38trmdun6.fsf@gnus.org>
	<jwvr35dub31.fsf-monnier+gmane.emacs.devel@gnu.org>
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: blaine.gmane.org 1481535954 11188 195.159.176.226 (12 Dec 2016 09:45:54 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Mon, 12 Dec 2016 09:45:54 +0000 (UTC)
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux)
Cc: emacs-devel@gnu.org
To: Stefan Monnier <monnier@iro.umontreal.ca>
Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Dec 12 10:45:50 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 1cGNB7-0001lG-OA
	for ged-emacs-devel@m.gmane.org; Mon, 12 Dec 2016 10:45:49 +0100
Original-Received: from localhost ([::1]:59810 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 1cGNBA-0002Bq-Bx
	for ged-emacs-devel@m.gmane.org; Mon, 12 Dec 2016 04:45:52 -0500
Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57766)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <larsi@gnus.org>) id 1cGNA0-0001xD-7h
	for emacs-devel@gnu.org; Mon, 12 Dec 2016 04:44:42 -0500
Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <larsi@gnus.org>) id 1cGN9x-0004Wz-2n
	for emacs-devel@gnu.org; Mon, 12 Dec 2016 04:44:40 -0500
Original-Received: from hermes.netfonds.no ([80.91.224.195]:42667)
	by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)
	(Exim 4.71) (envelope-from <larsi@gnus.org>) id 1cGN9w-0004VJ-RI
	for emacs-devel@gnu.org; Mon, 12 Dec 2016 04:44:36 -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 1cGN9q-0000hv-Ac; Mon, 12 Dec 2016 10:44:32 +0100
Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAElBMVEX+//ybgIYGAwQsHyLj
	0dL79fDWXDK3AAACRUlEQVQ4jV2US5LcIAyG5QrsRwYfwGKyD+DsrW55b9eY+18lEv0OC1ylDwk9
	fgwcMTIir6DLbb6diK0QwcE4BcTwAGcgSmRAcDKnrxtooxppKQTMGihG6MvJWQwESjBoGER8ADb7
	XDqIx4DS7f4UNXGoeg0cJzxXO696XAQLIRzHy66pFlpEjkARhuENCI4GOJf8igO+idQrZWTJXOD9
	BhHCWVPEIPjhEJG0C1HBo7D7DVea86VE88kfkZjqGPQSxEofkQLVslCq2br7BKfkQJpt7+IbsJwq
	jSn+6vb0AUYKWSshqi8gmlOtCTOh2pGqdlrkmsFF7QQm0dlcZ6w6B6fHLwnc6WXleecQQsrZ61EQ
	MaAu6zBLnUvKK24GWgd75PVIJaEwqEIMnDgmODPzOmb8Fgk7eNdD6RAyp4gy7y5uQ9213H6575lv
	Yp1zq7OOu2jpskks67fuDveDZRfubb+oAqoWziVjjT/VJtWB9nK+bFroOGetr2K+gWCa/JnUQwWY
	czAPVDCoPS/Db+2MCe0OFqgaKK1XXhjDG0Cw3mtuhe6r3uwRkqkOYEyaUe0jyjfw5bugx6lp27PN
	tYPpPidHqp5gwuog1OUBks6WJbLVZHN6KNGnLt0olqPaZXvMfNz1vSoYzUOb8AZMo5GtlPgBTIvn
	0p/g/wDaIayhkryDahkczbL6/gBp1e2w55/0rUlrz1Ckv4bNnv+8yNbaDvsNHPQH3JcvoaSpNQNt
	v72O074+HBeauh1s9952C9t+Lulvt/8DjY+Sa4dwujQAAAAASUVORK5CYII=
In-Reply-To: <jwvr35dub31.fsf-monnier+gmane.emacs.devel@gnu.org> (Stefan
	Monnier's message of "Sun, 11 Dec 2016 21:39:30 -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:210332
Archived-At: <http://permalink.gmane.org/gmane.emacs.devel/210332>

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>>> Keyword paramaters are also an option:
>>> (fmt "This is %{thing}.2f and %{zot}ss" :thing (funcall '+ 3.42423 4))
>> Yeah, that's prettier.
>
> FWIW, I don't see why that's preferable to
>
>     (let ((thing (funcall '+ 3.45453 4)))
>       (preformat "This is %[2f]{thing} and %{zot}ss"))

I think it's preferable in a code life cycle perspective.  You frequently
start out with

(fmt "This is %{thing}.2f")

because you have something in a variable you want to output.  But then
you see that you have to alter it before display, so then you have

(let ((thing-formatted (replace-regexp-in-string " +" " " thing)))
  (fmt "This is %{thing-formatted}.2f"))

That is, you're forced to both name and introduce a new temporary
variable, and you have to alter the format statement itself.  (This is
what PHP programmers do all the time, and it kinda sucks.)

With the optional keyword arguments, you just add it:

  (fmt "This is %{thing}.2f"
       :thing (replace-regexp-in-string " +" " " thing))

This sucks slightly less, in my opinion.

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