From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Ted Zlatanov Newsgroups: gmane.emacs.devel Subject: Re: RFC: String interpolation Date: Fri, 09 Dec 2016 14:19:37 -0500 Organization: =?utf-8?B?0KLQtdC+0LTQvtGAINCX0LvQsNGC0LDQvdC+0LI=?= @ Cienfuegos Message-ID: <8737hwnc52.fsf@lifelogs.com> References: <51825111-ace4-f750-4077-026a3b648d27@gmail.com> Reply-To: emacs-devel@gnu.org NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1481311235 1302 195.159.176.226 (9 Dec 2016 19:20:35 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 9 Dec 2016 19:20:35 +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 Fri Dec 09 20:20:30 2016 Return-path: 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 ) id 1cFQiZ-0007ji-Rp for ged-emacs-devel@m.gmane.org; Fri, 09 Dec 2016 20:20:27 +0100 Original-Received: from localhost ([::1]:48350 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cFQid-00006I-Sh for ged-emacs-devel@m.gmane.org; Fri, 09 Dec 2016 14:20:31 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33762) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cFQhy-0008Oe-64 for emacs-devel@gnu.org; Fri, 09 Dec 2016 14:19:51 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cFQhv-00036v-2W for emacs-devel@gnu.org; Fri, 09 Dec 2016 14:19:50 -0500 Original-Received: from [195.159.176.226] (port=35000 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cFQhu-000369-Rf for emacs-devel@gnu.org; Fri, 09 Dec 2016 14:19:47 -0500 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1cFQhn-0000Kz-Ne for emacs-devel@gnu.org; Fri, 09 Dec 2016 20:19:39 +0100 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: emacs-devel@gnu.org Original-Lines: 41 Original-X-Complaints-To: usenet@blaine.gmane.org X-Face: bd.DQ~'29fIs`T_%O%C\g%6jW)yi[zuz6; d4V0`@y-~$#3P_Ng{@m+e4o<4P'#(_GJQ%TT= D}[Ep*b!\e,fBZ'j_+#"Ps?s2!4H2-Y"sx" Mail-Copies-To: never Cancel-Lock: sha1:HZ+LUBW+xXwpu0RTsxFz6xutqBM= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.159.176.226 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:210201 Archived-At: On Wed, 7 Dec 2016 20:13:41 -0500 Clément Pit--Claudel wrote: CP> With the attached fmt.el, you can write things like this: CP> (let ((a 12) (b 15)) CP> (fmt "$a + $b = $(+ a b)")) CP> ⇒ "12 + 15 = 27" ... CP> (fmt "Welcome to Emacs! " CP> "Press $[where-is]{'help-with-tutorial} to open the tutorial.") CP> ⇒ "Welcome to Emacs! Press C-h t to open the tutorial." 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. format-spec examples of the two usages quoted: (let ((a 12) (b 15)) (format-spec "%a + %b = %u" (format-spec-make ?a a ?b b ?u (+ a b))) (format-spec "Welcome to Emacs! Press %w to open the tutorial" (format-spec-make ?w (with-temp-buffer (where-is 'help-with-tutorial t) (buffer-string)))) CP> (fmt "Today is $[date|%Y-%m-%d](current-time).") CP> ⇒ "Today is 2016-12-07." 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. 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. Ted