Hi Rachid,

EMPTY? and TAIL? really are the same:

>> same? :empty? :tail?
== true

I think you may be confusing TAIL, which returns a pointer to just past the
last element of a series, and TAIL? and EMPTY? which return true if a pointer
to a series is past the last element. My example was weird because I just
wanted to construct a series and set a pointer to its tail in one step - of
course I don't normally do that. It's easy enough to set TEST-BLOCK back to
its head with:

>> test-block: tail [1 2 3 4 5]
== []
>> test-block: head test-block
== [1 2 3 4 5]
>> index? test-block
== 1

So, while TEST-BLOCK might not be in the best of health, it isn't all that
sick either.

But, if you use FORALL or traverse a series in some other way, it often
happens that you'll end up with words bound to pointers to the ends of
series. Sometimes I use a construct like:

while [not tail? pointer][
    either [....] [pointer: remove pointer][pointer: next pointer]
]

where I delete elements I don't want and skip elements I want to keep. At the
end of this loop, if I want to find out if I have any elements left I have to
do,

if empty? head pointer [....]

where, as Robert said, it would be nicer to just get by with,

if empty? pointer [....]

See you,
Eric

---- Original message

Hi Eric,

Empty? isn't a synonym for tail?, as far as I know. Your example is a weird
construction, because if I try to test empty? with tail I do this:

>> test: [1 2 3]
== [1 2 3]
>> tail test
== []
>> empty? test
== false

Why do you do:

> >> test-block: tail [1 2 3 4 5]

It strikes me strange to define 'test-block with the index at the tail. It
influences 'test-block from the get-go:

>> test-block: tail [1 2 3 4 5]
== []
>> index? test-block
== 6
>> head test-block
== [1 2 3 4 5]
>> index? test-block
== 6

While:

>> test: [1 2 3]
== [1 2 3]
>> index? test
== 1
>> tail test
== []
>> index? test
== 1

The index is set to 6 no matter what, and I don't think that's "healthy" for
a block. =)

Regards,
Rachid

Reply via email to