Skip to content

Instantly share code, notes, and snippets.

@nowelium
Created May 5, 2010 08:01
Show Gist options
  • Save nowelium/390516 to your computer and use it in GitHub Desktop.
Save nowelium/390516 to your computer and use it in GitHub Desktop.
Stream := Object clone do (
create := method(car, cdr,
stream := self clone
stream car ::= car
stream cdr ::= cdr
stream
)
each := method(k,
k call(car)
cdr each(k)
)
squareBrackets := method(index,
if(index == 0, return car)
cdr call [index - 1]
)
)
@nowelium
Copy link
Author

nowelium commented May 5, 2010

Fibonacci number @ Stream

hoge := Stream clone do(
    fib := method(a, b,
        self create(a, block(
            fib(b, a + b)
        ))
    )
)
results := hoge fib(0, 1)
results [10] println // ==> 55

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment