<< Demo007 >> << Statements and Special Expressions >> << Section 1: Assignments and Variables >> a = 2 * 3; a? b:= 3 * 4; b? b:= b + a; b? Sigma (integer) -> integer; Sigma (N) = [ sum:=0; sum:=sum + 1..N; sum]; Sigma(7)? Sigmas (integer) -> multi(integer); Sigmas (N) = [ sum:=0; i = 1..N; sum:=sum + i; sum]; Sigmas(7)? Factorial (integer) -> integer; Factorial (N) = [Fact:=1; Fact:=Fact * 1..N; Fact ]; Factorial(7)? fib(integer) -> integer; fib(n) = [ Fib1:=0; Fib2:=1; [ i = 2..n; Fib3:=Fib2 + Fib1; Fib1:=Fib2; Fib2:=Fib3 ]; Fib2 ]; fib(5)? fib(1)? fib(2)? fib(3)? fib(12)? << Variables >> Counter:=0; << new global variable >> F(real) -> real; F(R) = [ Counter:=Counter + 1; R ** 2]; F(3.0)? Counter? F(5.0)? Counter? Increment( var(integer)) -> nothing; Increment( x) = [ x:=x + 1]; i:=0; Increment(var(i)); i? Increment(var(i)); i? P:=0; P:=1..15; P? P:=0; P:=P + 1..15; P? << Section 2: Conditionals >> max(integer, integer) -> integer; max(x, y) = if x > y then x else y; max(37, 29)? Even (integer) -> optional (integer); Even (I) = if mod(I,2) == 0 then I; Even(12)? Even(13)? Even(14)? << Section 3: Repetitions >> print(integer) -> nothing; print(I) = logln(I); f1 (integer) -> nothing; f1 (j) = [ i:=0; repeat [ ready when i > j; i:=i+1; print(i)]]; << early ready >> f2 (integer) -> nothing; f2 (j) = [ i:=0; repeat [ i:=i+1; ready when i > j; print(i)]]; << middle ready >> f3 (integer) -> nothing; f3 (j) = [ i:=0; repeat [ i:=i+1; print(i); ready when i > j]]; << late ready >> f1(7)? f2(7)? f3(7)? << Section 4: Filters >> Select1 (integer) -> multi(integer); Select1 (N) = [ i = 1..N; accept ( mod(i, 7) == 0); i ]; Select2 (integer) -> multi(integer); Select2 (N) = [ i = 1..N; reject ( mod(i, 7) <> 0); i ]; Select1 (30)? Select2 (30)? << Section 5: Exceptions >> FF (integer) -> integer; FF (V) = [ exception ( V == 0, "Value is Zero"); V]; FF (17)? FF (0)? FF (-19)?