From: Bette Sydelko
Subject: Several questions about LISP
Date: 
Message-ID: <4ggfrs$br6@alpha.wright.edu>
I have a number of questions about LISP, I will state them below.

1. What is the difference between these two statements:

(CDR(CAR(CDR(CAR'((A(B C(D E)))(C (D E)B))))))
and
(CDR(CAR(CDR(CAR((A(B C(D E)))(C (D E)B))))))
basically the second one is just missing the apostrophe.

2. How importan are the parentheses and which functions return a list with 
parentheses and which do not?

3. What exactly do the apostrophes do in terms that a normal person could 
understand, such as someone taking AP Computer Science in High School.

-Andy Sydelko
············@bbs.dmapub.dma.org

From: David B. Lamkins
Subject: Re: Several questions about LISP
Date: 
Message-ID: <dlamkins-2202961857140001@ip-pdx02-13.teleport.com>
In article <··········@alpha.wright.edu>, ········@paladin.wright.edu
(Bette Sydelko) wrote:

> I have a number of questions about LISP, I will state them below.
> 
> 1. What is the difference between these two statements:
> 
> (CDR(CAR(CDR(CAR'((A(B C(D E)))(C (D E)B))))))
> and
> (CDR(CAR(CDR(CAR((A(B C(D E)))(C (D E)B))))))
> basically the second one is just missing the apostrophe.

> 3. What exactly do the apostrophes do in terms that a normal person could 
> understand, such as someone taking AP Computer Science in High School.

> -Andy Sydelko
> ············@bbs.dmapub.dma.org

Lisp's evaluation rule, paraphrased:

Given a form (f p1 p2 p3 ...), evaluate all of the pN, then use them as
arguments to f.  In conventional mathematical notation, this is f(p1 p2 p3
...)

The ' is shorthand for a Lisp quote form, so 'x is the same as (quote x). 
What does quote do?  It suspends Lisp's evaluation rule, so that '(f p1 p2
p3) is just (f p1 p2 p3) rather than the result of applying the function f
to its parameters pN.

Your first example, substituting (quote ...) for '..., is
(CDR (CAR (CDR (CAR (quote ((A (B C (D E))) (C (D E) B)))))))
meaning that CAR is applied to ((A (B C (D E))) (C (D E) B)), then CDR is
applied to that result, then CAR to _that_ result, etc...

Your second example is 
(CDR (CAR (CDR (CAR ((A (B C (D E))) (C (D E) B))))))
which contains the form ((A (B C (D E))) (C (D E) B)).  
If we substitute this form in (f p1), then
f = (A (B C (D E))), and p1 = (C (D E) B).
But now f is not the name of a function, it is a list (A (B C (D E))). 
Since you seem to be just starting Lisp, what you really need to know is
that a list is not a function, so this won't work.

Another way of looking at this simply is that a quoted form is data, but
an unquoted form is a function application.

Does this help?

-- 
Dave
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CPU Cycles: Use them now or lose them forever...
http://www.teleport.com/~dlamkins/
From: Richard A. O'Keefe
Subject: Re: Several questions about LISP
Date: 
Message-ID: <4gjukl$3cj@goanna.cs.rmit.EDU.AU>
········@paladin.wright.edu (Bette Sydelko) writes:

>I have a number of questions about LISP, I will state them below.

>1. What is the difference between these two statements:

>(CDR(CAR(CDR(CAR'((A(B C(D E)))(C (D E)B))))))
>and
>(CDR(CAR(CDR(CAR((A(B C(D E)))(C (D E)B))))))
>basically the second one is just missing the apostrophe.

Neither of them is a statement.  Laid out more conventionally,
	(cdr (car (cdr (car '((A (B C (D E))) (C (D E) B)) ))))

calls the cdr function passing it the result of
 calling the car function passing it the result of
  calling the cdr function passing it the result of
   calling the car function passing it the literate (quoted) data structure
    ((A (B C (D E))) (C (D E) B))

The second one is
	(cdr (car (cdr (car ((A (B C (D E))) (C (D E) B)) ))))

which tries to evaluate ((A (B C (D E))) (C (D E) B)) as an expression.
This would be legal in Scheme, as long as the expression (A (B C (D E)))
returned a function as its result.  It is not legal in Common Lisp.

>2. How importan are the parentheses and which functions return a list with 
>parentheses and which do not?

The parentheses are *essential*.  There are *no* redundant parentheses in
Lisp.  There is no such animal as a list without parentheses (look, the
poster's a beginner, let's not drag in multiple values), so there are, and
can be, no functions returning them.

More precisely, parentheses are an aspect of the *external* representation
of a list; inside the computer, a list is made up of storage locations and
pointers.

>3. What exactly do the apostrophes do in terms that a normal person could 
>understand, such as someone taking AP Computer Science in High School.

Don't try to learn lisp from this newsgroup.  Read the book "The Little
Lisper" (or the latest edition, "The Little Schemer").  Seriously.  It
is a short, clear, simple little book that will leave you wondering why
you ever thought it might be hard.

In the mean time, in _any_ programming language, some parts of your source
can be thought of as representing DATA, and some parts can be thought of
as representing CODE.  For example, 1 and "xyz" (a number and a string)
are pretty obviously data, and in BASIC "PRINT X" is obviously code.
But Lisp has a lot of data types, and some of would look like code.
Lisp does not use an apostrophe, it uses a QUOTATION MARK, which says
"the thing after me is data, not code".

By the way, learning Lisp is MUCH easier if you sit at a keyboard, start
up a Lisp system, and type in the examples in the textbook and see what
happens.

-- 
Election time; but how to get Labor _out_ without letting Liberal _in_?
Richard A. O'Keefe; http://www.cs.rmit.edu.au/~ok; RMIT Comp.Sci.
From: Thomas A. Russ
Subject: Re: Several questions about LISP
Date: 
Message-ID: <TAR.96Feb23082142@hobbes.ISI.EDU>
In article <...> ········@paladin.wright.edu (Bette Sydelko) writes:
 > I have a number of questions about LISP, I will state them below.
 > 
 > 1. What is the difference between these two statements:
 > 
 > (CDR (CAR (CDR (CAR '((A (B C (D E))) (C (D E) B))))))
 > and
 > (CDR (CAR (CDR (CAR ((A (B C (D E))) (C (D E) B))))))
 > basically the second one is just missing the apostrophe.
                                                (called QUOTE in Lisp terms)

The quote symbol is used to inhibit the normal evaluation of the form.
(There is another reply with an extensive discussion of this.)  Quote
means to use the following form as a literal rather than interpreting it
as executable program.  To use an analogy from other programming
languages, it is the difference between lines 2 and 3 below:

      x = 3;      // line 1
      y = x;      // line 2
      z = "x";    // line 3

In line 2 the value of the variable x is used.  In line 3 the x is in
double quotes, so it means we are talking about the name (string) x.

 > 2. How importan are the parentheses and which functions return a list with 
 > parentheses and which do not?

Parentheses are vital.  The second part of the question is hard to
really answer.  All lists are represented using parentheses.  Most
functions can return either list-valued or atomic values, so there isn't
any good answer.  Example:

      (car '(a b))    =>     A
      (car '((a b)))  =>     (A B)

 > 3. What exactly do the apostrophes do in terms that a normal person could 
 > understand, such as someone taking AP Computer Science in High School.

Quotes inhibit evaluation.  For example:

      (setq a 1)
      (setq b 2)
      (car (list a b))       =>  1       ;; line 4
      (car (list 'a 'b))     =>  A       ;; line 5
      (car '(list 'a 'b))    =>  LIST    ;; line 6

In line 4, the list function is applyed to the arguments 1 and 2, the
result of evaluating the symbols A and B.  Car is then applied to the
form (1 . 2) and returns the value 1.

In line 5, the list function is applyed to the arguments A and B, both
symbols which were not evaluated because of the QUOTE.  Car is then
applied to the form (A . B) and returns the value A.

In line 6, the quote is used to treat (LIST 'A 'B) as a literal.  In
other words, list is not being used as function but as a symbol.  Car is
then applied to the form (LIST A B) and returns the value LIST.

--
Thomas A. Russ,  USC/Information Sciences Institute          ···@isi.edu    
From: Mark McConnell
Subject: Re: Several questions about LISP
Date: 
Message-ID: <4gsq3f$epl@news.cis.okstate.edu>
········@paladin.wright.edu (Bette Sydelko) wrote:
>I have a number of questions about LISP, I will state them below.
>
>1. What is the difference between these two statements:
>
>(CDR(CAR(CDR(CAR'((A(B C(D E)))(C (D E)B))))))
>and
>(CDR(CAR(CDR(CAR((A(B C(D E)))(C (D E)B))))))
>basically the second one is just missing the apostrophe.

Several posters have replied with the answer.  I'll supply a simpler
example.

What is the difference between    (car '(A B))      [correct]
                           and    (car (A B))       [wrong]

In each case, Lisp evaluates the argument, and then feeds the resulting 
value to the   car   function.  In the first case, the value of
'(A B) is the list (A B).  The car function returns the value A.

In the second case, Lisp tries to evaluate the argument (A B).  This
means looking for a _function_ named A, and applying A to the value of B.
But no function named A exists.  Hence you get an error message.