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: 12-Aug-2001 21:42

Hi Ladislav, all Latest News Flash from the Y front. I just blew a mental fuse and possibly discovered a new way of defining the Y-combinator in REBOL which is much simpler than the previous ones. Given the wrapped version of the factorial function: fact*: func [fact][ func [n][ either zero? n [1][n * fact n - 1] ] ] Define Y like this: Y2: func [f][f f :f] This is another combinator, (i.e., a higher order function with no free variables). Now at the console:
>> fact: Y2 :fact* >> fact 16.0
== 20922789888000 fact seems to calculate the correct answers.
>> do fact* Y2 :fact* 5
== 120
>> do fact* fact* Y2 :fact* 5
== 120 It seems to satisfy the fixed-point property for Y. Question 1: Is Y2 really a valid definition of Y? Or have I missed something important. One warning sign is that the same formulation does not work in Scheme. In Scheme you have to put as many applications of f into the definition of Y2 as the n you want the recursion to work for. Possibly it works for all cases in REBOL with just the 2 applications of f to f because of the difference in the evaluation model for local variables between REBOL and Scheme. I'll have another look at this when brain function is restored. Puzzled -Larry