Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Reading from file: without escape Backslash

94 views
Skip to first unread message

Thomas Guettler

unread,
Sep 6, 2002, 9:07:32 AM9/6/02
to
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

Tim Bradshaw

unread,
Sep 6, 2002, 9:30:35 AM9/6/02
to
* 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

Adam Warner

unread,
Sep 6, 2002, 9:55:07 AM9/6/02
to
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

Adam Warner

unread,
Sep 6, 2002, 9:57:44 AM9/6/02
to
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.

Thomas Guettler

unread,
Sep 6, 2002, 10:26:49 AM9/6/02
to
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

Adam Warner

unread,
Sep 6, 2002, 10:45:01 AM9/6/02
to
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

Erik Naggum

unread,
Sep 6, 2002, 6:30:05 PM9/6/02
to
* 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.

0 new messages