List! series [Was: blank]
[1/5] from: gmassar::dreamsoft::com at: 4-Oct-2000 16:04
I followed Elan's suggestion to try out list! series. Here is what I
did:
>> list: make list! [1 2 3 4]
== make list! [1 2 3 4]
>> first list
== 1
>> remove list
== make list! [2 3 4]
>> first list
** Script Error: Out of range or past end.
** Where: first list
What!!!
>> list
== make list! []
Oh, the series is completely empty!
Can anybody explain why remove all elements in the list instead of just
the first element? Remove block! series just one element at the head.
Why different?
[rebol--techscribe--com] wrote:
[2/5] from: larry:ecotope at: 4-Oct-2000 16:54
Hi gmassar
Some of the series functions work differently for lists then other series.
>From the new Core PDF doc:
Removing the element currently referenced in a list causes the reference to
reset to
the tail of the list
So using your example:
>> list: make list! [1 2 3 4]
== make list! [1 2 3 4]
>> remove list
== make list! [2 3 4]
>> list: head list
== make list! [2 3 4]
>> first list
== 2
The value returned from the remove function is a pointer to the list after
the removed element, but the current pointer for the list is at the tail.
Other functions work differently as well, I would suggest reading the
manual.
Cheers
-Larry
----- Original Message -----
From: <[gmassar--dreamsoft--com]>
To: <[list--rebol--com]>
Sent: Wednesday, October 04, 2000 4:04 PM
Subject: [REBOL] Re: List! series [Was: blank]
I followed Elan's suggestion to try out list! series. Here is what I
did:
>> list: make list! [1 2 3 4]
== make list! [1 2 3 4]
>> first list
== 1
>> remove list
== make list! [2 3 4]
>> first list
** Script Error: Out of range or past end.
** Where: first list
What!!!
>> list
== make list! []
Oh, the series is completely empty!
Can anybody explain why remove all elements in the list instead of just
the first element? Remove block! series just one element at the head.
Why different?
------------snip-----------------
[3/5] from: al:bri:xtra at: 4-Oct-2000 17:10
>> list: make list! [1 2 3 4]
== make list! [1 2 3 4]
>> first list
== 1
>> remove list
== make list! [2 3 4]
>> first list
** Script Error: Out of range or past end.
** Where: first list
>> first head list
== 2
As Larry points out, some functions work differently for list!. I believe
it's for performance reasons.
Andrew Martin
ICQ: 26227169
http://members.nbci.com/AndrewMartin/
http://members.xoom.com/AndrewMartin/
[4/5] from: rebol:techscribe at: 4-Oct-2000 17:38
Hi gmassar,
it's not quite as drastic as that.
After removing from the list, do
>> list: head list
== make list! [2 3 4]
Also try:
>> list: make list! [1 2 3 4]
>> at list 2
compare to
>> block: make block! [1 2 3 4]
>> at block 2
Another surprise:
>> list: make list! [1 2 3 4]
>> foreach element list [print element]
Also try
>> foreach element list [print mold element]
forall and forskip work as expected.
Also compare
>> block: make block! [1 2 3 4]
>> partial-block: skip block 2
<<quoted lines omitted: 4>>
>> partial-block
>> partial-list
In short, you'll run into surprises if you expect list to behave like a block.
Looks to me like list is not completely implemented in the experimental version
I'm using (0.10.38.4.2) .
[gmassar--dreamsoft--com] wrote:
[5/5] from: capolunghi:att at: 5-Oct-2000 13:51
gmassar:
Your list didn't really disappear:
if you do this..
>> list: make list! [1 2 3 4]
== make list! [1 2 3 4]
>> first list
== 1
>> remove list
== make list! [2 3 4]
>> first list
** Script Error: Out of range or past end.
** Where: first list
>> list
== make list! [] --- Is it gone??
>> head list
== make list! [2 3 4] ---- NO ! List is still there!
Good luck,
Joe
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted