[m-users.] Mercury for Game AI

David Epstein davideps at umich.edu
Mon Jan 24 21:00:40 AEDT 2022


Thank you M. McDonough & Zoltan.

On Mon, Jan 24, 2022 at 11:41 AM Zoltan Somogyi <zoltan.somogyi at runbox.com>
wrote:

>
> 2022-01-24 09:19 GMT+11:00 "M McDonough" <foolkingcrown at gmail.com>:
> > % I'm putting `dead` as its own functor since it precludes status.
> > % This can also make it easier/nicer when using rules for semidet preds.
> > % Probably use a 'status' type instead of bools, but for illustration:
> > :- type person ---> dead ; alive(awake::bool.bool, free::bool.bool).
>
> I agree with all this advice, but I would also add a further note,
> which is that I would replace the bools here with purpose-specific types.
>
> With the above type definition, it is too easy to write code such as
> Bob = alive(Free, Awake), when the two args should be the other way around.
>
> With the definitions
>
> :- type maybe_awake ---> not_awake ; is_awake.
> :- type maybe_free ---> not_free ; is_free.
> :- type person ---> dead ; alive(awake::maybe_awake, free::maybe_free).
>
> writing Bob = alive(Free, Awake) is guaranteed to be caught the compiler.
>
> This requires a minimal amount of extra effort, and that effort will be
> paid back
> at least a hundredfold the first time the compiler tells you exactly where
> you
> mixed up values of two of these types *without* you having to track the
> bug down
> in the debugger.
>
> Zoltan.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/users/attachments/20220124/e465b69d/attachment.html>


More information about the users mailing list