[REBOL] Encouraging functional programming Re:(8)

1999-12-01 Thread mailinglists

Hi,

I've been following this thread (though it goes over my head a bit) with
interest, but with this one you guys have lost me! =)

First of all what are Fibonnacci numbers?

Second, perhaps someone could explain to me what Ladislav's code does?

 -Original Message-
 I calculate the Fibonnacci numbers without recursion using REBOL. For
 example

  fib 100
 == 3.54224848179262E+20
 

 How would you calculate it with recursion?

 Jerry

 fib: func [first second n] [

 either n = 1 [first] [

 either n = 2 [second] [

 fib second first + second n - 1

 ]

 ]

 ]

  fib 1.0 1.0 100
 == 3.54224848179262E+20

 Ladislav




[REBOL] Encouraging functional programming Re:(8)

1999-11-28 Thread 70740 . 503

Ladislav,

I am impressed by your recursive fib. In fact it inspired me to write a
zero finding routine in a similar manner. If I am not imposing too much,
can you tell me if it is functional programming?

Jerry

 x: binsrch "x - exp - x" 'x 0 1
== 0.567143290409784
 exp - x
== 0.567143290409784


xeq: func [f v x] [do join v [": " x]  do f]

binsrch: func [f v b e]
[
   if ((xeq f v b) * (xeq f v e))  0
   [print "binsrch: f must have different signs at endpoints"
   return none]
   either (xeq f v b)  0
   [binsrch0 f v b e 50]
   [binsrch0 f v e b 50]
]

binsrch0: function [f v b e n] [x]
[
   x: b + e / 2
   if n = 0 [return x]
   either (xeq f v x)  0
   [binsrch0 f v x e n - 1]
   [binsrch0 f v b x n - 1]
]



[REBOL] Encouraging functional programming Re:(8)

1999-11-27 Thread 70740 . 503

Jordan,

I am impressed with your clever function. It seems to take only 10% more
time than my non-recursive version.

Jerry