[mercury-users] Conditional compilation
    Zoltan Somogyi 
    zs at cs.mu.OZ.AU
       
    Tue Aug 16 17:10:30 AEST 2005
    
    
  
On 16-Aug-2005, Peter Hawkins <peter at hawkins.emu.id.au> wrote:
> :- pred debugging is semidet.
> debugging :- semidet_fail.
> or
> debugging :- semidet_succeed.
> 
> main(!IO) :-
>    (if debugging then
>       do stuff
>     else
>       true
>    )
> 
> Unfortunately the mercury compiler doesn't optimize away the 
> if-then-else, even if I add a :- pragma inline to the debugging 
> predicate.
That's because the compiler doesn't know that semidet_fail always fails
and semidet_succeed always succeeds; if it did, that would undo a large
part of their usefulness.
You can get what you want with
	:- func debugging = bool.
	debugging = yes.		% or no
 	main(!IO) :-
		Debugging = debugging,
		(
			Debugging = yes,
			do stuff
		;
			Debugging = no
		).
This is probably easier than Ralph's suggestion. If the optimization level
is high enough to invoke inlining, Mercury will delete the unreachable arm
of the switch.
Zoltan.
--------------------------------------------------------------------------
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