w2: 'foo/('bar)/baz
; == foo/('bar)/baz
get w2
; == 42
w3: 'foo/('bar)
select get w3 'baz
?
w3: to-path w3
select w3 'baz
>> ? :w
FOO/BAR/BAZ is an integer of value: 42
@nedzadarek
w: 'FOO/(:REDUCES-TO-BAR)/BAZ
is the answer
select
something:>> arr: [a 42]
== [a 42]
>> select arr to-word "a"
== 42
>> select arr probe to-word "a"
a
== 42
>> select arr probe to-get-word "a"
:a
== 42
>> select arr probe to-set-word "a"
a:
== 42
>> select arr probe to-lit-word "a"
'a
== 42
@GiuseppeChillemi
When you set words to some values, <word>: <value>
(e.g. the-answer: 42
). <value>
will be evaluated.
integer!
(e.g. 42
) will give you 42
(the value looks the same). float!
(e.g. 3.14
) will give you 3.14
string!
, pair!
(2x14
) and some more - like aboveThere are some "special" cases:
path!
(e.g. foo/4
) will be evaluated. For example you have foo: [1 2 3 4]
, when you set value to some word, val: foo/4
, path foo/4
will be evaluated. foo/4
will be changed, in this case, to the 4th value of the foo
(4
).lit-path!
(e.g. 'foo/4
) will be evaluated to path!
foo/4
. As you know already, you can get
or reduce
it. w: foo/4
and get w
will give you 4
(4th element of the foo
).get-path!
will get you value that it points to. It is like path!
. However with path!
you cannot get function!
s for example (funs: #() funs/not-fibo: func [a] [ a - 10]
, funs/not-fibo
will try to call not-fibo
in the funs
map, it will raise an error because you haven't provided an argument). You can get such value by using lit-path!
: my-fun: :funs/not-fibo
. After this you can call it like any other function: my-fun 12
block!
every value within a block will be "the same", it won't use "special" rules that govern path!
, lit-path!
and get-path!
. For example you have a block my-block: [42 3.14 "string" word :get-word 'lit-word set-word: [another block with a word]]
, you can see that *-path
are not evaluated:
Helper:
foreach element my-block [
print "Value: "
probe element
print "Type: "
print mold type? element
print "####"
]
Output:
Value:
42
Type:
integer!
####
Value:
3.14
Type:
float!
####
Value:
"string"
Type:
string!
####
Value:
word
Type:
word!
####
Value:
:get-word
Type:
get-word!
####
Value:
'lit-word
Type:
lit-word!
####
Value:
set-word:
Type:
set-word!
####
Value:
[another block with a word]
Type:
block!
####
And last value [another block with a word]
will not evaluate words inside (you have no errors because there is no another
and a
word defined).
Red for Windows version 0.6.3 built 26-Mar-2018/1:14:22+02:00
@nedzadarek
Maybe yesterday we were after midnight but my question was different:
This is your code:
foo: [bar [baz 42]] w: 'foo/bar/baz get w ; == 42 reduce w ; == 42
I need something like:
z: bar
foo: [bar [baz 42]]
w: 'foo/(z)/baz
get w
; == 42
reduce w
; == 42
(I am just closing my day at work, I'll read it later)