TLS Chapter #02 Examples in Oz % Defined in previous chapters fun {IsAtomS X} if {IsAtom X} andthen {Not X == nil} then true else {IsNumber X} end end %%%%%%%%%%%%%%%%%%% The Little Schemer - Chapter - 2 %%%%%%%%%%%%%%%%%%%%%% % 2.7 fun {IsLat L} if L == nil then true elseif {IsAtomS L.1} then {IsLat L.2} else false end end % 2.1 local L in L = ['Jack' 'Sprat' could eat no chicken fat] {Browse 1#{IsLat L}} end % 2.2 local L in L = [['Jack'] 'Sprat' could eat no chicken fat] {Browse 2#{IsLat L}} end % 2.3 local L in L = ['Jack' ['Sprat' could] eat no chicken fat] {Browse 3#{IsLat L}} end % 2.4 local L in L = nil {Browse 4#{IsLat L}} end % 2.7 local L in L = [bacon and eggs] {Browse 7#{IsLat L}} end % 2.9 - 2.10 local L in L = [bacon and eggs] {Browse 9#(L == nil)} end % 2.11 local L in L = [bacon and eggs] {Browse 11#{IsAtomS L.1}} end % 2.12 - 2.13 local L in L = [bacon and eggs] {Browse 12#{IsLat L.2}} end % 2.15 - 2.16 local L in L = [and eggs] {Browse 15#(L == nil)} end % 2.17 local L in L = [and eggs] {Browse 17#{IsAtomS L.1}} end % 2.18 - 2.19 local L in L = [and eggs] {Browse 18#{IsLat L.2}} end % 2.20 - 2.21 local L in L = [eggs] {Browse 20#(L == nil)} end % 2.22 - 2.23 local L in L = [eggs] {Browse 22#{IsAtomS L.1}} end % 2.24 local L in L = [eggs] {Browse 24#{IsLat L.2}} end % 2.26 local L in L = nil {Browse 26#(L == nil)} end % 2.27 local L in L = [bacon [and eggs]] {Browse 27#{IsLat L}} end % 2.29 local L in L = [bacon [and eggs]] {Browse 29#{IsLat L}} end % 2.30 - 2.31 local L in L = [bacon [and eggs]] {Browse 30#(L == nil)} end % 2.32 local L in L = [bacon [and eggs]] {Browse 32#{IsAtomS L.1}} end % 2.33 - 2.34 local L in L = [bacon [and eggs]] {Browse 33#{IsLat L.2}} end % 2.35 local L in L = [[and eggs]] {Browse 35#(L == nil)} end % 2.36 local L in L = [[and eggs]] {Browse 36#{IsAtomS L.1}} end % 2.37 local L in L = [[and eggs]] {Browse 37#{IsLat L.2}} end % 2.47 local L1 L2 in L1 = nil L2 = [d e f g] {Browse 47#(L1 == nil orelse {IsAtomS L2})} end % 2.48 local L1 L2 in L1 = [a b c] L2 = nil {Browse 48#(L1 == nil orelse L2 == nil)} end % 2.49 local L1 L2 in L1 = [a b c] L2 = [atom] {Browse 49#(L1 == nil orelse L2 == nil)} end % 2.53 fun {IsMember L A} case L of nil then false [] H|T then if A == H then true else {IsMember T A} end else fail end end % 2.51 local A Lat in A = tea Lat = [coffee tea 'or' milk] {Browse 51#{IsMember Lat A}} end % 2.52 local A Lat in A = poached Lat = [fried eggs and scrambled eggs] {Browse 52#{IsMember Lat A}} end % 2.53 local A Lat in A = meat Lat = [mashed potatoes and meat gravy] {Browse 53#{IsMember Lat A}} end % 2.55 local Lat in Lat = [mashed potatoes and meat gravy] {Browse 55#(Lat == nil)} end % 2.62 local A Lat in A = meat Lat = [mashed potatoes and meat gravy] {Browse 62#(Lat.1 == A orelse {IsMember Lat.2 A})} end % 2.63 local A Lat in A = meat Lat = [mashed potatoes and meat gravy] {Browse 63#(Lat.1 == A)} end % 2.67 local Lat in Lat = [potatoes and meat gravy] {Browse 67#(Lat == nil)} end % 2.70 local A Lat in A = meat Lat = [potatoes and meat gravy] {Browse 70#(Lat.1 == A orelse {IsMember Lat.2 A})} end % 2.72 local A Lat in A = meat Lat = [and meat gravy] {Browse 72#{IsMember Lat A}} end % 2.74 local Lat in Lat = [and meat gravy] {Browse 74#(Lat == nil)} end % 2.77 local A Lat in A = meat Lat = [and meat gravy] {Browse 77#(Lat.1 == A orelse {IsMember Lat.2 A})} end % 2.84 local A Lat in A = meat Lat = [meat gravy] {Browse 84#(Lat.1 == A orelse {IsMember Lat.2 A})} end % 2.85 local A Lat in A = meat Lat = [meat gravy] {Browse 85#{IsMember Lat A}} end % 2.86 local A Lat in A = meat Lat = [and meat gravy] {Browse 86#{IsMember Lat A}} end % 2.87 local A Lat in A = meat Lat = [potatoes and meat gravy] {Browse 87#{IsMember Lat A}} end % 2.88 - 2.89 local A Lat in A = meat Lat = [mashed potatoes and meat gravy] {Browse 88#{IsMember Lat A}} end % 2.90 local Lat in Lat = [mashed potatoes and meat gravy] {Browse 90#(Lat == nil)} end % 2.92 local A Lat in A = meat Lat = [mashed potatoes and meat gravy] {Browse 84#(Lat.1 == A orelse {IsMember Lat.2 A})} end % 2.93 local A Lat in A = meat Lat = [mashed potatoes and meat gravy] {Browse 93#{IsMember Lat.2 A}} end % 2.102 local A Lat in A = meat Lat = [meat gravy] {Browse 102#{IsMember Lat.2 A}} end % 2.103 local A Lat in A = meat Lat = [and meat gravy] {Browse 103#{IsMember Lat.2 A}} end % 2.104 local A Lat in A = meat Lat = [potatoes and meat gravy] {Browse 104#{IsMember Lat.2 A}} end % 2.105 local A Lat in A = meat Lat = [mashed potatoes and meat gravy] {Browse 105#{IsMember Lat.2 A}} end % 2.106 local A Lat in A = liver Lat = [bagels and lox] {Browse 106#{IsMember Lat.2 A}} end % 2.108 local Lat in Lat = [bagels and lox] {Browse 108#(Lat == nil)} end % 2.110 local Lat in Lat = [and lox] {Browse 110#(Lat == nil)} end % 2.112 local Lat in Lat = [lox] {Browse 112#(Lat == nil)} end % 2.115 local Lat in Lat = [lox] {Browse 115#(Lat == nil)} end % 2.116 local A Lat in A = liver Lat = [lox] {Browse 116#(Lat.1 == A orelse {IsMember Lat.2 A})} end % 2.117 local A Lat in A = liver Lat = [lox] {Browse 117#{IsMember Lat.2 A}} end % 2.118 local A Lat in A = liver Lat = [and lox] {Browse 118#(Lat.1 == A orelse {IsMember Lat.2 A})} end % 2.119 local A Lat in A = liver Lat = [and lox] {Browse 119#{IsMember Lat.2 A}} end % 2.120 local A Lat in A = liver Lat = [bagels and lox] {Browse 120#(Lat.1 == A orelse {IsMember Lat.2 A})} end % 2.121 local A Lat in A = liver Lat = [bagels and lox] {Browse 121#{IsMember Lat.2 A}} end |