[gnu.emacs.bug] "format" function suggestion

phr@WHEATIES.AI.MIT.EDU (Paul Rubin) (10/05/88)

I suggest a new conversion spec, "%g" perhaps (after
G format in Fortran), to convert any object to its
printed form like prin1-to-string.
Also (nitpick) format's doc str does not describe %o or %x.

merlyn@intelob.intel.com (Randal L. Schwartz @ Stonehenge) (10/06/88)

In article <8810050713.AA02552@wheat-chex.ai.mit.edu>, phr@WHEATIES (Paul Rubin) writes:
| I suggest a new conversion spec, "%g" perhaps (after
| G format in Fortran), to convert any object to its
| printed form like prin1-to-string.
| Also (nitpick) format's doc str does not describe %o or %x.

And, as 18 people around the world are probably also typing in an
answer to say,

  (format "%s" val)

is identical to

  (format "%s" (prin1-to-string val))

because of some very handy undocumented feature.  I found this one the
hard way.
-- 
Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095
on contract to BiiN Technical Information Services (for now :-),
in a former Intel building in Hillsboro, Oregon, USA
<merlyn@intelob.intel.com> or ...!tektronix!inteloa[!intelob]!merlyn
Standard disclaimer: I *am* my employer!

phr@WHEATIES.AI.MIT.EDU (Paul Rubin) (10/08/88)

%s apparently does the right thing.
The `format' doc string incorrectly says that
the arg for %s must be a string or a symbol.

fons@cs.vu.nl (Fons Botman) (10/17/88)

In article <2977@mipos3.intel.com> merlyn@intelob.intel.com (Randal L. Schwartz @ Stonehenge) writes:
>In article <8810050713.AA02552@wheat-chex.ai.mit.edu>, phr@WHEATIES (Paul Rubin) writes:
>| I suggest a new conversion spec, "%g" perhaps (after
>| G format in Fortran), to convert any object to its
>| printed form like prin1-to-string.
>| Also (nitpick) format's doc str does not describe %o or %x.
>
>And, as 18 people around the world are probably also typing in an
>answer to say,
>  (format "%s" val)
>is identical to
>  (format "%s" (prin1-to-string val))
>because of some very handy undocumented feature.  I found this one the
>hard way.
>-- 
>Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095

And, as 18 people around the world are probably also typing in an
answer to say,
(format "%s" (prin1-to-string 'a\ b))
"a\\ b"
(format "%s" 'a\ b)
"a b"
(format "%s" (prin1-to-string '(a\ b)))
"(a\\ b)"
(format "%s" '(a\ b))
"(a\\ b)"

So the identity mentioned is not always true.  But because of the difference
between "princ" and "print" i agree with the original poster that there should
be an extra format to distinguish between princ and prin1 conversion.
An extra format character is nicer than using prin1-to-string and
princ-to-string (also because the latter does not exist :-).

It would be nice to have the same specifiers as common lisp, i do not relate
to fortran. CL uses ~s for prin1 and ~a for princ, but then the original
definition should be switched: %s now behaves as ~a (considering the
documentation and code, not the 'feature') which would involve a lot of
replacing in old lisp code.  So the choice is to the one who implements it
(isn't it always? :-).

						The Fons