[m-rev.] New library module: pile

Ralph Becket rafe at cs.mu.OZ.AU
Thu Feb 6 15:28:09 AEDT 2003


Peter Moulder, Thursday,  6 February 2003:
> Mostly aesthetic things, not sent to mercury-reviews.

We wish you would!  Your review comments are invariably helpful and it's
good to keep everyone in the loop.

> > +% Deconstruction, however, is O(n) for a pile containing n members.
> 
> Suggest s/Deconstruction/Conversion to a list/.

Good point.

> > +list(T) = list_2(T, []).
> 
> I prefer using a meaningful name if a reasonable one exists.
> E.g. prepend_to_list.

In general I agree with you, but in this case it's obvious what's going
on and the name list_2 clearly indicates that this function is auxiliary
to list/1.

> > +cons(X, T) = ( if T = nil then leaf(X) else branch(leaf(X), T) ).
> 
> Suggest biasing towards storing as list (leaves):
> 
>   cons(H, nil		  ) = leaf(H).
>   cons(H, leaf(I)	  ) = leaves([H, I]).
>   cons(H, leaves(Tail)	  ) = leaves([H | Tail]).
>   cons(H, T @ branch(_, _)) = branch(leaf(H), T).
> 
> This slightly improves speed of subsequent access (esp. conversion to a
> list) when the first few operations are cons (starting from nil).

It's a good point, but on the other hand the existing code only
allocates one cell at most and performs only one comparison.

The intuition behind the pile (or whatever we call it) is that we need a
structure that is quick to build and which we will probably ultimately
convert to a list.

> > +member(X, branch(TA, _)) :-
> > +    member(X, TA).
> > +
> > +member(X, branch(_, TB)) :-
> > +    member(X, TB).
> 
> Personally I'd prefer these clauses to be merged into a disjunction.

Hmmmmm, nah!

Thanks,
	Ralph
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list