Home   Archive   Permalink



Question on the get-word concept

I can make this work, but I don't know how to explain it to someone, that is, what terminology to use, and how to explain what is happening.
    
Here is a two-dimensional array, and two words that I will use as subscripts:
>> array1: [ ['a1' 'a2' 'a3'] ['b1' 'b2' 'b3'] ['c1' 'c2' 'c3'] ]
== [['a1' 'a2' 'a3'] ['b1' 'b2' 'b3'] ['c1' 'c2' 'c3']]
>> ix1: 2
== 2
>> ix2: 2
== 2
    
I know I can refer to the middle of the middle row (item b2) with the 'slash' notation:
>> probe array1/2/2
'b2'
== 'b2'
    
I thought at first that I could just substitute the subscripts for the integers, as follows:
>> probe array1/ix1/ix2
** Script Error: Invalid path value: ix1
** Where: halt-view
** Near: probe array1/ix1/ix2
    
That didn't work, so I figured out the 'get-word' concept and can do this:
>> probe array1/:ix1/:ix2
'b2'
== 'b2'
    
So that's fine, and I also can use the 'pick' function:
>> probe pick pick array1 2 2
'b2'
== 'b2'
>> probe pick pick array1 :ix1 :ix2
'b2'
== 'b2'
    
BUT, I ALSO can use this:
>> probe pick pick array1 ix1 ix2
'b2'
== 'b2'
    
I don't know how to explain to someone why using just the subscript words works in the 'pick' example immediately above but NOT in the 'slash' example farther back. I am wondering if someone else can explain.
    
Thank you.
    
    


posted by:   Steven White       6-Feb-2015/16:01:25-8:00



>> array1: [ ['a1' 'a2' 'a3'] ['b1' 'b2' 'b3'] ['c1' 'c2' 'c3'] ]
== [['a1' 'a2' 'a3'] ['b1' 'b2' 'b3'] ['c1' 'c2' 'c3']]
>> ix1: 2
== 2
>> ix2: 2
== 2
>> array1/(ix1)/(ix2)
== 'b2'
>>

posted by:   kealist       6-Feb-2015/16:23:20-8:00



Rebol2:
    
>> array1: [ix1: 1]
== [ix1: 1]
>> array1/ix1
** Script Error: Invalid path value: ix1
    
>> object1: make object! [ix1: 1]
>> object1/ix1
== 1
    
Rebol 3:
    
>> array1: [ix1: 1]
>> array1/ix1
== 1
    
with the plain word! it's looking for a path inside the object! / block! . Using paren! or get-word! gets the value as an integer! so it's using a number index

posted by:   kealist       6-Feb-2015/16:30:05-8:00



Steve,
    
The characters in a path are not evaluated, unless you do something to force the interpreter to evaluate them (i.e., as words which evaluate to values). The the get-word syntax, and the parentheses force the interpreter to perform that evaluation.

posted by:   Nick       7-Feb-2015/0:31:29-8:00