Hi,
Hi Ladislav,
you wrote:
>I give you another example:
>Your composite function:
>composite: func ['f 'g][func [x] compose [(f) (g) x]]
>f: func [x [any-function!]] ["OK"]
>g: func [x] [:x]
>x: func [x] ["OK"]
>fg: composite f g
>
>[correcting the typo:]
>
>>> result: fg :x
>** Script Error: x is missing its x argument.
>** Where: result: fg x
Composite works properly. x is an active function. x is supplied as an
argument to the composite function. The following will be executed:
compose [(f) (g) x]
f becomes the func [x [any-function!]] ["OK"]
g becomes func [x [any-function!]] ["OK"]
g wants an argument x, so REBOL grabs the x in compose [(f) (g) x]
REBOL evaluates x's body because it is a function and whatever the body
evaluates to will be used as g's argument. x is a function that takes an
argument. You didn't supply an argument for 'x, so REBOL reports an error.
Hope this helps,
Elan
[L]
Long speech.
If you debug the code, you get this:
composite: func ['f 'g][func [x] compose [(f) (g) :x]]
f: func [x [any-function!]] ["OK"]
g: func [x] [:x]
x: func [x] ["OK"]
fg: composite f g
>> fg :x
== "OK"
, which is correct result, because:
>> f g :x
== "OK"
Actually this really wasn't an example of the function evaluation bug, so
here it is:
block1: [func [x [function!]] [print "OK"] func [x] [print "OK"]]
== [func [x [function!]] [print "OK"] func [x] [print "OK"]]
block2: reduce block1
== [func [x [function!]][print "OK"] func [x][print "OK"]]
insert block1 'do
block1
== [do func [x [function!]] [print "OK"] func [x] [print "OK"]]
insert block2 'do
block2
== [do func [x [function!]][print "OK"] func [x][print "OK"]]
do block1
OK
do block2
** Script Error: none is missing its x argument.
** Where: do func [x [function!]][print "OK"] func [x][print "OK"]
And, please, don't explain to me, that a function shall be evaluated. It
shall not:
probe third block2
func [x][print "OK"]
(a function, no evaluation, no missing argument...)
Evaluation is in doc's reserved for words not for other datatypes.
Cf:
"The most common way to get the value of a word is to evaluate it (execute
it or get its value). "
You see? WORD is the data that is evaluated, not FUNCTION!