[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: confused by the wierd "q" option of "string.format".
- From: Ross Berteig <Ross@...>
- Date: Thu, 07 Jul 2011 17:16:21 -0700
At 04:54 PM 7/7/2011, David Manura wrote:
>On Thu, Jul 7, 2011 at 4:48 PM, Ross Berteig
><Ross@cheshireeng.com> wrote:
>> C:...>lua -e "print(string.format('%q','abc\a'))"
>> "abc"
>> It may or may not have emitted the \007 represented by the \a,
>but if so it
>> was visually lost (and it didn't even go 'ding' [...]
>....
>OTOH,
>
> $ cat -A test.lua
> print((('abc^H^H^H123'):gsub('[^a-z]', '')))$
Cute.
As a programmer, I'm somewhat allergic to putting naked control
characters in string literals. The backslash escapes exist
because I'm not alone in that allergy. The %q format character is
valuable because it can turn any string content into source text
that recreates that string. The difficulty I have with it is that
it does so by making the least number of transformations that it
can at the possible cost of legibility to a human reader.
I'm just advocating gently for the ability to choose a stronger
mapping that is slightly more friendly to my use case. I'm not
necessarily advocating that the behavior of %q itself be changed
because there are times where getting the long lines broken in
the output would be preferred to deliberately folding them onto
one line.
Ross Berteig Ross@CheshireEng.com
Cheshire Engineering Corp. http://www.CheshireEng.com/