2012-11-17

arrays are records are tuples

8.19: adda/dstr/array and record syntax as modes of access:
if ( x.y ) and ( x#y ) are both valid
regardless of whether x is defined as an array or record;
this ignores an idiom where
arrays represent lists of items,
while records represent items with named parts;
. well, my way lets you do it both ways,
but it should be admitted that the writer's freedom
is inevitably the reader's headache .

adda/dstr/array vs record precedence:
. if you have x#y.z
does it mean x#(y.z) or x#(y).z ?
my first impression is that y.z is the tightest binding;
ie, it means x#(y.z);
also, (x#(y) = x#y) only when y is an atom,
and you could argue that y.z is not an atom:
it's a sort of address-addition operation; [11.16:
but, of course, that would be a stretch!
it's more intuitively seen as a style of atom naming .
. finally, consider how functions and arrays
should be similar;
( f x.y ) should be seen as a variant of
( a# x.y ); therefore, the parsing is ( a#(x.y) ). ]
. x.y#z is unambiguous: x has component y,
which is an array taking parameter z;
ie, it's parsed as ( (x.y)#z ).

8.20: adda/dstr/arrays are a species of record.type:
. an array is generating a list of component names,
and then declaring them all to be the same type .
. records are a generalization of this,
where a generated list of components
can have a variety of types .
. in fact, fully-oop arrays are actually records;
because, they often have a variety of types .
. arrays are parameterized types,
and records can be parameterized too
. here's a syntax for allowing a record
to describe parts of itself the way arrays do:
reca(n.int).type: ( a.t1, b.t2, #(0..n).t3 );
x.reca(3)
-- now x = (a:..., b:..., 0:..., 1:..., 2:..., 3:... ).

1 comment:

  1. adda/type/tuple/arrays in record/syntax:
    8.21:
    . we have arrays as defining record fields,
    ie, the arrays are within the record,
    as long as the union of the field names is not overlapping;
    but within an interface definition,
    there can be one record def and numerous array defs,
    to mean the same things
    as if they were all in one record def .
    8.22:
    . why have special cases in syntax
    just for the writer's convenience
    when it's harder on the reader?
    . have it designed the same as when
    described outside of an interface:
    either there is a pure array: x#().t,
    or there is a pure record: x.(...)
    but if there is a tuple with both,
    then the arrays are embedded in the record,
    like this: x.( #(dom1).t, #(dom2).t2, ...);
    likewise for in the interface:
    .<...; .( #(dom1).t, #(dom2).t2, ...); > .

    ReplyDelete