From: anusha
Subject: how to apply quote to an evaluated atom?
Date: 
Message-ID: <f24cb1e0e3144db319398db04abd866c@localhost.talkaboutprogramming.com>
On evaluating a lisp function as a result I got an atom. Now I want to use
that atom with a quote in another function. Now how to apply that quote
within the program?
On evaluating a function a got an atom " a " as result. But I need " 'a "
to use it in another function. What change should I do in the previous
function to get " 'a " as result? Or can I add another statement in the
function which changes " a " to " 'a "?

Thanks,
Anusha.

From: Andy Cristina
Subject: Re: how to apply quote to an evaluated atom?
Date: 
Message-ID: <Q4iNd.7502$GT.2789@okepread01>
anusha wrote:
> On evaluating a lisp function as a result I got an atom. Now I want to use
> that atom with a quote in another function. Now how to apply that quote
> within the program?
> On evaluating a function a got an atom " a " as result. But I need " 'a "
> to use it in another function. What change should I do in the previous
> function to get " 'a " as result? Or can I add another statement in the
> function which changes " a " to " 'a "?
> 
> Thanks,
> Anusha.
> 

Don't mean to be questioning you, but why do you need 'a to pass to your 
function?  Normally, when you call a function from the REPL, you use the 
quote notation to prevent evaluation, but if your using the result of a 
function as an argument, it shouldn't be evaluated.  I.e,
CL-USER> (defun foo (x)
	   (if (= x 3)
	       'COWS
	       'PIGS))
FOO
CL-USER> (defun bar (x)
	   (if (eql x 'cows)
	       'FLY
	       'DONT-FLY))
BAR
CL-USER> (foo 3)
COWS
CL-USER> (bar 'cows)
FLY
CL-USER> (bar cows)  <--- Error caused here, cows not bound.  It should 
be quoted!
; Evaluation aborted
CL-USER> (bar (foo 3))  <--- Result doesn't need to be quoted, because 
"(foo 3)" is evaluated, not the result.
FLY


But if you really need the form 'a, you can return `(quote ,a), like this:
CL-USER> (defun huh (x)
	   `(quote ,x))
HUH
CL-USER> (huh 'cows)
'COWS
From: Rahul Jain
Subject: Re: how to apply quote to an evaluated atom?
Date: 
Message-ID: <87acqi6ubs.fsf@nyct.net>
Andy Cristina <·············@gmail.com> writes:

> But if you really need the form 'a, you can return `(quote ,a), like this:
> CL-USER> (defun huh (x)
> 	   `(quote ,x))
> HUH

Wimp!

(defun huh (x)
  `',x)

-- 
Rahul Jain
·····@nyct.net
Professional Software Developer, Amateur Quantum Mechanicist
From: Barry Margolin
Subject: Re: how to apply quote to an evaluated atom?
Date: 
Message-ID: <barmar-A9A8D5.00593906022005@comcast.dca.giganews.com>
In article 
<································@localhost.talkaboutprogramming.com>,
 "anusha" <················@nospam.yahoo.co.in> wrote:

> On evaluating a lisp function as a result I got an atom. Now I want to use
> that atom with a quote in another function. Now how to apply that quote
> within the program?
> On evaluating a function a got an atom " a " as result. But I need " 'a "
> to use it in another function. What change should I do in the previous
> function to get " 'a " as result? Or can I add another statement in the
> function which changes " a " to " 'a "?

You don't need to quote it.  If you pass on a function result to another 
function, it will be passed as is -- it won't be re-evaluated.

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
From: Kent M Pitman
Subject: Re: how to apply quote to an evaluated atom?
Date: 
Message-ID: <uwttmw860.fsf@nhplace.com>
"anusha" <················@nospam.yahoo.co.in> writes:

> On evaluating a lisp function as a result I got an atom. Now I want to use
> that atom with a quote in another function. Now how to apply that quote
> within the program?
> On evaluating a function a got an atom " a " as result. But I need " 'a "
> to use it in another function. What change should I do in the previous
> function to get " 'a " as result? Or can I add another statement in the
> function which changes " a " to " 'a "?

I'm guessing that you have some function like

 (defun t-or-nil (x) 
   (cond ((eq x 'yes) t)
         ((eq x 'no)  nil)
         (t (error "Not YES or NO: ~S" x))))

 (t-or-nil 'yes) => T

and then you have some other function that computes YES but you want
to pass 'YES, thinking that this is what T-OR-NIL wants for an
argument.

In fact, every function receives its argument already evaluated, so
T-OR-NILL in the above does not get 'YES or 'NO as an argument, but
rather gets YES or NO.

Later, in the execution of T-OR-NIL, it sees (EQ X 'YES), but in that
case it's EQ that is the function which will receive evaluated
arguments.  The first argument will be the result of evaluating X,
getting YES.  The second will be the result of evaluating 'YES,
getting YES.  Then EQ will see YES and YES, returning T (for true).

By the way, in order to pass 'YES as an argument to T-OR-NILL, you'd
have to pass ''YES, since 'YES is going to evaluate to YES, n ot 'YES.
If you were to pass 'YES as an argument to T-OR-NIL, it would signal
an error because 'YES is neither YES nor NO, the two values tested
for.  NOTE WELL: The function T-OR-NIL does NOT check for 'YES nor
'NO, it checks for YES or NO.  To understand this, see the previous
paragraph.

Also, incidentally, you want to call this a symbol, not an atom--the
term atom is an old-fashioned and misleading term in most cases.  It
means non-CONS.  It does not mean 'symbol'.  A symbol is a kind of
atom, but so is a number, and so is a vector, and so is any other kind
of data than a CONS.  So atom is nearly useful since it means nearly
all things.  In the rare cases you want to think of non-conses, then
you should think of them as just that, and you'll be better off.

So back to your original problem, you have a function that returns
some symbol (like our YES symbol above) and you want to pass it to
some other function (such as our T-OR-NIL above).  In that case, if

 (COMPUTE-SOMETHING) => YES

then

 (T-OR-NIL (COMPUTE-SOMETHING))

will do the right thing because (COMPUTE-SOMETHING) evaluates to YES,
just as 'YES would evaluate to YES, and since that's just the kind of
argument T-OR-NIL is looking for, you're all set.

The notion of quotation is MOSTLY useful at an original point of
notating a program, to say "I mean this literal symbol".  But when a
symbol is computed, you normally don't need to force a quote onto it
because you're holding it in a variable and the evaluation of the
value will substitute for the evaluation of the quotation you probably
think you are wanting todo.  They both yield the symbol, and you're
all set.

So whether you do

 (LET ((X (COMPUTE-SOMETHING)))
   (TO-OR-NIL X))
 => T

or

 (SETQ X (COMPUTE-SOMETHING)) => YES
 X => YES
 (T-OR-NIL X) => T

or

 (T-OR-NIL (COMPUTE-SOMETHING)) => T

it will always work withut any forcing of re-quoting.

Incidentally, symbols are not "evaluated symbols" or "unevaluated
symbols".  Symbols are just symbols.  They are not changed by
evaluation.  Evaluation, instead, just accesses a value that is
associated with the symbol (either directly in the symbol, if it is a
special variable, or indirectly in some table where the symbol is a
key, if it is a lexical variable).  So you will confuse yourself if
you talk about an "evaluated atom" (or "evaluated symbol") as if it is
any different than any other kind of atom (or symbol).

e.g.,

 (SETQ X 'Y)
 (SETQ Y 'Z)

If you do:

 X => Y

you get back the symbol Y, which is the result of evaluating X.  But
if you do:

 Y => Z

you get back the symbol Z, which is the result of evaluating Y.  But
those two Y's are the same even though one is the result of an
evaluation and one is the thing that was evaluated.  (I guess you
might have wanted toc all it a "pre-evaluated symbol", but don't,
because it's just a symbol in both cases.)

Hope there's something in there that helps you.
From: Christopher C. Stacy
Subject: Re: how to apply quote to an evaluated atom?
Date: 
Message-ID: <uvf96tdoz.fsf@news.dtpq.com>
Kent M Pitman <······@nhplace.com> writes:
> Also, incidentally, you want to call this a symbol, not an atom--the
> term atom is an old-fashioned and misleading term in most cases.  It
> means non-CONS.  It does not mean 'symbol'.  A symbol is a kind of
> atom, but so is a number, and so is a vector, and so is any other kind
> So atom is nearly useful since it means nearly all things.  
                    ^^^^
           "useless"

(for the non-native English readers out there...)
:)
From: David Sletten
Subject: Re: how to apply quote to an evaluated atom?
Date: 
Message-ID: <FkmNd.7475$e11.7400@twister.socal.rr.com>
Christopher C. Stacy wrote:
> Kent M Pitman <······@nhplace.com> writes:
> 
>>Also, incidentally, you want to call this a symbol, not an atom--the
>>term atom is an old-fashioned and misleading term in most cases.  It
>>means non-CONS.  It does not mean 'symbol'.  A symbol is a kind of
>>atom, but so is a number, and so is a vector, and so is any other kind
>>So atom is nearly useful since it means nearly all things.  
> 
>                     ^^^^
>            "useless"
> 
> (for the non-native English readers out there...)
> :)

That's a fine line to walk between the "nearly useful" and the "nearly 
useless"...
From: Christopher C. Stacy
Subject: Re: how to apply quote to an evaluated atom?
Date: 
Message-ID: <u4qgq5452.fsf@news.dtpq.com>
David Sletten <·····@slytobias.com> writes:

> Christopher C. Stacy wrote:
> > Kent M Pitman <······@nhplace.com> writes:
> >
> >>Also, incidentally, you want to call this a symbol, not an atom--the
> >>term atom is an old-fashioned and misleading term in most cases.  It
> >>means non-CONS.  It does not mean 'symbol'.  A symbol is a kind of
> >>atom, but so is a number, and so is a vector, and so is any other kind
> >> So atom is nearly useful since it means nearly all things.
> >                     ^^^^
> >            "useless"
> > (for the non-native English readers out there...)
> > :)
> 
> That's a fine line to walk between the "nearly useful" and the "nearly
> useless"...
 
Yeah, they're nearly the same thing.
From: David Sletten
Subject: Re: how to apply quote to an evaluated atom?
Date: 
Message-ID: <dPvNd.9924$BS.307@twister.socal.rr.com>
Christopher C. Stacy wrote:


>>That's a fine line to walk between the "nearly useful" and the "nearly
>>useless"...
> 
>  
> Yeah, they're nearly the same thing.

I forgot my emoticon, but I'm sure you realized I was just teasing. :)

David Sletten
From: John Thingstad
Subject: Re: how to apply quote to an evaluated atom?
Date: 
Message-ID: <opslrfncv0pqzri1@mjolner.upc.no>
On Sun, 06 Feb 2005 00:02:17 -0500, anusha  
<················@nospam.yahoo.co.in> wrote:

> On evaluating a lisp function as a result I got an atom. Now I want to  
> use
> that atom with a quote in another function. Now how to apply that quote
> within the program?
> On evaluating a function a got an atom " a " as result. But I need " 'a "
> to use it in another function. What change should I do in the previous
> function to get " 'a " as result? Or can I add another statement in the
> function which changes " a " to " 'a "?
>
> Thanks,
> Anusha.
>

just use (quote a)
'a is just a convenice notation provided by the reader

-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
From: Kenny Tilton
Subject: Re: how to apply quote to an evaluated atom?
Date: 
Message-ID: <NUnNd.83303$ld2.27142295@twister.nyc.rr.com>
anusha wrote:
> On evaluating a lisp function as a result I got an atom. Now I want to use
> that atom with a quote in another function. Now how to apply that quote
> within the program?
> On evaluating a function a got an atom " a " as result. But I need " 'a "
> to use it in another function. What change should I do in the previous
> function to get " 'a " as result? Or can I add another statement in the
> function which changes " a " to " 'a "?

Hmmm. Not sure what you mean. Do you want the symbol 'a instead of the 
string "a"? If so:

(intern "A") -> 'A

but watch out: (intern "a") -> '|a|

kt

-- 
Cells? Cello? Cells-Gtk?: http://www.common-lisp.net/project/cells/
Why Lisp? http://lisp.tech.coop/RtL%20Highlight%20Film

"Doctor, I wrestled with reality for forty years, and I am happy to 
state that I finally won out over it." -- Elwood P. Dowd
From: Pascal Bourguignon
Subject: Re: how to apply quote to an evaluated atom?
Date: 
Message-ID: <87ekftbw8y.fsf@thalassa.informatimago.com>
Kenny Tilton <·······@nyc.rr.com> writes:
> Hmmm. Not sure what you mean. Do you want the symbol 'a instead of the
> string "a"? If so:
> 
> (intern "A") -> 'A

No.

 (intern "A") --> A
 (quote A)    --> A
 'A           --> A

(Just try it at the REPL!)

(INTERN "A") returns the same thing as (QUOTE A)

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

Nobody can fix the economy.  Nobody can be trusted with their finger
on the button.  Nobody's perfect.  VOTE FOR NOBODY.
From: Rahul Jain
Subject: Re: how to apply quote to an evaluated atom?
Date: 
Message-ID: <87vf90ickk.fsf@nyct.net>
Pascal Bourguignon <····@mouse-potato.com> writes:

> (INTERN "A") returns the same thing as (QUOTE A)

But... QUOTE returns at compile-time. INTERN returns at run-time. It
sounds like the OP is trying to read lisp symbol names from the user. Of
course, as Kenny said, be careful of the case issues.

Oh crap, did I just agree with Kenny?

-- 
Rahul Jain
·····@nyct.net
Professional Software Developer, Amateur Quantum Mechanicist