help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Simple stringification


From: Pascal J. Bourguignon
Subject: Re: Simple stringification
Date: Mon, 22 Feb 2010 19:52:54 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (darwin)

Sean McAfee <address@hidden> writes:

> I recently needed a function that stringifies its argument.  I wrote my
> own:
>
> (defun stringify (arg)
>   (format "%s" arg))
>
> But then I thought that Emacs probably ought to offer a standalone
> function for this.  I can't find one, though.  The docs for the format
> function state that the "%s" format sequence uses princ to print any
> object.  However, (princ my-object) also prints the stringification of
> my-object to the echo area, unless called with an additional argument,
> eg. (princ my-object 'identity).


You're on the right track.  At the end you'll find princ-to-string
(or prin1-to-string which is the equivalent to (format "%S" arg)).


> Is there in fact a function that stringifies its single argument, and
> does nothing else?

Well, not in emacs lisp.  Here you have to implement these standard(*)
functions yourself:

(defun princ-to-string (x) (format "%s" x))
(defun prin1-to-string (x) (format "%S" x))



(*) both by ANSI INCITS 226-1994 (R2004) and by historic practice, see
    the numerous lisp systems designed before emacs...
-- 
__Pascal Bourguignon__


reply via email to

[Prev in Thread] Current Thread [Next in Thread]