Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Basic Fibs

Name: Anonymous 2013-08-01 16:07

screen 12
dim as integer i = 0
dim as ulongint a = 0, b = 1, c = 0

input "? ", i
while i >= 0
    print a; " ";
    c = b
    b = a + b
    a = c
    i -= 1
wend
sleep

And they said BASIC wasn't useful for anything.

Name: Anonymous 2013-08-01 18:15

>>3

No this is tail recursive and there is only one next thunk due to laziness.


zipWith :: (x -> y -> z) -> [x] -> [y] -> [z]
                                    /-- this is the thunk
zipWith f (x:xs) (y:ys) = f x y : zipWith f xs ys
zipWith f _ _ = []


So if we have three terms, the computations is as follow (with thunks marked):

fibs = 1 : 1 : 2 : zipWith (+) (1 : 1 : 2 :  thunk) (1 : 2 : thunk)

Because of laziness the thunks are only evaluated when needed.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List