Subject: Re: Proposal for array types
From: Paul Graham (pgraham@cadence.com)
Date: Mon Apr 08 2002 - 11:51:47 PDT
> I suggest dropping $low and $high, and adding $increment - which will return
> -1,0 or 1 for the right -> left increment. A non-existant dimension would
> return 0,-1,1 for $left, $right, $increment. A zero value for $increment
> indicates a single element array or a scalar.
> $increment would be forward compatible if we allow increments other than
> 1 (or the array is foreign).
It doesn't make sense for $increment to return 0. Otherwise a for loop
with an incrementer like:
i = i + $increment(X, 1);
will loop forever.
Also, it's not easy to step through an array using $left and $right only,
because you need to know whether the stop condition is (i <= $right) or (i
>= $right), or else you need to use MIN and MAX macros. So I think $low and
$high are still useful.
Practically speaking, it's hard to imagine a case where you would query a
non-existent dimension, except as a typo. Remember, this is not the same as
querying a non-existing element of an array. It's easy to query a
non-existent element by accident, because it's hard to keep track of array
bounds and index variables. But for instance, a two-dimensional unpacked
array has only two unpacked dimensions (and one or more packed dimensions),
so you're only ever likely going to use the integer literals 1, 2 and maybe
3 or more for the unpacked dimensions. I imagine you will have code like:
for (i1 = $low(A, 1); i1 <= $high(A, 1); i++)
for (i2 = $low(A, 2); i2 <= $high(A, 2); i2++)
A[i1][i2] = ...
If I accidentally type:
for (i = $low(A, 11); ...
then I would like the compiler to tell me as soon as possible. If $low and
$high just return 1'bx, then my array will remain mysteriously uninitialized
and it will take a long time to figure out why.
Paul
This archive was generated by hypermail 2b28 : Mon Apr 08 2002 - 11:52:46 PDT