From: Thomas Guettler
Subject: Reading from file: without escape Backslash
Date: 
Message-ID: <ala97q$oc3$02$1@news.t-online.com>
Hi!

I have a lisp program which reads with

(setq *gefa-prog-dir* (pathname (read infile))
       *gefa-ext-prog-dir* (pathname (read infile))))

data from a file. The file looks like this:
"C:\\xuma\\"
"C:\\xuma\\gefa\\daten\\"

But unfortunately a different programm (installer) needs
these paths, too. But the installer want it to be with
only one backslash. I looked at the help of "read" but there
is no option for turning backslash interpretion off.

I will try to write a method which reads character by character,
but may be someone has a better solution?

Thank you

   thomas

From: Tim Bradshaw
Subject: Re: Reading from file: without escape Backslash
Date: 
Message-ID: <ey3d6rrxn2c.fsf@cley.com>
* Thomas Guettler wrote:


> I will try to write a method which reads character by character,
> but may be someone has a better solution?

don't quote the strings and use READ-LINE?

--tim
From: Adam Warner
Subject: Re: Reading from file: without escape Backslash
Date: 
Message-ID: <alabqu$1n7g42$1@ID-105510.news.dfncis.de>
Hi Thomas Guettler,

> data from a file. The file looks like this:
> "C:\\xuma\\"
> "C:\\xuma\\gefa\\daten\\"

The file only looks like that because you are writing the output with the
escape characters. Backslash is an escape character so to display a
backslash it has to be backslashed. You could print out the strings using
princ instead of write. Compare the difference by evaluating these:

(write "C:\\xuma\\gefa\\daten\\")
(princ "C:\\xuma\\gefa\\daten\\")

Write prints output that in a form that can (typically) be read back in.

There's a lot more to the Lisp printer: 
http://www.lispworks.com/reference/HyperSpec/Body/22_.htm

Regards,
Adam
From: Adam Warner
Subject: Re: Reading from file: without escape Backslash
Date: 
Message-ID: <alabvr$1n7g42$2@ID-105510.news.dfncis.de>
Hi Thomas Guettler,

> data from a file. The file looks like this:
> "C:\\xuma\\"
> "C:\\xuma\\gefa\\daten\\"

Perhaps the file only looks like that because you are writing the output
with the escape characters. Backslash is an escape character so to display a
backslash it has to be backslashed. You could print out the strings using
princ instead of write. Compare the difference by evaluating these:

(write "C:\\xuma\\gefa\\daten\\")
(princ "C:\\xuma\\gefa\\daten\\")

Write prints output in a form that can (typically) be read back in.

There's a lot more to the Lisp printer: 
http://www.lispworks.com/reference/HyperSpec/Body/22_.htm

Regards,
Adam
From: Thomas Guettler
Subject: Re: Reading from file: without escape Backslash
Date: 
Message-ID: <aladsg$obl$06$1@news.t-online.com>
Adam Warner schrieb:
> Hi Thomas Guettler,
> 
> 
>>data from a file. The file looks like this:
>>"C:\\xuma\\"
>>"C:\\xuma\\gefa\\daten\\"
[cut]
> Write prints output in a form that can (typically) be read back in.

But isn't \n a newline?

  thomas
From: Erik Naggum
Subject: Re: Reading from file: without escape Backslash
Date: 
Message-ID: <3240340205017513@naggum.no>
* Thomas Guettler
| But isn't \n a newline?

  In Common Lisp, \ in strings only really escapes the " that would terminate
  the string, but since there is a need for an escape character, also itself.
  Another way to do this would be let two delimiters become one, but that was
  a path not taken for Common Lisp.  The reason for this is that \ is useful
  to make certain that any character is really a constituent in the print name
  of symbols.  Note that Common Lisp has both a single-escape and a
  multiple-escape mechanism with \ and |, respectively.  The latter, however,
  also makes letters retain their case, so the decision to use | over \ also
  has to be balanced for aesthetics.  There is nothing syntactically wrong in
  writing code |with| |symbols| |like| |this|, but it tends to get on people's
  nerves.

-- 
Erik Naggum, Oslo, Norway

Act from reason, and failure makes you rethink and study harder.
Act from faith, and failure makes you blame someone and push harder.
From: Adam Warner
Subject: Re: Reading from file: without escape Backslash
Date: 
Message-ID: <alaeog$1o3f7e$1@ID-105510.news.dfncis.de>
Hi Thomas Guettler,

> But isn't \n a newline?

No, \n is the character n. You can see this from a Lisp console:

[1]> "\n"
"n"

Newlines in Lisp strings are typed in as actual newlines:

[2]> "line1 
line2"
"line1
line2"

You cannot express them using escape notation.

If you are concatenating a string just take the string of the newline
character:

[3]> (concatenate 'string "line1" (string #\Newline) "line2")
"line1
line2"

Which is exactly the same output as above.

A more compact way is using the format function:

[4]> (format nil "line1~%line2")
"line1
line2"

t prints (it doesn't just return a string):

[5]> (format t "line1~%line2")
line1
line2

You can can even produce multiple newlines:

[6]> (format t "line1~5%line2")
line1




line2

Regards,
Adam