Hi,

Hi Ladislav,

I tried duplicating your code on my machine, but since you didn't set 'f to
anything in the code you supplied, REBOL reported an error when I tried to
evaluate the expression
append block2 :f

I am therefore limited to commenting on the code you presented:

you wrote:
>>> block2: [do func [f [any-function!]] [print "OK"]]
>== [do func [f [any-function!]] [print "OK"]]
>>> append block2 :f
>== [do func [f [any-function!]] [print "OK"] func [x][print "OK"]]

The result of append suggests that f evaluated to func [x] [print "OK"]
since that is what was appended in block2.
When you now do block2:

>>> do block2
>** Script Error: none is missing its x argument.
>** Where: do func [f [any-function!]] [print "OK"] func [x][print "OK"]

1. the first function in block2 will be evaluated. That function requires
an argument f, which is a function.
2. REBOL will search for an argument and finds func [x] [print "OK"]. Since
this is a function it will be evaluated, in order to retrieve its value,
which will be passed to func [f [any-function!]] ...
3. In the process of evaluating func [x] [print "OK"], REBOL will now
search for an argument 'x for this function and cannot discover one.
4. It therefore reports an error.

In summary, at the point in time in which REBOL is retrieving the argument,
it does not take the requested argument into consideration and does not
identify the function you supplied as identical with the argument type
expected by the first function being evaluated. Instead it does with this
function what it would with a function in all circumstances, namely it
evaluates to the function, expecting to use the return value of the
evaluated function as an argument for the first function being evaluated.

To achieve what you set out to do, will have to humor REBOL and provide
REBOL
with a function, whose return value is the function you wish to pass:

>> f: func [] [ return func [x] [print "OK"] ]

Now you get the desired result:

>> append block2 :f
== [do func [f [any-function!]] [print "OK"] func [][return func [x] [print
"OK"]]]
>> do block2
OK

Take Care,

Elan

>
>Take care
>
>Ladislav
>
>
>

I recall:

>> block1: [do func[f [any-function!]] [print "OK"] func [x] [print "OK"]]
== [do func [f [any-function!]] [print "OK"] func [x] [print "OK"]]
>> do block1
OK

Why isn't this answer good enough for you?

About your suggestion: I circumvented this bug in "Curried Functions" - see
TOBLOCK and RECO functions, I wonder if your suggestion could have been made
useful?

Ladislav

Reply via email to