Skip to content

Instantly share code, notes, and snippets.

@ygrenzinger
Last active October 15, 2017 19:48
Show Gist options
  • Save ygrenzinger/d64e82836beae5d71909132834fccdbc to your computer and use it in GitHub Desktop.
Save ygrenzinger/d64e82836beae5d71909132834fccdbc to your computer and use it in GitHub Desktop.
Oz Mooc
declare
fun {AppendLists L1 L2}
if L1.1 == nil then L2
else
L1.1 | {AppendLists L2.2 L2}
end
end
declare
fun {Fact N}
local FactAcc in
fun {FactAcc I Acc}
if I > N then Acc
else
{FactAcc (I+1) ((I * Acc.1) | Acc)}
end
end
{List.reverse {FactAcc 2 [1]}}
end
end
declare
fun {Prefix L1 L2}
if L1 == nil then true
else
if L2 == nil then false
else if L1.1 \= L2.1 then false
else
{Prefix L1.2 L2.2}
end
end
end
end
declare
fun {FindString L1 L2}
if L1 == L2 then true
else if L2 == nil then false
else if {Prefix L1 L2} then true
else
{FindString L1 L2.2}
end
end
end
end
declare
fun {FlattenList L}
local SubFlat in
fun {SubFlat L}
case L of
nil then nil
[] H|T then {Append {SubFlat H} {SubFlat T}}
[] X then [X]
end
end
{SubFlat L}
end
end
{Browse {FlattenList [a [1 [3 [4]]] [4 5 6]]}}
declare
fun {Fact N}
local FactT R in
proc {FactT I Acc R}
if I > N then R = Acc|nil
else
local T in
R = Acc|T
{FactT (I+1) (Acc*I) T}
end
end
end
{FactT 2 1 R}
R
end
end
{Browse {Fact 20}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment