emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: RFC: String interpolation


From: Paul Eggert
Subject: Re: RFC: String interpolation
Date: Mon, 12 Dec 2016 12:41:38 -0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1

On 12/12/2016 11:51 AM, Ted Zlatanov wrote:
I like how this separates expressions from strings. It might be more
readable if the % begins the next string:

     (format "Altitude= " alt "%.2f, direction = " dir "%.2f.")

Unfortunately although this syntax is clean it would not be upward compatible, as 'format' currently silently discards excess trailing arguments. In contrast, Lars's suggestion:

(format "Altitude= %.2f%" alt ", direction = %.2f%" dir ".")

is upward compatible. Also, I suspect that Lars's suggestion will be less error-prone than mine, as it would be more likely to diagnose stray occurrences of "%" at the end of a format.

It has some downsides: it only works in one function; `(apply 'format ...)`
can become surprising; and repeating a parameter requires duplicating
the code.

True for repeating a nontrivial parameter. However, that is not common and 'let' should be good enough for that, e.g., (let ((dup (complicated expression))) (format "appearance1 = %f%" dup ", appearance2 = %g%." dup)).

I'm not sure what is meant mean by 'only works in one function'. format-message should behave like 'format', and any function that calls 'format' or 'format-message' will get the extended behavior for free. For example, (message ...) would get the extended behavior.

(apply 'format FMT ...) would not get the extended behavior unless FMT itself uses the extension, and this should be good enough to avoid most surprises.

Ah, perhaps you're thinking about mixed forms like (format "x = %1d, y = %2d%" EX WYE ", z = %3d" ZEE)? To avoid confusion, the extension could work only if the format string has just one conversion specifier, at the end (just before the "%" at end of string). The idea would be to encourage people to write either the extended (format "x = %1d%" EX ", y = %2d%" WYE ", z = %3d%" ZEE) or the traditional (format "x = %1d, y = %2d, z = %3d" EX WYE ZEE) instead of trying to write a confusing mixture of the two.



reply via email to

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