REBOL for COBOL programmers |
Colon is not assignment
Date written: February 5, 2015 This note restates the point that a word with a colon after it is not an assignment statement that you might see in other languages. That common REBOL notation of a word with a colon attached to it, followed by some value, looks a lot like a variable followed by an assignment operator (the equals sign in python, the colon-equals in some other languages), but it is not. In your beginning efforts with REBOL, you can think of it that way, but if you always think of it that way, then at some point it will not be that way, your thinking will not match reality, and you could get caught. Just be aware. Look at the following example of a series and some operations on it. >> array: [1 2 3 4 5 6 7 8 9] == [1 2 3 4 5 6 7 8 9] >> probe array [1 2 3 4 5 6 7 8 9] == [1 2 3 4 5 6 7 8 9] >> length? array == 9 >> subarray: skip array 4 == [5 6 7 8 9] >> probe subarray [5 6 7 8 9] == [5 6 7 8 9] >> length? subarray == 5 >> poke subarray 3 11 == 11 >> probe subarray [5 6 11 8 9] == [5 6 11 8 9] >> probe array [1 2 3 4 5 6 11 8 9] == [1 2 3 4 5 6 11 8 9] >>The word "array" refers to the series of numbers one through nine. The word "subarray" refers to a point in that series starting at the fifth item. The syntax to define subarray does NOT mean to set up a variable called subarray and copy into it the series of numbers five through nine. It means that subarray refers to the array starting at the indicated spot. This can be seen when we poke a value into the third spot of subarray. The value of the word subarray changes, but so does the value of array, because they are not two separate "variables," but are words that refer to different spots in the same value. Note that if you DO want to make a separate word that contains values copied from array, there is a way to do that, namely, the "copy" function. Just be aware that the notation shown in the example above does not copy anything. |