From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Lars Ingebrigtsen Newsgroups: gmane.emacs.devel Subject: Re: RFC: String interpolation Date: Sat, 10 Dec 2016 16:39:00 +0100 Message-ID: References: <51825111-ace4-f750-4077-026a3b648d27@gmail.com> <8737hwnc52.fsf@lifelogs.com> <8c117f5c-209a-97d8-79ce-a78f707f0545@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1481384361 17899 195.159.176.226 (10 Dec 2016 15:39:21 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 10 Dec 2016 15:39:21 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) Cc: emacs-devel@gnu.org To: =?utf-8?Q?Cl=C3=A9ment?= Pit--Claudel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Dec 10 16:39:17 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 1cFjk4-0003vf-Vy for ged-emacs-devel@m.gmane.org; Sat, 10 Dec 2016 16:39:17 +0100 Original-Received: from localhost ([::1]:52123 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cFjk7-0005GW-GN for ged-emacs-devel@m.gmane.org; Sat, 10 Dec 2016 10:39:19 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35807) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cFjjx-0005FA-Bc for emacs-devel@gnu.org; Sat, 10 Dec 2016 10:39:10 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cFjju-0001R3-8m for emacs-devel@gnu.org; Sat, 10 Dec 2016 10:39:09 -0500 Original-Received: from hermes.netfonds.no ([80.91.224.195]:43075) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cFjju-0001Pp-1q for emacs-devel@gnu.org; Sat, 10 Dec 2016 10:39:06 -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 ) id 1cFjjo-0007wd-Pe; Sat, 10 Dec 2016 16:39:02 +0100 Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAHlBMVEX5x/GOHyHxtuX66f7J 8f70v+370ff73fv75f7GdX7eKVUhAAACa0lEQVQ4jWWTTU/bQBCGV5XiihsTqZS9QSoXfLbU+AdE LUcX1Yhjispa3CqKMssNEbXe3NggEfbf9p1dO6B2Do4zj9/Z+Vo1geVKjZpJ3jRqVJ82o6bGfzXJ 80apuYJlxhj5UcqYTE3qRhlxwRZCWN6Y1SR9mQAvFi3Dy2yhyABauC9nM+a2FTd3LKD//tts9pkX 4rXcOTVpBjCDtTEO266DQqWkfgh4y9BYiHqABLIIvkSv7ZyEUqpWc2N6IOacqwBqANODE3xurXPL UhQI9uYsHW5ddwy3KwXUiFQ8DOB6bZdlKaAGMIf6rL1BJNcVY+cSaCRdr88M35w413ktJ0QgXfYa DWX+ya4gaxOoR0pdCFgzF2wLf25TKEwJgAyH1ha2Owwfyh40KgP42IajP6H65PUWICmAJy6O7tbu nvRjDw4wqCuiMcBpcLcvIB/FUNr4zXVgvBz3dUh7R54o0OYWD/LnQx21yuZwEO3dyjNUL5VnphDX OxxFOpQ9qAXsIBaNv4rgoVfkEVxKLH0IfziuUndzqcNwESLQYVwmEwXWhK+Dp/F30v55AOmMduE9 7a5Ia/cPYGT0fkW0u9yCAwDsGWp4vifaL6vor/o6THsVgR9XCXRbgBKf7wiDlWw7x3GCAlDDJgG0 ygnIm7hvAhYCZBeqqQAVr5QfFLCyspxmDoVPZ9CvZQeF7K40y5h5UhBh4gDLfq8ycwHf5rcO9CiF pN3F9e7BvfYUJ14Nm5jNrwawv22JKIzsCSoH2HsF5N7uCFgBbOfRZ4X6aH+lMa1yaKLcnCwCafsA ptKS5j9QCWhie/1rUFXT6V9qZDDRhkFKVQAAAABJRU5ErkJggg== In-Reply-To: <8c117f5c-209a-97d8-79ce-a78f707f0545@gmail.com> (=?utf-8?Q?=22Cl=C3=A9ment?= Pit--Claudel"'s message of "Sat, 10 Dec 2016 09:25:57 -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." 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:210232 Archived-At: Cl=C3=A9ment Pit--Claudel writes: >> (let ((pvar (format "%.2f" variable))) >> "This number is ${pvar}s" >>=20 >> (You see the equivalent type of code in all languages that have "simple" >> string interpolation, like PHP, all the time.) > > I thought I adressed this case specifically in my proposal :/ > > (fmt "This number is $[%.2f]{pvar}s") Sure, you can add special cases to your domain-specific language to do any formatting you want to. Do you have a $[%] code for "strip out all the blanks from a string"? :-) The problem with string interpolation is, in general, that it isn't very general. And it isn't "composable": Once you hit a case that isn't covered, you have to rewrite the entire expression to a different form (i.e., traditional format strings with arguments afterwards), and I know from experience that people are loath to do that. Instead the temporary variables start popping up, obfuscating the code. So... I'm kinda on the "meh" side of the string interpolation debate. As Ted alluded to, there's a different, template based method that I think is more promising and is growing more popular in newer languages. In Emacs Lisp, you'd have either have a macro like (with-format ((zot "foo") (thing (funcall '+ 3.42423 4))) "This is %{thing}.2f and %{zot}ss") or (fmt "This is %{thing}.2f and %{zot}ss" zot (thing (funcall '+ 3.42423 4))) That is, named format arguments with format specs. You get all the advantages of normal format (i.e., the parameters are real code, not weirdly formatted things inside a string), but you don't have to match up the order of the parameters to the order of the % directives. --=20 (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no