This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
iex> list1 = [3, 2, 1] | |
[3, 2, 1] | |
iex> list2 = [4 | list1] | |
[4, 3, 2, 1] | |
iex> list1 | |
[3, 2, 1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare Sqrt Iterate Abs | |
fun {Abs X} if X < 0.0 then ~X else X end end | |
fun {Iterate S IsDone Transform} | |
if {IsDone S} then S | |
else S1 in | |
S1={Transform S} | |
{Iterate S1 IsDone Transform} | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare Sqrt SqrtIter Improve GoodEnough Abs | |
fun {Sqrt X} | |
Guess = 1.0 | |
in | |
{SqrtIter Guess X} | |
end | |
fun {SqrtIter Guess X} | |
if {GoodEnough Guess X} then Guess |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare FinallyExample Eval | |
fun {Eval E} | |
if {IsNumber E} then E | |
else | |
case E | |
of plus(X Y) then {Eval X} + {Eval Y} | |
[] times(X Y) then {Eval X} * {Eval Y} | |
else raise illFormedExpr(E) end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local SMerge in | |
fun {SMerge Xs Ys} | |
case Xs#Ys | |
of nil#Ys then Ys | |
[] Xs#nil then Xs | |
[] (X|Xr)#(Y|Yr) then | |
if X=<Y then X|{SMerge Xr Ys} | |
else Y|{SMerge Xs Yr} end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare X Y | |
if f(X Y d)==f(a Y c) then {Browse 'case'(1)} | |
else {Browse 'case'(2)} | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare Test | |
proc {Test X} | |
case X | |
of a|Z then {Browse 'case'(1)} | |
[] f(a) then {Browse 'case'(2)} | |
[] Y|Z andthen Y==Z then {Browse 'case'(3)} | |
[] Y|Z then {Browse 'case'(4)} | |
[] f(Y) then {Browse 'case'(5)} | |
else {Browse 'case'(6)} end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local X in | |
X=person(name:"George" age:25) | |
if {Label X}==person andthen {Arity X}.2.1==name andthen X.name=="George" then {Browse X.age} | |
else {Browse false} | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local X in | |
X=person(name:"George" age:25) | |
case X | |
of person(name:"George" age:_) then {Browse X.age} | |
else {Browse false} | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local X Y T in | |
X=1 | |
Y=1 | |
T=X==Y | |
case T of true then {Browse true} else {Browse false} end | |
end |
NewerOlder