tags:

views:

58

answers:

2

First of all, is it correct to use the term pointer when talking about the internal index in a list?

Consider the following Rebol code:

a: [1 2 3 4 5 6 7 8 9]
a: at a 4
b: a

a and b both point to the same list and both return [4 5 6 7 8 9]. This I understand. However, I don't see how the internal index can be moved in a, but not in b:

a: head a
length? a      ; Returns 9
length? b      ; Returns 6

How are the internal indices kept separate for a and b?

Lastly, is it correct in Rebol to say that a and b are references to the list [1 2 3 4 5 6 7 8 9], using the definition of reference in Java or C#?

A: 

In more REBOLish terminology, a is a variable that refers to a series. That variable, a, inherently has a current position.

b is also a variable that references a series and so it also inherently has a current position.

As it happens, both a and b reference the same series, yet each has a different current position. The current position is an attribute of the series variable. This can be useful at times.

The REBOL Core Manual has a whole chapter on series ..... check out especially section 10 on Multiple Series Variables:

http://www.rebol.com/docs/core23/rebolcore-6.html#section-10
Sunanda
Thanks for the link. I actually was unaware of the online Rebol documentation and have been learning it from the Auverlot/Wood book. I don't know how I missed the online docs!
A: 

Sunanda's answer is close, but not exact. In addition to the manual he mentions, there is also the Rebol progamming wikibook, containing a section on series http://en.wikibooks.org/wiki/REBOL_Programming/Language_Features/Series , as well as the REBOL wiki containing other documentation articles by various authors (you may want to check the rebol.net and rebol.org sites).

My answers:

"First of all, is it correct to use the term pointer when talking about the internal index in a list?" - it is incorrect at least for two reasons. The first one being, that the data you use is not a list, but a block (notice, that there is a list datatype in REBOL). The second one being, that the internal index is an integer value, not a computer memory address.

"How are the internal indices kept separate for a and b?" - after the assignment the variable a no longer refers to the same block as the variable b, it refers to the block with the same head, but with a different index. The index is an integral part of the block value. This property does not have much in common with variables as Sunanda suggested above. The fact is, that every REBOL block has an index, although the most frequent index value of REBOL blocks is 1.

Ladislav