[REBOL] Re: R: Re: This is a strange thing
From: joel:neely:fedex at: 2-Jul-2001 15:11
Romano Paolo Tenca wrote:
> What has confuse me, i think, is this:
> >> b: "foo"
> == "foo"
> >> a: [b]
> == [b]
> >> reduce a
> == ["foo"]
> >> reduce a/1
> == b
> >> get a/1
> == "foo"
> Can you explain to me the different behaviour of Reduce with
> "a" and "a/1"?
First, take a look at HELP for REDUCE
>> help reduce
Evaluates an expression or block expressions and
returns the result.
REDUCE is a native value.
value -- (Type: any)
When you REDUCE a block you get back a block of results (the
results of evaluating all expressions within the argument
>> b: "foo" == "foo"
>> a: [b] == [b]
>> reduce a == ["foo"]
However, a path (as an expression!) evaluates to whatever is
that path. Therefore, evaluating
>> reduce a/1 == b
provides you with what is identified by A/1, namely the word B.
In the same way, given
glorp: make object! [
z: does [print "hello"]
one can say
>> reduce glorp/x == 17
To understand your last line, consider this:
>> a/1 == b
tells us that what is in the 1 position of A is the word B.
The definition of GET is
>> help get
GET word /any
Gets the value of a word.
GET is a native value.
word -- Word to get (Type: any-word)
/any -- Allows any type of value, even unset.
that is, GET retrieves the value of a word. So this expression
>> get a/1 == "foo"
first evaluates A/1 to the word B, then applies GET to B, and
returns the result, which is B's associated value "foo".
It's turtles all the way down!