Guest User

Untitled

a guest
Mar 9th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Oz 1.21 KB | None | 0 0
  1. % <LList T> ::= lNil | lCons(T ({} -> <LList T>))
  2.  
  3. declare fun {LIter F X} lCons(X fun {$}{LIter F {F X}} end) end
  4.  
  5. declare fun {LFrom K}{LIter fun {$ N} N+1 end K} end
  6.    
  7. declare
  8. fun {LTake N LL}
  9.    case N#LL
  10.    of 0#_ then nil
  11.    [] _#lNil then nil
  12.    [] M#lCons(X LT) then X|{LTake M-1 {LT}}
  13.    end
  14. end
  15.  
  16. declare
  17. fun {Krazy K LL}
  18.    local
  19.       fun {Pom N#LL}
  20.      case N#LL
  21.      of _#lNil then lNil
  22.      [] 0#lCons(_ T) then {Pom K#{T}}
  23.      [] N#lCons(H _) then lCons(H fun {$}{Pom N-1#LL} end)
  24.      end
  25.       end
  26.    in {Pom K#LL}
  27.    end
  28. end
  29.  
  30. {Show {LTake 10 {Krazy 2 {LFrom 1}}}}
  31.  
  32. declare
  33. fun {Fibonacci}
  34.    local
  35.       fun {Fib A#B}
  36.      lCons(B fun {$}{Fib A+B#A} end)
  37.       end
  38.    in {Fib 1#0}
  39.    end
  40. end
  41.  
  42. {Show {LTake 10 {Fibonacci}}}
  43.  
  44. % <LBT T> ::= lEmpty | lNode(T ({}-> <LBT T>)({}-> <LBT T>))
  45.  
  46. declare
  47. fun {LTree N}
  48.    lNode(N fun {$}{LTree 2*N} end fun {$}{LTree 2*N+1} end)
  49. end
  50.  
  51. declare
  52. fun {BreadthLBT Tree}
  53.    local
  54.       fun {Bre Queue}
  55.      case Queue
  56.      of nil then lNil
  57.         [] lEmpty|Tail then {Bre Tail}
  58.      [] lNode(V L R)|Tail then lCons(V fun {$}{Bre {Append Tail [{L} {R}]}} end)
  59.      end
  60.       end
  61.    in {Bre [Tree]}
  62.    end
  63. end
  64.  
  65. {Show {LTake 10 {BreadthLBT {LTree 1}}}}
Add Comment
Please, Sign In to add comment