all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Simple stringification
@ 2010-02-22 17:36 Sean McAfee
  2010-02-22 18:01 ` Andreas Röhler
       [not found] ` <874ol95chl.fsf@galatea.lan.informatimago.com>
  0 siblings, 2 replies; 3+ messages in thread
From: Sean McAfee @ 2010-02-22 17:36 UTC (permalink / raw)
  To: help-gnu-emacs

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).

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


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

* Re: Simple stringification
  2010-02-22 17:36 Simple stringification Sean McAfee
@ 2010-02-22 18:01 ` Andreas Röhler
       [not found] ` <874ol95chl.fsf@galatea.lan.informatimago.com>
  1 sibling, 0 replies; 3+ messages in thread
From: Andreas Röhler @ 2010-02-22 18:01 UTC (permalink / raw)
  To: help-gnu-emacs

Sean McAfee wrote:
> 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).
> 
> Is there in fact a function that stringifies its single argument, and
> does nothing else?
> 

(string 88 99 ) --> "Xc"
(number-to-string 34)"34"

BTW I'm living well with format meanwhile, inserted via abbrev.

Andreas




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

* Re: Simple stringification
       [not found] ` <874ol95chl.fsf@galatea.lan.informatimago.com>
@ 2010-02-24 20:13   ` Stefan Monnier
  0 siblings, 0 replies; 3+ messages in thread
From: Stefan Monnier @ 2010-02-24 20:13 UTC (permalink / raw)
  To: help-gnu-emacs

>> 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))

Actually prin1-to-string seems to be predefined in my version of Emacs.


        Stefan


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

end of thread, other threads:[~2010-02-24 20:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-02-22 17:36 Simple stringification Sean McAfee
2010-02-22 18:01 ` Andreas Röhler
     [not found] ` <874ol95chl.fsf@galatea.lan.informatimago.com>
2010-02-24 20:13   ` Stefan Monnier

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.