Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % <LList T> ::= lNil | lCons(T ({} -> <LList T>))
- declare fun {LIter F X} lCons(X fun {$}{LIter F {F X}} end) end
- declare fun {LFrom K}{LIter fun {$ N} N+1 end K} end
- declare
- fun {LTake N LL}
- case N#LL
- of 0#_ then nil
- [] _#lNil then nil
- [] M#lCons(X LT) then X|{LTake M-1 {LT}}
- end
- end
- declare
- fun {Krazy K LL}
- local
- fun {Pom N#LL}
- case N#LL
- of _#lNil then lNil
- [] 0#lCons(_ T) then {Pom K#{T}}
- [] N#lCons(H _) then lCons(H fun {$}{Pom N-1#LL} end)
- end
- end
- in {Pom K#LL}
- end
- end
- {Show {LTake 10 {Krazy 2 {LFrom 1}}}}
- declare
- fun {Fibonacci}
- local
- fun {Fib A#B}
- lCons(B fun {$}{Fib A+B#A} end)
- end
- in {Fib 1#0}
- end
- end
- {Show {LTake 10 {Fibonacci}}}
- % <LBT T> ::= lEmpty | lNode(T ({}-> <LBT T>)({}-> <LBT T>))
- declare
- fun {LTree N}
- lNode(N fun {$}{LTree 2*N} end fun {$}{LTree 2*N+1} end)
- end
- declare
- fun {BreadthLBT Tree}
- local
- fun {Bre Queue}
- case Queue
- of nil then lNil
- [] lEmpty|Tail then {Bre Tail}
- [] lNode(V L R)|Tail then lCons(V fun {$}{Bre {Append Tail [{L} {R}]}} end)
- end
- end
- in {Bre [Tree]}
- end
- end
- {Show {LTake 10 {BreadthLBT {LTree 1}}}}
Add Comment
Please, Sign In to add comment