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

Escaping in strings

4 views
Skip to first unread message

Thomas Strathmann

unread,
Nov 11, 2001, 5:45:50 PM11/11/01
to
Hello,

First of all, forgive me, if this is a trivial and stupid question but I am
really stuck at this point (just in the process of learning things):
I need to pass the string "\304" but the \ is just left out by the reader.
\\ like in C does not have the desired effect and everything else does not
do anything useful either... Please help me.


Regards,
Thomas

--
Thomas S. Strathmann http://pdp7.org
Lisp - Because today is the car of the cdr of your life

had...@worldnet.att.net

unread,
Nov 11, 2001, 6:08:49 PM11/11/01
to
Thomas Strathmann wrote:

> First of all, forgive me, if this is a trivial and stupid question but I am
> really stuck at this point (just in the process of learning things):
> I need to pass the string "\304" but the \ is just left out by the reader.
> \\ like in C does not have the desired effect and everything else does not
> do anything useful either... Please help me.

I think "\\304" is what you really want. Remember when you type it into
a listener, the response you get is going to be readable, hence will
still look like "\\304". However, this is because you're still seeing
the extra \ that is doing the escaping.

Mayb the following little dialog with my listener will make things
clearer:

CL-USER 9 > (setf str "\\304")
"\\304"

CL-USER 10 > (length str)
4

CL-USER 11 > (loop for i below (length str) collecting (char str i))
(#\\ #\3 #\0 #\4)


--
Howard Ding
had...@worldnet.att.net
http://math.sunysb.edu/~hading http://thunder.prohosting.com/~hading

Kaz Kylheku

unread,
Nov 11, 2001, 6:21:12 PM11/11/01
to
In article <slrn9utvsr...@adams.pdp7.org>, Thomas Strathmann wrote:
>Hello,
>
>First of all, forgive me, if this is a trivial and stupid question but I am
>really stuck at this point (just in the process of learning things):
>I need to pass the string "\304" but the \ is just left out by the reader.
>\\ like in C does not have the desired effect and everything else does not
>do anything useful either... Please help me.

In Common Lisp, which I assume you are using, \\ does in fact have the
right effect. It specifies a single backslash character so that

"\\304"

is a four-character string object consisting of the characters

#\\ #\3 #\0 #\4.

However, perhaps you are being confused by the printed representation
of that string which the Lisp system is producing back to you. If you
print the string like this:

(prin1 "\\304")

then you will get the output

"\\304"

quotes, double backslash and all. That's simply because the prin1 function
produces a representation of an object in a form that can be read back
to reproduce that object.

Try:

(princ "\\304")(terpri)

or

(format t "~a~%" "\\304")

Also, try experimenting with setting the *print-escape* variable to nil:

(setf *print-escape* nil)

Hope that helps.

Erik Naggum

unread,
Nov 11, 2001, 10:49:05 PM11/11/01
to
* Thomas Strathmann

| First of all, forgive me, if this is a trivial and stupid question but I am
| really stuck at this point (just in the process of learning things):
| I need to pass the string "\304" but the \ is just left out by the reader.
| \\ like in C does not have the desired effect and everything else does not
| do anything useful either... Please help me.

If you want to write in C, I think actually writing in C is your best bet
for the "desired effect". If you want to know what the "desired effect"
_should_ be when you are writing in _any_ programming language, you need
to be looking for that rules of that language, not some other. E.g., if
a language decides to mimic C in some ways, it is a rule of that language.

In Common Lisp, a string is delimited by "", within which a \ will escape
the following \ or ". A symbol name may be delimited by || within which
a \ will escape the following \ or |. Outside of either, a \ will cause
the next character to be considered a constituent character of a symbol
name regardless of any other traits it might have had. That is all.

///
--
Norway is now run by a priest from the fundamentalist Christian People's
Party, the fifth largest party representing one eighth of the electorate.
--
Carrying a Swiss Army pocket knife in Oslo, Norway, is a criminal offense.

Thomas Strathmann

unread,
Nov 12, 2001, 4:07:54 AM11/12/01
to
Hello,

and thank you all for your great help. I really appreciate it and now it
works. As I suspected I was the one that was wrong... ;-)

Regards,
Thomas


PS: I must really say this is the first newsgroup I really enjoy because
you people really care about CL and spreading knowlegde. Most of the
longer threads have been very enlightening for me and the length and
detail of many of the answers here clearly show that Lispers are
something "special". ;-) Thanks again.

0 new messages