From: isaac councill
Subject: newbie code
Date: 
Message-ID: <9gaujn$1808@r02n01.cac.psu.edu>
Hello,

I am quite new to Lisp and am running into a problem with a program that I'm
writing.  I need to take a variable that stores a number (for instance
36.15) and feed it into a function that returns the variable's value in
quotation marks.  Any advice on how to do this would be greatly appreciated.

> (defvar foo 36.15)
> (some-function foo)
"36.15"

Thanks in advance,
Isaac

From: Geoff Summerhayes
Subject: Re: newbie code
Date: 
Message-ID: <tii2n7p3ms6675@corp.supernews.com>
"isaac councill" <····@psu.edu> wrote in message ················@r02n01.cac.psu.edu...
> Hello,
>
> I am quite new to Lisp and am running into a problem with a program that I'm
> writing.  I need to take a variable that stores a number (for instance
> 36.15) and feed it into a function that returns the variable's value in
> quotation marks.  Any advice on how to do this would be greatly appreciated.
>
> > (defvar foo 36.15)
> > (some-function foo)
> "36.15"
>
> Thanks in advance,
> Isaac
>

CL-USER 1 > (format nil "\"~A\"" 36.15)
"\"36.15\""

CL-USER 2 > (princ (format nil "\"~A\"" 36.15))
"36.15"
"\"36.15\""

Geoff
From: Steven L. Collins
Subject: Re: newbie code
Date: 
Message-ID: <9gbr8q$261$1@slb0.atl.mindspring.net>
"Geoff Summerhayes" <·············@hNoOtSmPaAiMl.com> wrote in message
···················@corp.supernews.com...
>
> "isaac councill" <····@psu.edu> wrote in message
················@r02n01.cac.psu.edu...
> > Hello,
> >
> > I am quite new to Lisp and am running into a problem with a program that
I'm
> > writing.  I need to take a variable that stores a number (for instance
> > 36.15) and feed it into a function that returns the variable's value in
> > quotation marks.  Any advice on how to do this would be greatly
appreciated.
> >
> > > (defvar foo 36.15)
> > > (some-function foo)
> > "36.15"
> >
> > Thanks in advance,
> > Isaac
> >
>
> CL-USER 1 > (format nil "\"~A\"" 36.15)
> "\"36.15\""
>
> CL-USER 2 > (princ (format nil "\"~A\"" 36.15))
> "36.15"
> "\"36.15\""
>
> Geoff

You don't need the \"  in the format directives string ?
 [1]> (defvar foo 36.15)
FOO
[2]> (format nil "~a" foo)
"36.15"

If you *must* have your own function ?
[3]> (defun my-foo (x)
        (format nil "~a" x))
MY-FOO
[4]> (my-foo foo)
"36.15"

Check out "The Association of Lisp Users" web site to find online resources
about the lisp language.  http://www.lisp.org/table/contents.htm

Good luck and have fun,
Steven
From: Geoff Summerhayes
Subject: Re: newbie code
Date: 
Message-ID: <tik5kdlgibnbc9@corp.supernews.com>
"Steven L. Collins" <·······@ix.netcom.com> wrote in message ·················@slb0.atl.mindspring.net...
>
> "Geoff Summerhayes" <·············@hNoOtSmPaAiMl.com> wrote in message
> ···················@corp.supernews.com...
> >
> > "isaac councill" <····@psu.edu> wrote in message
> ················@r02n01.cac.psu.edu...
> > > Hello,
> > >
> > > I am quite new to Lisp and am running into a problem with a program that
> I'm
> > > writing.  I need to take a variable that stores a number (for instance
> > > 36.15) and feed it into a function that returns the variable's value in
> > > quotation marks.  Any advice on how to do this would be greatly
> appreciated.
> > >
> > > > (defvar foo 36.15)
> > > > (some-function foo)
> > > "36.15"
> > >
> > > Thanks in advance,
> > > Isaac
> > >
> >
> > CL-USER 1 > (format nil "\"~A\"" 36.15)
> > "\"36.15\""
> >
> > CL-USER 2 > (princ (format nil "\"~A\"" 36.15))
> > "36.15"
> > "\"36.15\""
> >
> > Geoff
>
> You don't need the \"  in the format directives string ?
>  [1]> (defvar foo 36.15)
> FOO
> [2]> (format nil "~a" foo)
> "36.15"
>
> If you *must* have your own function ?
> [3]> (defun my-foo (x)
>         (format nil "~a" x))
> MY-FOO
> [4]> (my-foo foo)
> "36.15"
>
> Check out "The Association of Lisp Users" web site to find online resources
> about the lisp language.  http://www.lisp.org/table/contents.htm
>

Depends on what he actually wants, the quotes come from the representation
of the string in the listener, they are not part of the string itself.
Consider,

CL-USER 1 > (format nil "Deep thought said ~A." 42)
"Deep thought said 42."

CL-USER 2 > (format t "Deep thought said ~A." 42)
Deep thought said 42.
NIL

CL-USER 3 > (format nil "Deep thought said, \"~A.\"" 42)
"Deep thought said, \"42.\""

CL-USER 4 > (format t "Deep thought said, \"~A.\"" 42)
Deep thought said, "42."
NIL
From: Coby Beck
Subject: Re: newbie code
Date: 
Message-ID: <eg7W6.462482$fs3.76094782@typhoon.tampabay.rr.com>
"isaac councill" <····@psu.edu> wrote in message
················@r02n01.cac.psu.edu...
> > (defvar foo 36.15)
> > (some-function foo)
> "36.15"
>
> Thanks in advance,
> Isaac
>

some-function ::= write-to-string

Coby
From: Sunil Mishra
Subject: Re: newbie code
Date: 
Message-ID: <3B2D940C.6030801@notmyemail.com>
Coby Beck wrote:

> "isaac councill" <····@psu.edu> wrote in message
> ················@r02n01.cac.psu.edu...
> 
>>>(defvar foo 36.15)
>>>(some-function foo)
>>>
>>"36.15"
>>
>>Thanks in advance,
>>Isaac
>>
>>
> 
> some-function ::= write-to-string
> 
> Coby
> 
> 
> 

Also available are princ-to-string and prin1-to-string, the macro 
with-output-to-string for more complex string generation, and format 
with nil as the stream argument.

I've always wondered though... If you know that you have an integer or 
perhaps a floating point, would it not be more efficient to roll an 
output function that does just that, rather than checking if it is a 
symbol, etc?

Sunil