unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* How to concatenate a backslash to a string
@ 2006-11-27 16:37 Mirko
  2006-11-27 16:58 ` David Kastrup
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Mirko @ 2006-11-27 16:37 UTC (permalink / raw)


Hello group.

When in *scratch* I try
(concat "\\" "%")
I get "\\%"

But what I really want is to get "\%".   (I am trying to TeXify some
text and convert %->\%, $->\$, etc).

If I try (concat "\" "%") I get a syntax error because the \ is
escaping the ".

Many thanks,

Mirko

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How to concatenate a backslash to a string
  2006-11-27 16:37 How to concatenate a backslash to a string Mirko
@ 2006-11-27 16:58 ` David Kastrup
  2006-11-27 20:37   ` Kevin Rodgers
  2006-11-27 17:05 ` Robert Thorpe
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 6+ messages in thread
From: David Kastrup @ 2006-11-27 16:58 UTC (permalink / raw)


"Mirko" <mvukovic@nycap.rr.com> writes:

> Hello group.
>
> When in *scratch* I try
> (concat "\\" "%")
> I get "\\%"

Sure.

> But what I really want is to get "\%".

There is no such thing.  This is illegal string syntax.

> (I am trying to TeXify some text and convert %->\%, $->\$, etc).

Have you tried what happens if you do
(insert "\\%")
in a buffer?

> If I try (concat "\" "%") I get a syntax error because the \ is
> escaping the ".

Sure.  But you don't expect when typing
(insert "x")
that the quote characters end up in your buffer, as they are merely
part of the string syntax.  So why do you expect that the doubled
backslashes, which are merely part of the string syntax, end up in the
buffer?

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How to concatenate a backslash to a string
  2006-11-27 16:37 How to concatenate a backslash to a string Mirko
  2006-11-27 16:58 ` David Kastrup
@ 2006-11-27 17:05 ` Robert Thorpe
  2006-11-27 17:09 ` Perry Smith
       [not found] ` <mailman.1169.1164647400.2155.help-gnu-emacs@gnu.org>
  3 siblings, 0 replies; 6+ messages in thread
From: Robert Thorpe @ 2006-11-27 17:05 UTC (permalink / raw)


Mirko wrote:
> Hello group.
>
> When in *scratch* I try
> (concat "\\" "%")
> I get "\\%"
>
> But what I really want is to get "\%".   (I am trying to TeXify some
> text and convert %->\%, $->\$, etc).
>
> If I try (concat "\" "%") I get a syntax error because the \ is
> escaping the ".

In Lisp print and read are exact opposites.  What print emits will
produce the same data when read by read.  So, if read needs something
to be quoted then print must quote it.

If you do (concat "\\" %") the resulting string is \% if you do (princ
(concat "\\" "%")) you will see this.

When you just evaluate this though you effectively get (print (concat
"\\" "%")) and print quotes the \ so read can understand it later.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How to concatenate a backslash to a string
  2006-11-27 16:37 How to concatenate a backslash to a string Mirko
  2006-11-27 16:58 ` David Kastrup
  2006-11-27 17:05 ` Robert Thorpe
@ 2006-11-27 17:09 ` Perry Smith
       [not found] ` <mailman.1169.1164647400.2155.help-gnu-emacs@gnu.org>
  3 siblings, 0 replies; 6+ messages in thread
From: Perry Smith @ 2006-11-27 17:09 UTC (permalink / raw)
  Cc: help-gnu-emacs


On Nov 27, 2006, at 10:37 AM, Mirko wrote:

> Hello group.
>
> When in *scratch* I try
> (concat "\\" "%")
> I get "\\%"
>
> But what I really want is to get "\%".   (I am trying to TeXify some
> text and convert %->\%, $->\$, etc).
>
> If I try (concat "\" "%") I get a syntax error because the \ is
> escaping the ".

You may be getting what you want.  Notice that "\\" in the scratch  
buffer gives you back "\\" (I'm assuming you are hitting control-J to  
eval and print the line.

I don't think you can get any string in the scratch buffer to print  
like you want it.  It will always have an even number of \'s when  
printed.

Perry Smith ( pedz@easesoftware.com )
Ease Software, Inc. ( http://www.easesoftware.com )

Low cost SATA Disk Systems for IBMs p5, pSeries, and RS/6000 AIX systems

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How to concatenate a backslash to a string
       [not found] ` <mailman.1169.1164647400.2155.help-gnu-emacs@gnu.org>
@ 2006-11-27 18:27   ` Mirko
  0 siblings, 0 replies; 6+ messages in thread
From: Mirko @ 2006-11-27 18:27 UTC (permalink / raw)



Perry Smith wrote:
> On Nov 27, 2006, at 10:37 AM, Mirko wrote:
>
> > Hello group.
> >
> > When in *scratch* I try
> > (concat "\\" "%")
> > I get "\\%"
> >
> > But what I really want is to get "\%".   (I am trying to TeXify some
> > text and convert %->\%, $->\$, etc).
> >
> > If I try (concat "\" "%") I get a syntax error because the \ is
> > escaping the ".
>
> You may be getting what you want.  Notice that "\\" in the scratch
> buffer gives you back "\\" (I'm assuming you are hitting control-J to
> eval and print the line.
>
> I don't think you can get any string in the scratch buffer to print
> like you want it.  It will always have an even number of \'s when
> printed.
>
> Perry Smith ( pedz@easesoftware.com )
> Ease Software, Inc. ( http://www.easesoftware.com )
>
> Low cost SATA Disk Systems for IBMs p5, pSeries, and RS/6000 AIX systems

Thanks to all three of you.  Indeed, I was confused by the output in
the *scratch* buffer.  Once I tested the ouput of my commands in an
actual buffer, I was got the expected behavior: a single backslash
followd by whatever symbol I wanted.

Thanks again

Mirko

PS  Another newbie question is brewing, but I am still trying to figure
it out :-)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How to concatenate a backslash to a string
  2006-11-27 16:58 ` David Kastrup
@ 2006-11-27 20:37   ` Kevin Rodgers
  0 siblings, 0 replies; 6+ messages in thread
From: Kevin Rodgers @ 2006-11-27 20:37 UTC (permalink / raw)


David Kastrup wrote:
> "Mirko" <mvukovic@nycap.rr.com> writes:
>> But what I really want is to get "\%".
> 
> There is no such thing.  This is illegal string syntax.

<nit>
Not really: (equal "\%" "%") ==> t
</nit>

-- 
Kevin

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2006-11-27 20:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-11-27 16:37 How to concatenate a backslash to a string Mirko
2006-11-27 16:58 ` David Kastrup
2006-11-27 20:37   ` Kevin Rodgers
2006-11-27 17:05 ` Robert Thorpe
2006-11-27 17:09 ` Perry Smith
     [not found] ` <mailman.1169.1164647400.2155.help-gnu-emacs@gnu.org>
2006-11-27 18:27   ` Mirko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).