2.23: adda/cstr/set generator:
(^ x,y,z: int . f(x,y,z) ) -- this is the set generator;
see how the power param is terminated by a period?
the reason that can't be the usual math operators {: | }
is due to (:) being confused with the label declaration
and with other math uses for (| ) .
. (x.t, y.t) can also be defined by ( x,y: t ).
2.29:
. even if it was ok to overload (| ),
the form of it is opposite of what I need:
math puts the control var to the right of (|):
{ f(x) | x in t }
when I want the control var as the head:
{^ x in t .
f(x)
} -- that way var's are declared before they are used,
and it's easier to read generally,
when the body of the generator is getting large
(I have to admit that for math's one-liner's,
the math way looks neater ).
2012-02-29
Subscribe to:
Post Comments (Atom)
8.1: adda/syntax/generators
ReplyDelete. here is the current, fully typed generator:
f = {^(x.{1..3}).(int,int): (x, x+1) }
-- generates f = { (1, 2), (2,3), (3,4) };
but now I'm thinking we need only define
the control var's type, not the return type,
because then that already tells you
what operations are used,
which then tells you what the result's type is:
eg, f= {^(x.{1..3}) (x, x+1) }
= { 1:2, 2:3, 3:4 } .
. math's way to define the return type is this:
f = {(x in dom, y in codomain) | y = f(x) };
but we need to keep our set generator syntax
consistent with our syntax for the
function call generator: f^(3)(x) = f f f x;
hence, {^(x.t) f(x) }
instead of {^(x.t).t: f(x) }.
. the mandatory colon has be replaced
by the mandatory parenthesis .