From: Jeff Stephens
Subject: Another quick question on LENGTH and Lists
Date: 
Message-ID: <UzAb9.19456$Rx4.282415@twister.tampabay.rr.com>
  I thank you for the previous help. A quick question...  After exploring
LENGTH
with the info provided by the replies, I also tried the following:

    (LENGTH '(1 '(2 3) 4)) which returned 3 as I expected, so I decided to
try

    (LENGTH '(1 (2 3) 4)) without the quote in front of (2 3) half expecting
an error,

     but this second form also returned 3.  Are there any subtleties here
that I should
    be aware of that might get me into trouble later, or are these two forms
which
    both return 3 really identical?

Thanks and Regards,
Jeff Stephens

From: thelifter
Subject: Re: Another quick question on LENGTH and Lists
Date: 
Message-ID: <b295356a.0208300031.65aee70e@posting.google.com>
"Jeff Stephens" <········@tampabay.rr.com> wrote in message news:<······················@twister.tampabay.rr.com>...
> I thank you for the previous help. A quick question...  After exploring
> LENGTH
> with the info provided by the replies, I also tried the following:
> 
>     (LENGTH '(1 '(2 3) 4)) which returned 3 as I expected, so I decided to
> try
> 
>     (LENGTH '(1 (2 3) 4)) without the quote in front of (2 3) half expecting
> an error,
> 
>      but this second form also returned 3.  Are there any subtleties here
> that I should

I'm still a Lisp newbie but I think both Lists are NOT identical, they
only have the same length:

Actually list1 = '(1 (quote (2 3)) 4)

The difference will show up if you evaluate the following:

(eval (cadr list))  == evaluate the second element of the list.

In the first case this should return (2 3), which is the result from
evaluating
(quote (2 3)).

In the second case this should yield an error, because he will try to
evaluate
(2 3) and "2" is not a function.

Correct me if I'm wrong, didn't try this out.

Best regards...
From: Johannes Grødem
Subject: Re: Another quick question on LENGTH and Lists
Date: 
Message-ID: <lzelcghdji.fsf@unity.copyleft.no>
* ·········@gmx.net (thelifter):

> In the second case this should yield an error, because he will try to
> evaluate (2 3) and "2" is not a function.

No, the entire expression (which (2 3) is a part of) is protected from
evaluation, so if you wanted to call a function called 2, you could
use backquote, for example:

`(1 ,(2 3) 4)

This will yield an error if there is no function named 2.  (You can
have a function named "2", by the way.)

Like this, for example:

(defun |2| () 2)

But you would have to call it like this, though:

(|2|)

If this article was confusing, just ignore it and go read your book
more thoroughly.

-- 
johs
From: Barry Margolin
Subject: Re: Another quick question on LENGTH and Lists
Date: 
Message-ID: <o3Lb9.3$Hq1.126@paloalto-snr1.gtei.net>
In article <··············@unity.copyleft.no>,
Johannes Gr�dem <··@kopkillah.com> wrote:
>`(1 ,(2 3) 4)
>
>This will yield an error if there is no function named 2.  (You can
>have a function named "2", by the way.)

No you can't.  The only things that can appear in the function position of
an expression are symbols or lambda expressions.  An implementation could
provide an extension that allows numbers to be used there, but it's not
standard and I've never heard of any implementation doing so.

-- 
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: Erann Gat
Subject: Re: Another quick question on LENGTH and Lists
Date: 
Message-ID: <gat-3008020934350001@192.168.1.50>
In article <···············@paloalto-snr1.gtei.net>, Barry Margolin
<······@genuity.net> wrote:

> In article <··············@unity.copyleft.no>,
> Johannes Gr�dem <··@kopkillah.com> wrote:
> >`(1 ,(2 3) 4)
> >
> >This will yield an error if there is no function named 2.  (You can
> >have a function named "2", by the way.)
> 
> No you can't.

Sure you can.  There are at least three ways to do it:

(defun \2 () ...)

(defun |2| () ...)

(setf *read-base* (+ 1 1))
(defun 2 () ...)

E.
From: Tim Bradshaw
Subject: Re: Another quick question on LENGTH and Lists
Date: 
Message-ID: <ey3fzwwmg28.fsf@cley.com>
* Erann Gat wrote:

> Sure you can.  There are at least three ways to do it:

To be precise: you can't have a function whose name is the integer 2.
You can have a function whose name is a symbol whose name is "2".

(To be even more precise I would need to not talk about the names of
functions but rather work from names to function objects)

--tim
From: Coby Beck
Subject: Re: Another quick question on LENGTH and Lists
Date: 
Message-ID: <aknm2s$16p0$1@otis.netspace.net.au>
"Johannes Gr�dem" <··@kopkillah.com> wrote in message
···················@unity.copyleft.no...
> * ·········@gmx.net (thelifter):
>
> > In the second case this should yield an error, because he will try to
> > evaluate (2 3) and "2" is not a function.
>
> No, the entire expression (which (2 3) is a part of) is protected from
> evaluation,

but you missed the part in thelifter's post where he said (eval (cadr
list)), ie (eval (2 3))

I believe he was correct in everything he wrote.

--
Coby Beck
(remove #\Space "coby 101 @ bigpond . com")
From: Johannes Grødem
Subject: Re: Another quick question on LENGTH and Lists
Date: 
Message-ID: <lzy9aoh6ps.fsf@unity.copyleft.no>
* "Coby Beck" <·····@mercury.bc.ca>:

> but you missed the part in thelifter's post where he said (eval (cadr
> list)), ie (eval (2 3))

It appears I have somehow confused elements of the post he answered to
with his post.  Sorry.

-- 
johs
From: P.C.
Subject: Re: Another quick question on LENGTH and Lists
Date: 
Message-ID: <3d6fd316$0$27669$edfadb0f@dspool01.news.tele.dk>
Hi.

"Coby Beck" <·····@mercury.bc.ca> skrev i en meddelelse
··················@otis.netspace.net.au...
>
> "Johannes Gr�dem" <··@kopkillah.com> wrote in message
> ···················@unity.copyleft.no...

> but you missed the part in thelifter's post where he said (eval (cadr
> list)), ie (eval (2 3))
>
> I believe he was correct in everything he wrote.
>
> --
> Coby Beck
> (remove #\Space "coby 101 @ bigpond . com")

If Length are defined recursivily it shuld travel any sublist proberly yielding
T case there are a Cdr fo the list , anyway shuldn't a Length calculate the real
number of atoms all together .
P.C.
From: Marc Spitzer
Subject: Re: Another quick question on LENGTH and Lists
Date: 
Message-ID: <slrnamvopt.2nnh.marc@oscar.eng.cv.net>
In article <·························@dspool01.news.tele.dk>, P.C. wrote:
> Hi.
> 
> "Coby Beck" <·····@mercury.bc.ca> skrev i en meddelelse
> ··················@otis.netspace.net.au...
>>
>> "Johannes Gr�dem" <··@kopkillah.com> wrote in message
>> ···················@unity.copyleft.no...
> 
>> but you missed the part in thelifter's post where he said (eval (cadr
>> list)), ie (eval (2 3))
>>
>> I believe he was correct in everything he wrote.
>>
>> --
>> Coby Beck
>> (remove #\Space "coby 101 @ bigpond . com")
> 
> If Length are defined recursivily it shuld travel any sublist
> proberly yielding T case there are a Cdr fo the list , anyway
> shuldn't a Length calculate the real number of atoms all together .
> P.C.

But acording to the spec it is not.  It takes a proper sequence 
and returns the number of elements it counted.  A sub list is 1 
element at that level.

marc
From: P.C.
Subject: Re: Another quick question on LENGTH and Lists
Date: 
Message-ID: <3d709aaa$0$154$edfadb0f@dspool01.news.tele.dk>
Hi.

"Marc Spitzer" <····@oscar.eng.cv.net> skrev i en meddelelse
·························@oscar.eng.cv.net...
> In article <·························@dspool01.news.tele.dk>, P.C. wrote:
> But acording to the spec it is not.  It takes a proper sequence
> and returns the number of elements it counted.  A sub list is 1
> element at that level.
> marc

Now that indicate the function to be defined somhow adding one as long there are
a Cdr in the list . But don't this ask for several "Length" functions ,as
mentioned who know if one member are a function with parameters .
Still both Mapcar and Apply are also counting without checking if a member are
an atom or an symbolic expression , guess if you want the true Length or realy
need to check a list you need to rewrite the Length function, but that shuldn't
be that difficult as it shuld be easy to apply or mapcar the Length function
itself recursivly to the list.
P.C.
From: Joe Marshall
Subject: Re: Another quick question on LENGTH and Lists
Date: 
Message-ID: <cV5c9.144794$aA.31669@sccrnsc02>
"P.C." <··········@privat.dk> wrote in message ····························@dspool01.news.tele.dk...
>
> [I] guess if you want the true Length or really
> need to check a list you need to rewrite the Length function

I wouldn't call this the `true' length.  LENGTH takes a sequence
as an argument and returns the number of elements in the sequence.
The fact that some of the elements of the sequence might be aggregate
objects is unimportant.
From: P.C.
Subject: Re: Another quick question on LENGTH and Lists
Date: 
Message-ID: <3d711076$0$209$edfadb0f@dspool01.news.tele.dk>
Hi.

"Joe Marshall" <·············@attbi.com> skrev i en meddelelse
··························@sccrnsc02...
>
> "P.C." <··········@privat.dk> wrote in message
····························@dspool01.news.tele.dk...
> >
> > [I] guess if you want the true Length or really
> > need to check a list you need to rewrite the Length function
>
> I wouldn't call this the `true' length.  LENGTH takes a sequence
> as an argument and returns the number of elements in the sequence.
> The fact that some of the elements of the sequence might be aggregate
> objects is unimportant.

You are quite right ,as long as you just need the number of sub lists with or
without functions , guess that functions can look for the present of a list with
both Car and Cdr , just  guess this would be somthing like And ,while both a car
and a cdr will yield T and any other yield Nil.  Case there _are_ sublists these
could proberly be defined within same function, where you then ask with "no
sublist" parameter ,   Or a simble call to Cdr
This is so simple to implerment  with recursive functions ; I mean why not have
this as a _must_ within a Length function ---- that it carry a complete length
function, guess othervise you could use Length function in it's own redefinment
. This is Lisp
.  Wonder how you could redefine Length to a Length or a (Lambda Length '(x y
.........   expression ; one that automaticly redefine a Length function shuld
be allright I guess , as long as it's your own tool and you never use it ;))
Anyway Im'e quite sure that you can use Length recursivly, defing a new Length
function traveling sublists that you can call with a parameter ,isn't this kind
of things done with 3 or 5 lines Lisp code.
P.C.

P.C.
From: Marc Spitzer
Subject: Re: Another quick question on LENGTH and Lists
Date: 
Message-ID: <slrnan250s.tb.marc@oscar.eng.cv.net>
In article <·······················@dspool01.news.tele.dk>, P.C. wrote:
> Hi.
> 
> "Joe Marshall" <·············@attbi.com> skrev i en meddelelse
> ··························@sccrnsc02...
>>
>> "P.C." <··········@privat.dk> wrote in message
> ····························@dspool01.news.tele.dk...
>> >
>> > [I] guess if you want the true Length or really
>> > need to check a list you need to rewrite the Length function
>>
>> I wouldn't call this the `true' length.  LENGTH takes a sequence
>> as an argument and returns the number of elements in the sequence.
>> The fact that some of the elements of the sequence might be aggregate
>> objects is unimportant.
> 
> You are quite right ,as long as you just need the number of sub lists with or
> without functions , guess that functions can look for the present of a list with
> both Car and Cdr , just  guess this would be somthing like And ,while both a car
> and a cdr will yield T and any other yield Nil.  Case there _are_ sublists these
> could proberly be defined within same function, where you then ask with "no
> sublist" parameter ,   Or a simble call to Cdr
> This is so simple to implerment  with recursive functions ; I mean why not have
> this as a _must_ within a Length function ---- that it carry a complete length
> function, guess othervise you could use Length function in it's own redefinment
> . This is Lisp
> .  Wonder how you could redefine Length to a Length or a (Lambda Length '(x y
> .........   expression ; one that automaticly redefine a Length function shuld
> be allright I guess , as long as it's your own tool and you never use it ;))
> Anyway Im'e quite sure that you can use Length recursivly, defing a new Length
> function traveling sublists that you can call with a parameter ,isn't this kind
> of things done with 3 or 5 lines Lisp code.
> P.C.
> 
> P.C.

Well if you wanted a treewalker to count the number of enements go do it,
lenght does not do that.  It is a simple recursive function after all.

marc

> 
> 
> 
From: P.C.
Subject: Re: Another quick question on LENGTH and Lists
Date: 
Message-ID: <3d711c15$0$191$edfadb0f@dspool01.news.tele.dk>
Hi.

"Marc Spitzer" <····@oscar.eng.cv.net> skrev i en meddelelse
·······················@oscar.eng.cv.net...
> In article <·······················@dspool01.news.tele.dk>, P.C. wrote:
> Well if you wanted a treewalker to count the number of enements go do it,
> lenght does not do that.  It is a simple recursive function after all.

Right, and you are quite right if you claim that it would be meaningless to
apply functions with Mapcar ,case this was not done with lists with atleast two
Atoms ,symbols or whatever , ---- sorry about the missing &rest in the halve
Lambds example btw. Anyway traveling sublists aplying functions ,don't need a
parameter as any function call can be pointet with any symbolic represantation
as we all know ,but I only point to this off-topic issue, as then Length still
don't count each single Atom ;))
P.C.
From: Marc Spitzer
Subject: Re: Another quick question on LENGTH and Lists
Date: 
Message-ID: <slrnan2bdt.14u.marc@oscar.eng.cv.net>
In article <·······················@dspool01.news.tele.dk>, P.C. wrote:
> Hi.
> 
> "Marc Spitzer" <····@oscar.eng.cv.net> skrev i en meddelelse
> ·······················@oscar.eng.cv.net...
>> In article <·······················@dspool01.news.tele.dk>, P.C. wrote:
>> Well if you wanted a treewalker to count the number of enements go do it,
>> lenght does not do that.  It is a simple recursive function after all.
> 
> Right, and you are quite right if you claim that it would be meaningless to
> apply functions with Mapcar ,case this was not done with lists with atleast two
> Atoms ,symbols or whatever , ---- sorry about the missing &rest in the halve
> Lambds example btw. Anyway traveling sublists aplying functions ,don't need a
> parameter as any function call can be pointet with any symbolic represantation
> as we all know ,but I only point to this off-topic issue, as then Length still
> don't count each single Atom ;))
> P.C.
> 
> 
> 

The point I think you are missing is that lenght is defind to not
count every atom.  It is defined to count every element in a proper
sequence. 

So you are pointing out that lenght behaves *exactly* as the standard
defines it shall.  It seems to me that your major point is a complete
waste of everyones time.  

marc
From: Joe Marshall
Subject: Re: Another quick question on LENGTH and Lists
Date: 
Message-ID: <4%8c9.255004$983.528907@rwcrnsc53>
"P.C." <··········@privat.dk> wrote in message ····························@dspool01.news.tele.dk...
> .  Wonder how you could redefine Length to a Length or a (Lambda Length '(x y
> .........   expression ; one that automaticly redefine a Length function shuld
> be allright I guess , as long as it's your own tool and you never use it ;))
> Anyway Im'e quite sure that you can use Length recursivly, defing a new Length
> function traveling sublists that you can call with a parameter ,isn't this kind
> of things done with 3 or 5 lines Lisp code.
> P.C.

What would you want it to return for something like this:

#(a b (c #(d e) f) "foo")

This is a sequence of four elements, two of which are themselves sequences.
From: P.C.
Subject: Re: Another quick question on LENGTH and Lists
Date: 
Message-ID: <3d712e77$0$125$edfadb0f@dspool01.news.tele.dk>
Hi.

"Joe Marshall" <·············@attbi.com> skrev i en meddelelse
····························@rwcrnsc53...
>
> What would you want it to return for something like this:
>
> #(a b (c #(d e) f) "foo")
>
> This is a sequence of four elements, two of which are themselves sequences.

Eh, ------- now in the little Lisp I know, I would rather say

(defun n-length (x)
(cond
((Cdr x) ( + 1 (n-length (cdr x))))
( T (+ 1 ))
))

Anyway this don't seem to work ,as if I set "A" like this ;
(setq a '(a c (a b) a))
And evaluate (n-length a) then n-length yield 4.

P.C.
http://groups.yahoo.com/group/skuespilhus/
>
>
>
From: Kaz Kylheku
Subject: Re: Another quick question on LENGTH and Lists
Date: 
Message-ID: <akrgio$g52$1@luna.vcn.bc.ca>
In article <·······················@dspool01.news.tele.dk>, P.C. wrote:
> Hi.
> 
> "Joe Marshall" <·············@attbi.com> skrev i en meddelelse
> ····························@rwcrnsc53...
>>
>> What would you want it to return for something like this:
>>
>> #(a b (c #(d e) f) "foo")
>>
>> This is a sequence of four elements, two of which are themselves sequences.
> 
> Eh, ------- now in the little Lisp I know, I would rather say
> 
> (defun n-length (x)
> (cond
> ((Cdr x) ( + 1 (n-length (cdr x))))
> ( T (+ 1 ))
> ))

There are indeed two cases to handle, but these are not it.
All you care about is whether or not the input list is empty,
in other words whether or not it is the symbol NIL.

(defun my-stupidly-recursive-length-function-that-only-works-on-lists (list)
  (if (null list)
    0
    (1+ (my-stupidly-recursive-length-function-that-only-works-on-lists 
      (rest list)))))
From: Erik Naggum
Subject: Re: Another quick question on LENGTH and Lists
Date: 
Message-ID: <3239664914814827@naggum.no>
* Jeff Stephens
| A quick question...  After exploring LENGTH with the info provided by the
| replies, I also tried the following:

  Why do you "try" things at random when you have a pretty good book that will
  explain this shortly?  Please acquire patience -- you will need it.  Read on
  in the book until this is explained to you.  Eagerness is good, but endeavor
  to direct it whither it is most productive.

-- 
Erik Naggum, Oslo, Norway

Act from reason, and failure makes you rethink and study harder.
Act from faith, and failure makes you blame someone and push harder.
From: Thien-Thi Nguyen
Subject: Re: Another quick question on LENGTH and Lists
Date: 
Message-ID: <kk9sn0x593d.fsf@glug.org>
"Jeff Stephens" <········@tampabay.rr.com> writes:

> but this second form also returned 3.  Are there any subtleties here
> that I should be aware of that might get me into trouble later, or are
> these two forms which both return 3 really identical?

if you have encountered EQUAL (as suggested by another post up the
thread), probably you can formulate an expression that will answer this
question.

thi
From: Robert Hanlin
Subject: Re: Another quick question on LENGTH and Lists
Date: 
Message-ID: <c427d639.0208311230.76b56a74@posting.google.com>
"Jeff Stephens" <········@tampabay.rr.com> wrote in message news:<······················@twister.tampabay.rr.com>...
> I thank you for the previous help. A quick question...  After exploring
> LENGTH
> with the info provided by the replies, I also tried the following:
> 
>     (LENGTH '(1 '(2 3) 4)) which returned 3 as I expected, so I decided to

What precisely does quote do, Jeff?  It takes in parameters, and how
does it transform them?


Cheers,
Robert