[m-users.] Inferring over dynamic data
Zoltan Somogyi
zoltan.somogyi at runbox.com
Sun Jan 23 22:50:11 AEDT 2022
2022-01-18 20:07 GMT+11:00 "Zoltan Somogyi" <zoltan.somogyi at runbox.com>:
> Example Prolog predicate that operates on these two predicates:
>
> add_new_component(Item, NewComponent) :-
> m(Item, OldComponents),
> retract(m(Item, OldComponents),
> NewComponents = [NewComponent | OldComponents],
> assert(m(Item, NewComponents)),
> assert(s(Item)).
>
> In Mercury, the direct equivalent of this code is
>
> add_new_component(Item, NewComponent, S0, S, M0, M) :-
> map.lookup(Item, OldComponents),
> NewComponents = [NewComponent | OldComponents],
> map.det_update(Item, NewComponents, M0, M),
> set.insert(Item, S0, S).
The first line of the Mercury definition has a typo, which I fear
may confuse people just learning Mercury: what now reads
map.lookup(Item, OldComponents)
should read
map.lookup(M0, Item, OldComponents)
The difference is really important, since M0 represents the current
state of the map in which the lookup is done; without it, the lookup
cannot be done.
Zoltan.
More information about the users
mailing list