[m-rev.] Minor addition to string.m
Fergus Henderson
fjh at cs.mu.OZ.AU
Fri Jan 31 15:51:27 AEDT 2003
On 31-Jan-2003, Ralph Becket <rafe at cs.mu.OZ.AU> wrote:
> Peter Moulder, Thursday, 30 January 2003:
> >
> > In perl, chomp removes no more than one newline. E.g. "foo\n\n" -> "foo\n".
> > If the name `chomp' is retained, then I think the previously-posted
> > behaviour/implementation should be used.
>
> I considered this. I'm not sure the difference would be significant
> since it's almost certain only to be used to snip off the "\n" after
> a call to read_line_as_string. I will change it to snip off just the
> one if anybody feels strongly.
I agree with Peter Moulder on this one. If we're going to reuse the
Perl name, then we should use the same semantics.
> > On a similar vein, can use
> >
> > ( if I < N then
> > ( if P(S ^ unsafe_elem(I)) then ... else I )
> > else
> > I
> > ).
>
> I've applied the s/elem/unsafe_elem/ suggestion. I don't think adding
> the extra if-then-else makes the code any more readable.
I agree about the readability, but making the s/elem/unsafe_elem/ change
on its own is not acceptable, because Mercury's commutative optional
semantics does not guarantee that the code will work -- the range
check might get reordered to occur after the call to unsafe_elem.
(That is, presuming I understood what you meant. Since you didn't post
the revised diff, it's difficult to be sure.)
> The existing
> formulation, I < N, P(S ^ unsafe_elem(I)) works fine with the current
> compiler,
Are you sure? With every possible combination of compiler options?
Have you tested them all?
Even if it does happen to work, it would still be a latent bug,
just waiting to be triggered by the next compiler optimization
that someone adds.
> but the correct solution is for us to add an explicit ordered
> conjunction which would forbid the reordering of its conjuncts for any
> reason.
I agree that adding a sequential conjunction operator would be a good
extension. However, that doesn't justify writing broken code in the
mean time.
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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