Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Functional programming in REBOL

From: larry:ecotope at: 8-Aug-2001 10:39

Hi Gabriele, Thanks for your comments.
> [BTW, just to let you know, I think this has been discussed on > this list before, with Ladislav providing a nice and general solution > IIRC]
Yes, I missed e-func, see my reply to Ladislav earlier.
> LP> pa2: func [f x /local h][ > LP> h: func [f x][func [y][f :x :y]] > LP> h :f :x > LP> ] > > I'd write it as: > > pa2: func [f x] [ > use [ff xx] [ > xx: :x > ff: :f > func [y] [ff xx y] > ] > ]
Yes, I have a set of higher-order funcs written in exactly that fashion. But I don't like it. Renaming all the variables in the code block is ugly, and it seemed to me the approach would be cumbersome (and perhaps diffcult) to generalize for creating the generic cfunc. I think changing only the spec blocks as in cfunc or Ladislav's e-func is preferable.
> or > > pa2: func [f x] [ > func [y] reduce [:f :x 'y] > ]
I really liked that one. Unfortunately, it doesn't pass the mystery test as shown in the console session below where I have renamed your version to pa4.
>> pa2: func [f x /local h][
[ h: func [f x][func [y][f :x :y]] [ h :f :x [ ]
>> pa4: func [f x] [
[ func [y] reduce [:f :x 'y] [ ]
>> mystery2: pa2 :pa2 :pa2 >> mystery4: pa4 :pa4 :pa4 >> type? mystery2 :+
== function!
>> type? mystery4 :+
** Script Error: y expected value1 argument of type: number pair char mone y date time tuple ** Where: mystery4 ** Near: func [f x][ func [y] reduce [:f :x 'y] ] func [f x][ func [y] reduce [:f :x 'y] ] y Regards -Larry