Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[REBOL] Re: list length

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 > 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
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]