[mercury-users] Safe use of uninitialised arrays
Peter Schachte
schachte at cs.mu.OZ.AU
Fri Jan 21 12:27:48 AEDT 2000
On Wed, Jan 19, 2000 at 10:23:59AM -0800, Ralph Becket wrote:
> Efficiency question. It's often the case that one
> creates an array and then fills in every slot.
> However, the current array library insists that
> the programmer provides a value with which to
> initialise every element before delivering the new
> array. Now I think this is good practice in general,
> but there are places where you just don't want the
> overhead. In much the same way as one is prepared
> to take the consequences by compiling with array
> bounds checking disabled, I'd like to have something
> like
>
> :- func array__unsafe_init_uninitialised(int) = array(T).
Of course, that'd have to be cc_multi.
> Alternatively, I'd be almost as happy with being able
> to supply an initialising predicate, e.g.
>
> :- pred array__init_from_fn(
> int, % array size
> pred(T2, T2, T1), % `generating function'
> T2, % `seed value'
> T2, % `final value'
> array(T1)
> ).
This sounds reasonable. You'd probably want the closure to take one
more argument, though: the array index. Sure, you could keep track of
that yourself in the two arguments you're threading through your
closure, but since the init_from_fn predicate keeps track of this
already, why should you?
I wonder, though, whether the overhead of higher-order calls would
outweigh the savings from not redundantly intializing the array?
--
Peter Schachte I don't believe in collective guilt, but
mailto:schachte at cs.mu.OZ.AU I do believe in collective responsibility.
http://www.cs.mu.oz.au/~schachte/ -- Audrey Hepburn
PGP: finger schachte at 128.250.37.3
--------------------------------------------------------------------------
mercury-users mailing list
post: mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the users
mailing list