list length
[1/4] from: ammoncooke:y:ahoo at: 30-May-2001 19:28
Hi,
I am trying to compare the length of two text-lists. This is the code I am using to
get the length:
lst1-len: lst1/text: to-integer length? lst1/data
when the list has 20 items in it this code returns 2
when the list has 8 it returns 8
Thanks!!
Ammon
[2/4] from: carl:cybercraft at: 31-May-2001 15:32
On 30-May-01, Ammon Cooke wrote:
> Hi,
> I am trying to compare the length of two text-lists. This is the
<<quoted lines omitted: 4>>
> Thanks!!
> Ammon
You're almost there. As the list is a block it's index can move
which will be (I assume) the cause of the differing results you got
above. For instance...
>> view layout[a-list: text-list "aa" "bb" "cc" "dd"]
>> a-list/data
== ["aa" "bb" "cc" "dd"]
>> length? a-list/data
== 4
>> a-list/data: next a-list/data
== ["bb" "cc" "dd"]
>> length? a-list/data
== 3
All the data's still there though, as can be seen if we get the length
from the head of the list...
>> length? head a-list/data
== 4
So, just place 'head before your lst1/data and you should always get
the length of the full list.
--
Carl Read
[carl--cybercraft--co--nz]
[3/4] from: arolls:bigpond:au at: 31-May-2001 16:35
Also note that
length? lst1/data
is already an integer, and need not be
converted to an integer again with
'to-integer.
You would probably want something more
like:
lst1-len: length? lst1/data
lst1/text: to-string lst1-len
or
lst1/text: to-string lst1-len: length? lst1/data
Anton.
[4/4] from: ammoncooke::yahoo::com at: 31-May-2001 13:43
Thanks!! Your fix didn't exactly fix the problem you attempted to fix, but
rather another bug I needed to fix! You see I set a text object to the
value of "0" as a default then to test the text-list's length! I copied the
lenth! to the /text of the text object, but for some reason text objects do
not resize themselves so.... What it did fix was the fact that by runnning
the code:
lst1-len: lst1/text: to-integer length! lst1/data
I was actually changing th value of lst1/text, I didn't realize this.
Thanks Again
Ammon
What a list!!
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted