Hi, Elan

[some text deleted ...]

I think if you take a minute to see how simple the implementation of the
curried function really is, something that would be far more complicated to
implement in something like Perl, I trust (any Perl experts out there?),
you should slowly begin to realize that it is well worth your while to
begin to learn some of the more subtle details of REBOL programming.

[L]
Thanks for your nice words, I'll try my best...
[/L]

[examples deleted...]

Now, I tried the version of curried you included in your message and

ad a) I believe your curried function is not designed properly in that it
requires a function and in addition a block of words. Since the function
you pass to curried must meet the formal REBOL requirements for a function,
it includes the block of arguments already. Why do require that they
passed? My curried function uses the function's own argument block and does
not require that the argument block be passed separately. Why don't you
look at how I did that and modify your curried function accordingly?

[L]
Ah, you didn't look at my description of the second argument?

Don't worry, I looked how you did it and modified my version accordingly:

curryfirst: func [fnc [any-function!]
    /local formargs firstarg original
    ] [
    formargs: first :fnc
    if empty? formargs [return none]
    original: compose [(:fnc) (formargs)]
    func compose [(first formargs)] compose/deep [func [(next formargs)]
[(original)]]
    ]

[/L]

I am not sure what your curried function is supposed to return. It most
certainly does not return a function that will generate new functions,
whose first argument has been bound to a value passed to that function.
That is what a curried function should do. Mine does do that. Why don't you
take a look at how I did that and use a similar approach?

[L]
I swear, I will try my best, but the original is the original...
[/L]

ad b) We had established in the function reentry thread that relying on the
argument binding in the parent function is dangerous, when you reuse the
parent function to create additional descendant functions.
I tested your curried function with add and this is what I get:

>> ladislav-addc: ladislav-curried :add [x y] ;- shouldn't need to add block
>> source ladislav-addc
ladislav-addc: func [x y][func [] [function x y]]
>> ladislav-add4: ladislav-addc 4
** Script Error: ladislav-addc is missing its y argument.
** Where: ladislav-add4: ladislav-addc 4

[L]
here I must stand behind the poor man,
If you don't know what is the purpose of the argument, how can you use the
function meaningfully?
[/L]

Ladislav-addc should not require a y argument, since it is supposed to
create a curried function, in other words a function that binds the first
argument and will in future use the bound argument together with a second
or more arguments.

Contrast the above code with my version, which at least does handle add
correctly:

>> add: func [x y] [ x + y ]
>> addc: curried :add
>> add4: addc 4
>> add5: addc 5
>> add4 4
== 8
>> add5 4
== 9

Study it and learn from it. Why not?

[L]
I am prepared to do so.
[/L]

>Try your curried for yourself.

Why? Why "for yourself"?

Elan

[L]
I tried to suggest you to try the given example - to find out what is wrong
with your implementation. My suggestion was probably meaningful, because you
know...

rest of code deleted

Ladislav

Reply via email to