%
% semantics of case allows for non-record values in the left-hand
% side: the meaning is not to throw a dynamic typing error, but rather
% to follow the "else" clause; e.g:
%
local I = fun {$ X} X end in
case I of H|T then
{Browse H}
else {Browse 'no match'}
end
end
local X = 5 in
case X of H|T then
{Browse H}
else {Browse 'no match'}
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Syntactic sugar examples %
%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
local X A B in
A = "George"
B = 25
X = person(name:A age:B)
{Browse X}
end
local X = person(name:"George" age:25) in {Browse X} end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
local T in
local A B C D in
T = tree(key:A left:B right:C value:D)
A = 1
B = 2
C = 3
D = 4
end
{Browse T}
end
local T in
local tree(key:A left:B right:C value:D) = T in
A = 1
B = 2
C = 3
D = 4
end
{Browse T}
end
local A B C D T = tree(key:A left:B right:C value:D) in
A = 1
B = 2
C = 3
D = 4
{Browse T}
end
%Exercise:
%Here is another attempt at a construct equivalent to the above.
%Will it work? Why or why not?
%
%local T = tree(key:A left:B right:C value:D) in
% A = 1
% B = 2
% C = 3
% D = 4
% {Browse T}
%end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
local T in
local tree(key:A left:B right:C value:D)=T in A = 1 B = 2 C = 3 D = 4 end
{Browse T}
end
%Exercise:
%Here is another attempt at a construct equivalent to the above.
%Will it work? Why or why not?
% local T in
% local A B C D in
% {Label T} = tree
% T.key = A
% T.left=B
% T.right=C
% T.value=D
% A = 1
% B = 2
% C = 3
% D = 4
% end
% {Browse T}
% end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Extracting values from a compound data structure %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
local T A in
T = tree(key:"seif" age:48 profession:"professor")
tree(key:A ...) = T
{Browse A}
end
%Note : The browser will display a list of ASCII values. To view that
%as a string, click on Options, Representation and then String
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%