Hi, I would like to count the length of an array!!! it may sound
absurd for arrays but the concept is similar to lists.
for eg. array_a => #(((a b)(c d))(e f)(g h) nil); would give-->4
Q:how to count the number of sublists of the form (x y) in the array??
(i am sure a small function procedure can do it, but is there a one
shot command!)
In article <·····················@newserve.cc.binghamton.edu> ······@bingvaxu.cc.binghamton.edu (??) writes:
>Hi, I would like to count the length of an array!!! it may sound
>absurd for arrays but the concept is similar to lists.
The usual (and more efficient) way to do this with arrays is to use the
fill pointer, rather than a special element value.
>for eg. array_a => #(((a b)(c d))(e f)(g h) nil); would give-->4
(position nil array_a)
>Q:how to count the number of sublists of the form (x y) in the array??
That's not the same thing, is it? The answer to this is
(count-if #'consp array_a)
--
Barry Margolin
System Manager, Thinking Machines Corp.
······@think.com {uunet,harvard}!think!barmar
From: Thomas A. Russ
Subject: Re: array element counter
Date:
Message-ID: <20841@venera.isi.edu>
In article ... ······@bingvaxu.cc.binghamton.edu (??) writes:
>Hi, I would like to count the length of an array!!! it may sound
>absurd for arrays but the concept is similar to lists.
The usual (and more efficient) way to do this with arrays is to use the
fill pointer, rather than a special element value.
>for eg. array_a => #(((a b)(c d))(e f)(g h) nil); would give-->4
(position nil array_a)
Of course, for a one dimensional array (= vector), the simplest
solution would be to use the LENGTH function:
(length array_a)
- Tom.
In article <·····@venera.isi.edu> ···@ISI.EDU (Thomas A. Russ) writes:
Path: ads.com!ames!elroy.jpl.nasa.gov!usc!isi.edu!venera.isi.edu!tar
From: ···@ISI.EDU (Thomas A. Russ)
Newsgroups: comp.lang.lisp
Date: 2 Mar 92 17:08:45 GMT
References: <·····················@newserve.cc.binghamton.edu>
<············@early-bird.think.com>
Sender: ····@isi.edu
Reply-To: ···@isi.edu
Organization: USC-ISI
Lines: 19
In article ... ······@bingvaxu.cc.binghamton.edu (??) writes:
>Hi, I would like to count the length of an array!!! it may sound
>absurd for arrays but the concept is similar to lists.
[okay, so just multiply the results of ARRAY-DIMENSION...]
The usual (and more efficient) way to do this with arrays is to use the
fill pointer, rather than a special element value.
>for eg. array_a => #(((a b)(c d))(e f)(g h) nil); would give-->4
(position nil array_a)
Of course, for a one dimensional array (= vector), the simplest
solution would be to use the LENGTH function:
(length array_a)
- Tom.
if you create an array, it's got a size/length already. if you want to
know how full it is (and what would that mean exactly?), then the
fill-pointer idea is ok for certain things.
but suppose the array has holes? then what?
if the array has no holes, are you using vector-push-extend?
array-dimension is likely best here, too.
or did I miss too much of previous discussion?
-- clint
--
Clint Hyde "Give me a LispM or give me death!" -- jwz
Advanced Decision Systems Internet: ·····@chesapeake.ads.com
2111 Wilson Blvd #800
Arlington, VA 22201 (703) 875-0327