% This file is simply the “tangled” code of oz-demo.org; % it is the “raw” source code, provided for your convenience. {Browse 'Hello world'} declare S = 'Hello world' {Browse S} declare `A fancier greeting` = 'A pleasure to make you acquaintance, my good fellow.' {Browse `A fancier greeting`} declare `An alphanumeric atom` = this_Is_An_Atom `A printable characters atom` = 'This is also an atom.' `A quoted keyword` = 'if' {Browse `An alphanumeric atom`} {Browse `A printable characters atom`} {Browse `A quoted keyword`} {Browse 123} % integer {Browse 1.23} % floating point {Browse &{ } % character ({ is 123 in ASCII) {Browse 0123} % octal (leading 0) {Browse 0x123} % hexidecimal (leading 0x) {Browse true} {Browse false} {Browse nil} {Browse (1 | 2 | 3 | nil)} {Browse [1 2 3]} {Browse "Hello world"} {Browse [&H &e &l &l &o & &w &o &r &l &d]} {Browse ""} declare X = my_record_name( descr : 'A record carrying this string and an integer' a_num : 123) {Browse X} {Browse X.descr} {Browse X.a_num} declare X = r('I am field 1. Field 2 is 123. Field 3 is true.' 123 true) {Browse X.1} {Browse X.2} {Browse X.3} declare L = [1 2 3] `Explicit L` = '|'(1 '|'(2 '|'(3 nil))) {Browse L.1} {Browse L.2} {Browse `Explicit L`} {Browse (if true then 'true is true.' end)} {Browse (if true then 'First branch' else 'Second branch' end)} if false then {Browse 'No else clause here.'} end {Browse (if false then 'No.' elseif false then 'No.' else 'Yes.' end)} declare L = [1 2 3] {Browse (case L of nil then 'Empty' [] _|nil then 'Singleton' [] _|_|nil then 'Length 2' [] _|_|_|nil then 'Length 3' else 'Longer than 3' end) } {Browse 1 == 1} {Browse 1 =< 1} {Browse 1 >= 1} {Browse 1 < 1} {Browse 1 > 1} {Browse atom1 == atom2 } {Browse "String1" == "String2"} {Browse [1 2 3] == [1 2 3 4]} {Browse true == false } {Browse r(1 2 3) == r(2 3 4) } {Browse abc < bcd} {Browse abc < abcd} % {Browse [1] < [2]} % Cannot compare lists! {Browse {And false false}} {Browse {And false true }} {Browse {And true false}} {Browse {And true true }} %1 % Cannot “execute” an expression! declare fun {Exp M N} if N == 0 then 1 else M * {Exp M (N - 1)} end end {Browse {Exp 2 5}} declare fun {F} 5 end declare fun {F} {Browse 10} % do something 10 % return a value end declare fun {Exp M} fun {$ N} if N == 0 then 1 else M * {{Exp M} (N - 1)} end end end {Browse {{Exp 5} 5}} declare fun {Exp M N} if N == 0 then 1 else M * {Exp M (N - 1)} end end {Browse {Exp 5 5000}} declare fun {Step2 M} if M > 1 then {Step1 M - 2} else M end end fun {Step1 M} if M > 0 then {Step2 M - 1} else M end end fun {MyPlan M} {Step1 M} end