From: Jeff Stephens
Subject: Beginner question on function "LENGTH"
Date: 
Message-ID: <Nazb9.18620$Rx4.265341@twister.tampabay.rr.com>
  I have just started to try and teach myself Common Lisp.  I am using the
book by David Touretzky, "A Gentle Introduction to LISP".  I have gotten to
the section in chapter 2 that introduces lists, and several examples are
given
using the primitive function "LENGTH".  But I keep getting errors when I
try, e.g.,

    (LENGTH (1 2 3 4))  - according to the book this should return 4

    as should

    (LENGTH (A B C D))

    I also tried

    (LENGTH ('A 'B 'C 'D)

    but this also produced an error.  I am using LispWorks Personal Edition
on
    Windows 98.  Can someone help me?  I assume I have the syntax wrong, but
    I don't know how to correct this.

Thanks in advance for any help.

Regards,
Jeff Stephens

From: Frank A. Adrian
Subject: Re: Beginner question on function "LENGTH"
Date: 
Message-ID: <yBBb9.70$oP2.85305@news.uswest.net>
Jeff Stephens wrote:

>   I have just started to try and teach myself Common Lisp.  I am using the
> book by David Touretzky, "A Gentle Introduction to LISP".  I have gotten
> to the section in chapter 2 that introduces lists, and several examples
> are given
> using the primitive function "LENGTH".  But I keep getting errors when I
> try, e.g.,
> 
>     (LENGTH (1 2 3 4))  - according to the book this should return 4

Try (length '(1 2 3 4))

Etc.

faa
From: Barry Margolin
Subject: Re: Beginner question on function "LENGTH"
Date: 
Message-ID: <Nnzb9.31$j%4.1880@paloalto-snr1.gtei.net>
In article <······················@twister.tampabay.rr.com>,
Jeff Stephens <········@tampabay.rr.com> wrote:
>  I have just started to try and teach myself Common Lisp.  I am using the
>book by David Touretzky, "A Gentle Introduction to LISP".  I have gotten to
>the section in chapter 2 that introduces lists, and several examples are
>given
>using the primitive function "LENGTH".  But I keep getting errors when I
>try, e.g.,
>
>    (LENGTH (1 2 3 4))  - according to the book this should return 4

Your problem isn't with LENGTH, it's with expression syntax in general.

All the arguments in a function call are first evaluated.  So before LENGTH
is called, the expression (1 2 3 4) is evaluated.  This has a 1 in the
place where a function name should be, and that's obviously nonsense.

Try: (length (list 1 2 3 4))
or:  (length '(1 2 3 4))

>    as should
>
>    (LENGTH (A B C D))

This is trying to call a function named A, with the values of the
variables B, C, and D as parameters.  If any of those don't exist, you'll
get an error.  It should be:

(length '(a b c d))
or
(length (list 'a 'b 'c 'd))

Quoting was probably discussed pretty early in the book, so I think you
need to go back and review that section.

-- 
Barry Margolin, ······@genuity.net
Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
From: Jeff Stephens
Subject: Re: Beginner question on function "LENGTH"
Date: 
Message-ID: <_2Ab9.19030$Rx4.275780@twister.tampabay.rr.com>
"Barry Margolin" <······@genuity.net> wrote in message
······················@paloalto-snr1.gtei.net...
> In article <······················@twister.tampabay.rr.com>,
> Jeff Stephens <········@tampabay.rr.com> wrote:
> >  I have just started to try and teach myself Common Lisp.  I am using
the
> >book by David Touretzky, "A Gentle Introduction to LISP".  I have gotten
to
> >the section in chapter 2 that introduces lists, and several examples are
> >given
> >using the primitive function "LENGTH".  But I keep getting errors when I
> >try, e.g.,
> >
> >    (LENGTH (1 2 3 4))  - according to the book this should return 4
>
> Your problem isn't with LENGTH, it's with expression syntax in general.
>
> All the arguments in a function call are first evaluated.  So before
LENGTH
> is called, the expression (1 2 3 4) is evaluated.  This has a 1 in the
> place where a function name should be, and that's obviously nonsense.
>
> Try: (length (list 1 2 3 4))
> or:  (length '(1 2 3 4))
>
> >    as should
> >
> >    (LENGTH (A B C D))
>
> This is trying to call a function named A, with the values of the
> variables B, C, and D as parameters.  If any of those don't exist, you'll
> get an error.  It should be:
>
> (length '(a b c d))
> or
> (length (list 'a 'b 'c 'd))
>
> Quoting was probably discussed pretty early in the book, so I think you
> need to go back and review that section.
>
  I went back over the previous pages, but could not find quoting mentioned
anywhere.  I am only on page 36, so I didn't have to cover too many pages.
So far the discussion has been pretty generic, and Prof. Touretzky has been
using a block notation like this:

                        ______________________
                        |                                       |
                        |                                       |
 (A B C D)-----> |         LENGTH                 |--------> 4
                        |                                       |
                        |                                       |
                        |_____________________ |

Other examples of this form worked fine, as for example, ZEROP, so

        (ZEROP 12)

returns NIL.  So I assumed that LENGTH would work as is.  Quoting must be
further along.  I believe this book was written back in the mid 80's before
the
ANSI standard was finalized.

Thanks for the help.





> --
> Barry Margolin, ······@genuity.net
> Genuity, Woburn, MA
> *** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to
newsgroups.
> Please DON'T copy followups to me -- I'll assume it wasn't posted to the
group.
>
From: Paul F. Dietz
Subject: Re: Beginner question on function "LENGTH"
Date: 
Message-ID: <3D6ECFFF.23B34229@dls.net>
Jeff Stephens wrote:

>   Quoting must be
> further along.  I believe this book was written back in the mid 80's before
> the ANSI standard was finalized.


QUOTE has been part of Lisp since the very beginning in the 1960s.

	Paul
From: Edi Weitz
Subject: Re: Beginner question on function "LENGTH"
Date: 
Message-ID: <87bs7lqi06.fsf@bird.agharta.de>
"Jeff Stephens" <········@tampabay.rr.com> writes:

>   I have just started to try and teach myself Common Lisp.  I am
> using the book by David Touretzky, "A Gentle Introduction to LISP".
> I have gotten to the section in chapter 2 that introduces lists, and
> several examples are given using the primitive function "LENGTH".
> But I keep getting errors when I try, e.g.,
> 
>     (LENGTH (1 2 3 4))  - according to the book this should return 4
> 
>     as should
> 
>     (LENGTH (A B C D))
> 
>     I also tried
> 
>     (LENGTH ('A 'B 'C 'D)
> 
>     but this also produced an error.  I am using LispWorks Personal
> Edition on Windows 98.  Can someone help me?  I assume I have the
> syntax wrong, but I don't know how to correct this.

What you want is

  (LENGTH '(1 2 3 4))

or

  (LENGTH '(A B C D))

I just scanned through Touretzky's book and it looks like he explains
this in Chapter 3, "EVAL notation", page 87f.

Edi.
From: Jeff Stephens
Subject: Re: Beginner question on function "LENGTH"
Date: 
Message-ID: <O7Ab9.19077$Rx4.276656@twister.tampabay.rr.com>
"Edi Weitz" <···@agharta.de> wrote in message
···················@bird.agharta.de...
> "Jeff Stephens" <········@tampabay.rr.com> writes:
>
> >   I have just started to try and teach myself Common Lisp.  I am
> > using the book by David Touretzky, "A Gentle Introduction to LISP".
> > I have gotten to the section in chapter 2 that introduces lists, and
> > several examples are given using the primitive function "LENGTH".
> > But I keep getting errors when I try, e.g.,
> >
> >     (LENGTH (1 2 3 4))  - according to the book this should return 4
> >
> >     as should
> >
> >     (LENGTH (A B C D))
> >
> >     I also tried
> >
> >     (LENGTH ('A 'B 'C 'D)
> >
> >     but this also produced an error.  I am using LispWorks Personal
> > Edition on Windows 98.  Can someone help me?  I assume I have the
> > syntax wrong, but I don't know how to correct this.
>
> What you want is
>
>   (LENGTH '(1 2 3 4))
>
> or
>
>   (LENGTH '(A B C D))
>
> I just scanned through Touretzky's book and it looks like he explains
> this in Chapter 3, "EVAL notation", page 87f.

Thanks.  Maybe he was just trying to illustrate the concept here in chapter
2
without expecting that anyone would actually try LENGTH using this syntax.
I
was lulled by the fact that all the other examples he gives up to this point
work
just fine, e.g. +,-,/, etc., and NUMBERP, SYMBOLP, ZEROP, EQUAL, NOT,
ODDP, EVENP, etc.

Thanks for the help.
>
> Edi.
>
From: Hannah Schroeter
Subject: Re: Beginner question on function "LENGTH"
Date: 
Message-ID: <akqmte$m47$2@c3po.schlund.de>
Hello!

Jeff Stephens <········@tampabay.rr.com> wrote:

>[...]

>>   (LENGTH '(A B C D))

>Thanks.  Maybe he was just trying to illustrate the concept here in chapter
>2
>without expecting that anyone would actually try LENGTH using this syntax.
>I
>was lulled by the fact that all the other examples he gives up to this point
>work
>just fine, e.g. +,-,/, etc., and NUMBERP, SYMBOLP, ZEROP, EQUAL, NOT,
>ODDP, EVENP, etc.

There are self evaluating forms in Lisp, i.e. they always evaluate
to themselves without needing to be quoted. These are, among others,
number literals, which you seem to have been using mostly.

In contrasts, lists are NOT self evaluating, but evaluate to a function
call (save for if the name part, i.e. first element of the list,
denotes a macro call or special form), and thus, if you want the lists
themselves, you must either quote them or construct them (e.g. through
evaluating the function named "list").

Kind regards,

Hannah.