On 2015-03-26, Nicolas Hafner <
shin...@tymoon.eu> wrote:
> On 26/03/15 09:10,
jara...@skynet.be wrote:
>> Hi,
>> given a multi-line string
>>
>> "abc
>> def"
>>
>> I'd like to "align" the lines. In other programming languages one can escape
>> the line end with a backslash like
>>
>> "\
>> abc
>> def"
>>
>> Is there a replacement in Common Lisp?
>>
>> Many thanks
>> Helmut
>>
>
> A bit ugly, but you can do something like
>
> #.(format NIL "foo~
> bar~
> baz")
>
> resulting in
>
> "foobarbaz"
In TXR, I experimented in this area.
Firstly, literals do not span lines (possibly a design mistake, but
one that could be fixed later):
$ txr -p '"abc
def"'
txr: (string:2): syntax error
txr: (string:2): newline in string literal
txr: unhandled exception of type syntax-error:
txr: message: read: syntax error
Escaped newline deletes all surrounding unescaped whitespace, from
current line and following line:
$ txr -p '"abc \
def"'
"abcdef"
Escaped space is preseved:
$ txr -p '"abc\ \
def"'
"abc def"
... on either side of the line continuation:
$ txr -p '"abc\
\ def"'
"abc def"
C-like escapes encode special characters, so \n for newline.
We achieve a multi-line string with a desired indentation:
$ txr -P '"abc\x6f22\x5b57\n\
\ def\n\
\ ghi\n"
abc漢字
def
ghi
Largely a no-brainer.