[m-dev.] a conditional field update operator

Paul Bone paul at bone.id.au
Wed Mar 8 16:02:11 AEDT 2017


On Wed, Mar 08, 2017 at 02:41:19PM +1100, Zoltan Somogyi wrote:
> One of the changes I made to simplify_info operations was to
> replace code like this:
> 
> simplify_info_set_varset(X, !Info) :-
>     !Info ^ simp_varset := X.
> 
> with code like this:
> 
> simplify_info_set_varset(X, !Info) :-
>    ( if private_builtin.pointer_equal(X, !.Info ^ simp_varset) then
>        true
>    else
>        !Info ^ simp_varset := X
>    ).
> 
> Do people think such an extension to field syntax would be useful
> more generally than just in the Mercury compiler? If so, what should
> the syntax be?

Depending on the code that creates the new value (X), it might be more
appropriate to use a normal equality test.  It probably makes sense to
support both equality tests.

Since this would be very rarely used I'd hesitate to give it a
symbol/operator.  I'd prefer to give it a name, it may make it more awkward
to use but it's an operator that can be defined for something else later (if
necessary).

    update_field_if_not_pointer_equal(!Info ^ simp_varset, X),

Hrm, it's a mouthful, just an idea.


-- 
Paul Bone
http://paul.bone.id.au


More information about the developers mailing list