<< Demo006 >> << Streams >> << Section 1: Basic Constructs >> ( 1, 2, 3, 7, 11, 13)? ( 3.4, 5.6, 7.8, 9.2)? ( 'A', 'D', 'A', 'M')? x = 5; y = 7; ( x - y, x + y, x * y, x / y)? ( 2, (9, 7), (4, 5, 6), 3, 8)? 3 .. 7? << Section 2: Operations on Streams >> 2 * ( 3, 4, 5)? 2 - ( 3, 4, 5)? ( 3, 4, 5) - 2? ( 2, 3) + ( 4, 5, 6)? ( 2, 3) * ( 4, 5, 6)? ( 2, 3) - ( 4, 5, 6)? ( 2, 3, 4) * ( 4, 5, 6)? - ( 2, 3, 4)? + ( 2.3, 3.4, 4.5)? ~ ( true, false, true)? f(integer) -> integer; f(x) = 3 * x; f(( 2, 3, 4))? g(integer,integer) -> integer; g(x,y) = x + y; g((2,3),(4,5))? (2, 3, 4) - (5, 6) * (7, 8)? 2 * 1..5? 1..3 - 1..3? ( 21, 2 * 13..15, 33)? << Section 3: Empty Streams >> 2..1? +2..1? 2 * 2..1? 2 - 2..1? 2..1 - 2..1? 2..1 + ( 4, 5, 6)? ( 2, 3) * 2..1? f(2..1)? g((2, 3), 2..1)? ( 2, 2..1, 5)? << Section 4: Expression Evaluation Rules >> A() -> multi(integer); A() = ( 3, 4, 5); B() -> multi(integer); B() = ( 7, 9); C() -> multi(integer); C() = 1..0; << empty stream >> 2 * A()? << product = 1 * 3 >> A() - 5? << product = 3 * 1 >> A() + B()? << product = 3 * 2 >> B() * A()? << product = 2 * 3 >> A() * C()? << product = 3 * 0 >> C() + B()? << product = 0 * 2 >> F(integer,integer,integer) -> integer; F(x, y, z) = x + y + z; F(A(), A(), A())? << product = 3 * 3 * 3; => 27 evaluations of F >> F(A(), B(), B())? << product = 3 * 2 * 2; => 12 evaluations of F >> F(A(), B(), C())? << product = 3 * 2 * 0; => no evaluations of F >> << Section 6: Quantifiers >> f(integer,integer) -> multi(integer); f(p, q) = p .. q; f(3,6)? f(7,2)? g1(integer,integer) -> multi(integer); g1(p, q) = (p - q, p + q, p .. q); g1(7,2)? g1(3,5)? h(integer, integer) -> optional (integer); h(p, q) = p.. q; h(3,6)? h(7,2)? << Section 7 Example: Parental Relations >> type Person = (Mary, George, John, Liz, Albert, Alice, Jane, Harry, Unknown ); mother(Person) -> Person; mother(=Mary) = Liz; mother(=George) = Liz; mother(=John) = Alice; mother(=Liz) = Jane; mother(others) = Unknown; father(Person) -> Person; father(=Mary) = John; father(=George) = John; father(=John) = Albert; father(=Liz) = Harry; father(others) = Unknown; parents(Person) -> multi(Person); parents( P ) = ( father(P), mother(P) ); grandmothers(Person) -> multi(Person); grandmothers( P ) = ( mother(father(P)), mother(mother(P)) ); grandfathers(Person) -> multi(Person); grandfathers( P ) = ( father(father(P)), father(mother(P)) ); grandparents(Person) -> multi(Person); grandparents( P ) = parents(parents(P)); mother(Mary)? father(mother(George))? parents(Mary)? parents(Harry)? grandfathers(Mary)? grandparents(George)? << Section 8: Undefined Values >> Sqrt(real) -> optional(real); Sqrt(X) = sqrt(X) when X >= 0.0; Sqrt(25.0)? Sqrt(-25.0)? << << Section 10: Recursive Stream Definitions >> from(integer) -> multi(integer); from(n) = (n, from(n+1)); from(0)? Factorials(integer, integer) -> multi(integer); Factorials(n, p) = ( p, Factorials(n + 1, (n + 1) * p)); Factorials(1,1)? >>