From: Company Mail
Subject: Elementary newbie question. Probably stupid.
Date: 
Message-ID: <34E9F908.9108D093@planet.dk>
It is obvious to me that this is a very simple question and I'll
probably kick myself when I get the answer. Read no further unless you
don't mind helping me out.

I downloaded Powerlisp to experiment with and learn the language and I
have been following some books and tutorials.
Unfortunately I have quickly come up against a problem which I can't
solve and I suspect it relates to Powerlisp in particular rather than
LISP as such. Basically it's confusion about literal or evaluated
expressions.

I type...

(setq myvar '(one two three))
(setq myothevar '(four five six))
(setq mycompound '(myvar myothervar))

...so far so good. Now
(car myvar)
...returns...
one
...and...
(car compound)
...returns...
myvar

Seems OK, but...

(listp (car compound))
...returns nil
and
(car (car compound))
produces an error consistent with the nil return of the listp function
i.e. myvar is not a list
This is very odd because when I type myvar on it's own I get the list I
created initially.

Why is myvar being treated literally when it is a return value, but not
otherwise? Is this just some strange PowerLisp quirk or am I missing
something obvious?
(BTW I tried inserting eval with no success)

I am only a beginner at LISP, but I've been programming in other
languages. I'm working through a book which uses a common lisp standard
and typing everything word for word.

I hope someone can help.
TIA
Brennan


--
__________________________________________________
The Planet
multimedia design studio
_____________________
  Klerkegade 19, 4.
  DK-1308 Copenhagen K
  Denmark

  Phone  +45 33 93 00 20
  Mobile +45 21 66 67 10

private mail: ···················@hotmail.com
Company site: http://www.planet.dk
Company mail: ···········@planet.dk

From: Barry Margolin
Subject: Re: Elementary newbie question. Probably stupid.
Date: 
Message-ID: <J6nG.3$Ju1.4790@cam-news-reader1.bbnplanet.com>
In article <·················@planet.dk>, Company Mail  <····@planet.dk> wrote:
>Why is myvar being treated literally when it is a return value, but not
>otherwise? Is this just some strange PowerLisp quirk or am I missing
>something obvious?
>(BTW I tried inserting eval with no success)

When you're evaluating an expression of the form (function-name arg1 arg2
...), the rule in Lisp is that you evaluate each of the argument
expressions, and pass those values to the function.  The return values of
the argument expressions are *not* re-evaluated.  If they were, it would be
impossible to pass symbols and lists as arguments to functions, since it
would always try to evaluate them.

-- 
Barry Margolin, ······@bbnplanet.com
GTE Internetworking, Powered by BBN, Cambridge, MA
Support the anti-spam movement; see <http://www.cauce.org/>
Please don't send technical questions directly to me, post them to newsgroups.
From: Thomas A. Russ
Subject: Re: Elementary newbie question. Probably stupid.
Date: 
Message-ID: <ymik9at4vfi.fsf@sevak.isi.edu>
Company Mail <····@planet.dk> writes:

> 
> It is obvious to me that this is a very simple question and I'll
> probably kick myself when I get the answer. Read no further unless you
> don't mind helping me out.
> 
> I downloaded Powerlisp to experiment with and learn the language and I
> have been following some books and tutorials.
> Unfortunately I have quickly come up against a problem which I can't
> solve and I suspect it relates to Powerlisp in particular rather than
> LISP as such. Basically it's confusion about literal or evaluated
> expressions.

This is Lisp in general.

> I type...
> 
> (setq myvar '(one two three))

This creates a list with three elements, namely the symbols 'one 'two
'three 

> (setq myothevar '(four five six))

This creates a list with three elements, namely the symbols 'four 'five
'six

> (setq mycompound '(myvar myothervar))

This creates a list with two elements, namely the symbols 'myvar 'myothervar

Based on your questions below, I would imagine that at this point you
are expecting instead:

 '((one two three) (four five six))

The reason you don't get this is that the quote (') is telling lisp not
to evaluate the following expression.  You thus get a literal value with
two symbols in it.  To get the values associated with those symbols, you
need to evaluate them.  Of course, just doing

 (setq mycompound (myvar myothervar))

will just generate a different error, namely that the function MYVAR
can't be found.  That is because the evaluation rule for SExpressions
treats the first place in a list specially -- namely it does a function
rather than a value lookup.  What you would want is

 (setq mycompound (list myvar myothervar))

which calls the LIST function on the values of myvar and myothervar.
Since they are not quoted, they are evaluated.

> ...so far so good. Now
> (car myvar)
> ...returns...
> one
> ...and...
> (car compound)
> ...returns...
> myvar

Yes.  But this is the SYMBOL myvar and not the LIST that is the value of
the symbol myvar.

> Seems OK, but...
>
> (listp (car compound))
> ...returns nil

As expected.  Also,

(symbolp (car compound)) 

  returns T

> and
> (car (car compound))
> produces an error consistent with the nil return of the listp function
> i.e. myvar is not a list

Yes.

> This is very odd because when I type myvar on it's own I get the list I
> created initially.

That is because when you type myvar by itself, it is evaluated.  What
you see in the Lisp top level listener is the already evaluated form.
In other words, for you to have the behavior you expect, the value
returned by 

  (car compound)

would need to be

(ONE TWO THREE)

> Why is myvar being treated literally when it is a return value, but not
> otherwise? Is this just some strange PowerLisp quirk or am I missing
> something obvious?

Hard to say if it is really obvious.  Those people who have experience
with Lisp may find it obvious, but it is a not uncommon source of confusion
for novices.  The notion of evaluation is a fundamental concept to
grasp, however.

One source of confusion when coming from other programming languages is
that they don't have the notion of a symbol as an object in its own
right.  Symbols are just something that the compiler manipulates, but
that can't be examined by the program at run-time.

For a bit of fun, try 

 (describe 'myvar)

and see what your Lisp system tells you.  (I'm assuming PowerLisp
implements the CommonLisp describe function).

> (BTW I tried inserting eval with no success)

Hmmm.  Depending on where you inserted it, it should have worked:

(car (eval (car compound)))

   => ONE

But then again, you should be discouraged from using EVAL.  There are
only a very few cases where its use is justified in Lisp programming.
Often when it is used by beginners, it is a sign that there is some
other fundamental issue that is not properly understood.

> I am only a beginner at LISP, but I've been programming in other
> languages. I'm working through a book which uses a common lisp standard
> and typing everything word for word.
> 
> I hope someone can help.
> TIA
> Brennan
> 
> 
> --
> __________________________________________________
> The Planet
> multimedia design studio
> _____________________
>   Klerkegade 19, 4.
>   DK-1308 Copenhagen K
>   Denmark
> 
>   Phone  +45 33 93 00 20
>   Mobile +45 21 66 67 10
> 
> private mail: ···················@hotmail.com
> Company site: http://www.planet.dk
> Company mail: ···········@planet.dk
> 
> 
> 

-- 
Thomas A. Russ,  USC/Information Sciences Institute          ···@isi.edu