[mercury-users] Request for comments on this code
Ian MacLarty
maclarty at csse.unimelb.edu.au
Tue Jul 11 11:18:02 AEST 2006
On Mon, Jul 10, 2006 at 04:39:36PM +1000, Peter Schachte wrote:
> On Sun, Jul 09, 2006 at 05:13:41PM +1000, Mark Brown wrote:
> > On 09-Jul-2006, Peter Moulder <Peter.Moulder at infotech.monash.edu.au> wrote:
> > > Mercury guarantees that
> > > the `if' goal is executed entirely before the `then' goal (modulo any
> > > backtracking).
>
> > > (I think that there was a proposal for a `&&' operator to make the above
> > > more readable; I can't remember the fate of that proposal.)
> >
> > It was deemed insufficiently useful at the time. For cases like the above,
> > the idea would be to try to make explicit the IO states that you are
> > interested in (*). So the code would look something like:
> >
> > clock(R0, !IO),
> > do_stuff(N, Q, !IO),
> > clock(R1, !IO),
>
> This is preferable to the if->then;else version, but still doesn't
> seem quite right semantically. Being pure should mean the program
> behaves deterministically, and clock doesn't. It also seems strage to
> thread the IO state through do_stuff if it doesn't do IO. A smarter
> Mercury compiler could realize the subterfuge and decide do_stuff
> couldn't affect the IO state, and neither could clock/3, and so R1 =
> R0. Better to make clock/3 impure, as Mark suggests later.
>
The better solution for custom benchmarking code like this is to use
trace goals (proposed a few months ago on mercury-developers). With
trace goals you could turn the benchmarking on or off statically or
dynamically and also the predicate whose body contains the benchmarking
code wouldn't need to be impure. Also the trace goals wouldn't get
reordered.
Ian.
--------------------------------------------------------------------------
mercury-users mailing list
post: mercury-users at csse.unimelb.edu.au
administrative address: owner-mercury-users at csse.unimelb.edu.au
unsubscribe: Address: mercury-users-request at csse.unimelb.edu.au Message: unsubscribe
subscribe: Address: mercury-users-request at csse.unimelb.edu.au Message: subscribe
--------------------------------------------------------------------------
More information about the users
mailing list