comments on array proposal


Subject: comments on array proposal
From: Paul Graham (pgraham@cadence.com)
Date: Thu Apr 11 2002 - 06:43:58 PDT


My action items from Monday's meeting:

> ACTION: Paul to send Stu example on how to handle array concatenation

Draft 5 defines array literals, which I assume consist of
constants, but does not define a general array expression in the form of a
concatenation.

For 3.1 we can generalize array concatenation to allow arbitrary
expressions. An unpacked array is not as useful if you can't assign to it
with a concatenation. It's nicer to be able to say:

    x = {a, b, c};

than to say

    x[1] = a; x[2] = b; x[3] = c;

> Question of the value to be returned when an error input is provided to a
> function like $left. Should return X. Generally decided after discussion.

I think we should report an error for attempting to select a nonexistent
dimension. It's somewhat analogous to indexing a scalar. You aren't just
getting the bounds wrong, you are completely mistaking the type of object
you're dealing with.

> $increment sounds better than low, high

I don't see how you can write a loop with $left and $right and $increment
without also getting the min and max of $left and $right (which is what $low
and $high are):

    for (i = `MIN($left(A, 1), $right(A, 1)); i <= `MAX($left(A, 1), $right(A(1)); i += $increment(A, 1)) ...

Or to go from $left to $right using $incrment, you have to conditionally
compare:

    for (i = $left(A, 1); $left(A, 1) > $right(A, 1) ? i >= $right(A, 1) : i <= $right(A, 1); i += $increment(A, 1))

Doesn't this look nicer?

    for (i = $low(A, 1); i <= $high(A, 1); i++)

In this example, since we are going from $low to $high, $increment is not
necessary (it's +1 by definition). So I vote we keep $low and $high. I'm
still not sure how you would use $increment.

Paul



This archive was generated by hypermail 2b28 : Thu Apr 11 2002 - 06:45:27 PDT