TLS Chapter #01 Examples in Oz % Scheme equivalent functions in Oz fun {IsNil L} case L of nil then true [] _|_ then false else fail end end %fun {CAR L} L.1 end %fun {CDR L} L.2 end %fun {CONS X Y} X|Y end %fun {LIST X} {IsList X} end %fun {NULL X} {IsNil X} end %fun {EQ X Y} X == Y end % Note: Scheme Atom? is slightly different then standard Oz function IsAtom fun {IsAtomS X} if {IsAtom X} andthen {Not X == nil} %% note: {IsAtom nil} == true then true else {IsNumber X} %% note: numbers not atoms in Oz end end %%%%%%%%%%%%%%%%%%% The Little Schemer - Chapter - 1 %%%%%%%%%%%%%%%%%%%%%% % 1.1 {Browse 1#atom} % 1.2 {Browse 2#turkey} % 1.3 {Browse 3#1492} % 1.4 {Browse 4#u} % 1.5 {Browse 5#'*abc$'} % 1.6 {Browse 6#[atom]} % 1.7 {Browse 7#[atom turkey 'or']} % 1.8 % {Browse 8#[atom turkey] 'or'} % 1.9 {Browse 9#[[atom turkey] 'or']} % 1.10 {Browse 10#xyz} % 1.11 {Browse 11#[x y z]} % 1.12 {Browse 12#[[x y] z]} % 1.13 {Browse 13#[how are you doing so far]} % 1.14 {Browse 14#{Length [how are you doing so far]}} % 1.15 {Browse 15#[[[how] are] [[you] [doing so]] far]} % 1.16 {Browse 16#{Length [[[how] are] [[you] [doing so]] far]}} % 1.17 {Browse 17#{IsList nil}} % 1.18 {Browse 18#{IsAtomS nil}} % 1.19 {Browse 19#{IsList [nil nil nil]}} % 1.20 local L in L = [a b c] {Browse 20#(L.1)} end % 1.21 local L in L = [[a b c] x y z] {Browse 21#(L.1)} end % 1.22 %local L in % L = hotdog % {Browse 22#(L.1)} %% Note: compiler flags as error %end % 1.23 %local L in % L = nil % {Browse 23#(L.1)} %% Note: compiler flags as error %end % 1.25 local L in L = [[[hotdogs]] [and] [pickle] relish] {Browse 25#(L.1)} end % 1.26 local L in L = [[[hotdogs]] [and] [pickle] relish] {Browse 26#(L.1)} end % 1.27 local L in L = [[[hotdogs]] [and]] {Browse 27#(L.1.1)} end % 1.28 local L in L = [a b c] {Browse 28#(L.2)} end % 1.29 local L in L = [[a b c] x y z] {Browse 29#(L.2)} end % 1.30 local L in L = [hamburger] {Browse 30#(L.2)} end % 1.31 local L in L = [[x] t r] {Browse 31#(L.2)} end % 1.32 %local A in % A = hotdogs % {Browse 32#(A.2)} %% Note: compiler flags as error %end % 1.33 %local L in % L = nil % {Browse 33#(L.2)} %% Note: compiler flags as error %end % 1.35 local L in L = [[b] [x y] [[c]]] {Browse 35#(L.2.1)} end % 1.36 local L in L = [[b] [x y] [[c]]] {Browse 36#(L.2.2)} end % 1.37 %local L in % L = [a [b [c]] d] % {Browse 37#(L.1.2)} %% Note: compiler flags as error %end % 1.40 local A L in A = peanut L = [butter and jelly] {Browse 5#(A|L)} end % 1.41 local S L in S = [banana and] L = [peanut butter and jelly] {Browse 41#(S|L)} end % 1.42 local S L in S = [[help] this] L = [is very [[hard] to learn]] {Browse 42#(S|L)} end % 1.44 local S L in S = [a b c] L = nil {Browse 44#(S|L)} end % 1.45 local S L in S = a L = nil {Browse 45#(S|L)} end % 1.46 local S L in S = [[a b c]] L = b {Browse 46#(S|L)} end % 1.47 local S L in S = a L = b {Browse 47#(S|L)} end % 1.49 local S L in S = a L = [[b] c d] {Browse 49#(S|L.1)} end % 1.50 local S L in S = a L = [[b] c d] {Browse 50#(S|L.2)} end % 1.51 local L in L = nil {Browse 51#(L == nil)} end % 1.52 local L in L = nil {Browse 52#{IsNil L}} end % 1.53 local L in L = [a b c] {Browse 53#{IsNil L}} end % 1.54 local A in A = spaghetti try {Browse 54#{IsNil A}} catch _ then skip end end % 1.56 local S in S = 'Harry' {Browse 56#{IsAtomS S}} end % 1.57 local S in S = 'Harry' {Browse 57#{IsAtomS S}} end % 1.58 local S in S = ['Harry' had a heap 'of' apples] {Browse 58#{IsAtomS S}} end % 1.60 local L in L = ['Harry' had a heap 'of' apples] {Browse 60#{IsAtomS L.1}} end % 1.61 local L in L = ['Harry' had a heap 'of' apples] {Browse 61#{IsAtomS L.2}} end % 1.62 local L in L = ['Harry'] {Browse 62#{IsAtomS L.2}} end % 1.63 local L in L = [swing low sweet cherry oat] {Browse 63#{IsAtomS L.2.1}} end % 1.64 local L in L = [swing [low sweet] cherry oat] {Browse 64#{IsAtomS L.2.1}} end % 1.65 local A1 A2 in A1 = 'Harry' A2 = 'Harry' {Browse 65#(A1 == A2)} end % 1.66 local A1 A2 in A1 = 'Harry' A2 = 'Harry' {Browse 66#(A1 == A2)} end % 1.67 local A1 A2 in A1 = margarine A2 = butter {Browse 67#(A1 == A2)} end % 1.69 local L1 L2 in L1 = nil L2 = [strawberry] {Browse 69#(L1 == L2)} end % 1.70 local N1 N2 in N1 = 6 N2 = 7 {Browse 70#(N1 == N2)} end % 1.72 local L A in L = ['Mary' had a little lamb] A = 'Mary' {Browse 72#(L.1 == A)} end % 1.73 local L A in L = [soured milk] A = milk {Browse 73#(L.2 == A)} end % 1.74 local L in L = [beans beans we need jelly beans] {Browse 74#(L.1 == L.2.1)} end |