Ridley,
>> help next
Returns the series at its next position.
Arguments:
series -- (series port)
Note the use of the words "the" and "its" in "Returns THE series at ITS
next position."
>> b: make block! ["hello"]
== ["hello"]
>> b: next b
== []
>> index? b
== 2
>> head b
== ["hello"]
>> help append
Appends a value to the tail of a series and returns the series head.
Arguments:
series -- (series port)
value --
Refinements:
/only -- Appends a block value into a block series as a block
Here note the words "... and returns THE series HEAD."
>> source append
append: func [
{Appends a value to the tail of a series and returns the series head.}
series [series! port!]
value
/only {Appends a block value into a block series as a block}
][
head either only [insert/only tail series :value
] [
insert tail series :value
]
]
Note the line:
head either only ...
ie, when you have used append, append will returns head b, and head b is
>> head b
== ["hello"]
before append and will continue to begin at "hello" after the append.
Some people have complained that append should not return the head of the
series, because, as in your case, you may be dealing with a series whose
current position has been modified, and the resulting series is not intended.
If that is the behavior you are looking for, you can simply use the
following home-brewn version of append. I stored in a file called append.r.
This version does returns the series at its former current position, but it
does not do the same thing for ports, because 'at does not support ports.
REBOL []
append: func [
{Appends a value to the tail of a series and returns the series at its
passed position, if series is a series! type and not a port!.}
series [series! port!]
value
/only {Appends a block value into a block series as a block}
/local position s
][
if series? series [position: index? series]
s: head either only [insert/only tail series :value
] [
insert tail series :value
]
return either series? series [ at s position ] [s]
]
>> do %append.r
Script: "Untitled" (none)
>> append at [1 2 3 4] 3 100
== [3 4 100]
>> b: make block! ["hello"]
== ["hello"]
>> b: next b
== []
>> append b "Why do I see the first string?"
== ["Why do I see the first string?"]
;- Elan >> [: - )]