🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.emacs.bug
Article #98512

Re: string evaluation seems inconsistent...

#98512
From: Todd Kaufmann
Date: Thu, 04 Jul 1991 05:33
60 lines
3004 bytes
In article <9107021544.AA01159@beast.icad.com> nick@icad.COM writes:

   If single backslashes are elided to no backslashes, shouldn't double
   backslashes be elided to single ones?

This seems to have come up a lot lately, so let's see if I can shed some light.


Strings are printed in a readable fashion, so lisp can read in the object.
If you use princ or (in elisp) insert, you get a non-(lisp)readable string.
Thus, to be readable, a backslash (and other special characters) are
escaped with a backslash.  Thus a string with a single backslash would be "\\",
and a string with a single doublequote would be "\"".  These would both
print in the same way, and are both strings of length one.

Any character can have a backslash before it; if it's not special, then it
doesn't change it's meaning.  Thus "\x" is the same as "x", and will print
it it's canonical form (as "x").  But "\"" is special, because it would
normally begin/end a string, and "\\" is special, because it's the escape
character.  THESE ARE THE ONLY TWO.  You can see for yourself with the
following, which will return a list of strings of length 1 for each of the
ascii characters (plus one).  You can put this in the *scratch* buffer or
any buffer in lisp-interaction-mode and type ^J after it.

(let ((l ())
      (i 0))
  (while (< i 129)
    (setq l (cons (char-to-string i) l)
	  i (1+ i)))
  (nreverse l))

The elisp reader syntax has been extended to allow such forms as \C-x, \M-z,
\123, \^k, \b, \r, \n, and similiar shorthands, but the are just that.
HOWEVER, you should always use them in your code because otherwise the
nasty mailer gateway will get you!  But the printer doesn't use these.
The printer will escape newlines if print-escape-newlines is non-nil, and
there's also the text-char-description function, Which is used by C-h c and
C-x =.


Here's one more example, a string consisting of quote, backslash and quote,
and the results of evaluating the forms from the scratch buffer:

    (setq qsq "\"\\\"")
    "\"\\\""
    (length qsq)
    3
    (mapcar '(lambda (c) c) qsq)
    (34 92 34)
    ;^   ^  ^
    ;|   |  |
    ;|   |  doublequote
    ;|   backslash
    ;doublequote



This seems like a FAQ.. is it in the list? (I should probably read it).

 -todd
Technical Details
Message-ID: <TODD.91Jul4143347@as03.atr.co.jp>
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!cis.ohio-state.edu!as03.ATr.co.JP!todd
References: <9107021544.AA01159@beast.icad.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fb2f1,5dc08851e7cafa4b
X-Google-Attributes: gidfb2f1,public
X-Google-ArrivalTime: 1991-07-03 22:33:47 PST
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!cis.ohio-state.edu!as03.ATr.co.JP!todd
From: todd@as03.ATr.co.JP (Todd Kaufmann)
Newsgroups: gnu.emacs.bug
Subject: Re: string evaluation seems inconsistent...
Message-ID: <TODD.91Jul4143347@as03.atr.co.jp>
Date: 4 Jul 91 05:33:47 GMT
References: <9107021544.AA01159@beast.icad.com>
Sender: gnulists@ai.mit.edu
Reply-To: todd@atr-la.atr.co.jp
Distribution: gnu
Organization: ATR Interpreting Telephony Research Labs., Japan
Lines: 60
Approved: bug-gnu-emacs@prep.ai.mit.edu