Good morning,
Here's a few questions about working with arrays and other
miscellaneous things.
1. What does the declaration of an array as a return type look like?
'proc p() : [] int { }' doesn't seem to work, but you can leave
off the type in the declaration and do 'return arrayvar;' and
that gets figured out.
2. Is this a wise thing to do? Can you return an array that's been
created in a sub-routine?
We had thought about doing was get a list of results from one
sub-routine, where the number wasn't known in advance, for
processing by another. The code might look like
var matches : [] 2*(2*int);
matches = find_matching_points(pts1, pts2);
where find_matching_points counts the number of matches, creates
an array to hold them, and then copies the matches into the result
before returning it. We weren't sure if this would work, though,
and took another approach.
3. It seems to be a bad idea to put arrays inside records that are
passed as arguments, because of the pass-by-value behavior. Is
this a fair statement, or should it be safe?
One sub-routine used an inout intent on a record with arrays that
it populated. It would cause the program to segfault or die with
a nil dereference about half the time. Changing the argument to
an array of records, and also passing an index into the array,
was stable (because the array is passed by reference, so it gives
you access to the arrays inside the record without copying them?).
4. The spec says that reference assignment for records is under
discussion (p. 135). Does this also apply to a ref intent for a
record argument?
5. The spec (p. 170) says that domain.exterior(), interior(), and
translate() can take a single integer argument, but this causes
a compilation error.
const dom : domain(rank=2) = { 1..10, 1..10 };
writeln("exterior(2,2) ", dom.exterior(2,2));
writeln("exterior(2) ", dom.exterior(2));
The first call is accepted, the second produces
> ex_domain.chpl:5 error: unresolved call 'domain(2,
int(64).false).exterior(2)'
> $CHPL_HOME/modules/internal/ChapelRange.chpl:559: note:
candidates are: range.exterior(i: idxType)
> $CHPL_HOME/modules/internal/ChapelRange.chpl:565: note:
range.exterior(i: idxType)
> $CHPL_HOME/modules/internal/ChapelArray.chpl:971: note:
_domain.exterior(off: rank*_value.idxType)
> $CHPL_HOME/modules/internal/ChapelArray.chpl:981: note:
_domain.exterior(off: _value.idxType ...rank)
> $CHPL_HOME/modules/internal/ChapelArray.chpl:982: note:
_domain.exterior(off: rank*_value.idxType)
6. Many of the internal and standard modules use the low and high
members of ranges. It seems that first and last would be safer
if the step size or alignment caused them not to hit low/high
exactly. Would it be a best practice to use first/last, or is
the worry unfounded?
Thanks for your time answering these!
Greg
------------------------------------------------------------------------------
_______________________________________________
Chapel-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-users