Re: [m-users.] IO argument clobbering

Volker Wysk <[email protected]>
Newsgroups gmane.comp.lang.mercury.general
Message-ID <[email protected]>
Am Montag, dem 17.07.2023 um 15:27 +0100 schrieb Sean Charles
(emacstheviking):
> Hi,

Hi there.

> 
> I am trying to pass a predicate to a rendering loop so the loop can manage
> the system but call back each frame to get the application to render its
> state.
> 
> I have this as the callback definition:
> 
> 
> :- type callback == (pred(world, world, io, io)).
> :- inst callback == (pred(in, out, di, uo) is det).
> 
> :- pred run_loop(
>     callback::in, world::in, world::out, io::di, io::uo
> ) is det.

This should be:

:- pred run_loop(
    callback::in(callback), world::in, world::out, io::di, io::uo
) is det.

You need a higher order inst, when you want to call a variable as a
predicate.


> My call site code looks like this, nothing spectacular:
> 
> :- pred app_loop(world::in, world::out, io::di, io::uo) is det.
> 
> app_loop(!W, !IO) :-
>  % do stuff
>  .
> 
> The game loop set up and call is this:
> 
>     mk_world(60, World, !IO),
>     run_loop(app_loop, World, _, !IO),
>     close_window(!IO).
> 
> The idea was that, at that point, the 'control' of the application is
> managed by my emerging framework, dare I call it that, and I wanted to be
> able to pass in various callbacks, starting with basic frame rendering,
> the implementation code is this:
> 
> run_loop(AppHandler, !W, !IO) :-
>     window_should_close(X, !IO),
>     (
>         X = yes,
>         trace_info("Stopped by user", [], !IO)
>     ;
>         X = no,
>            :
>            :
>         %%%%%%%%%%
>         % RENDER %
>         %%%%%%%%%%
>         begin_drawing(!IO),
> 193:        AppHandler(!W, !IO),
> 194:    end_drawing(!IO),
> 195:
> 196:    run_loop(AppHandler, !W, !IO)
>     ).
> 
> The compiler error centres around line 196, which I wasn't expecting, of
> course!
> 
> ui.m:196: In clause for `run_loop(in, in, out, di, uo)':
> ui.m:196:   mode error in conjunction. The next 3 error messages indicate
> ui.m:196:   possible causes of this error.
> ui.m:196:   
> ui.m:193:   In clause for `run_loop(in, in, out, di, uo)':
> ui.m:193:   in argument 1 (i.e. the predicate term) of higher-order
> predicate
> ui.m:193:   call:
> ui.m:193:   mode error: variable `AppHandler' has instantiatedness
> `ground',
> ui.m:193:   expecting higher-order pred inst of arity 4.
> ui.m:196:   
> ui.m:194:   In clause for `run_loop(in, in, out, di, uo)':
> ui.m:194:   in argument 1 of call to predicate `raylib.end_drawing'/2:
> ui.m:194:   unique-mode error: the called procedure would clobber its
> argument,
> ui.m:194:   but variable `STATE_VARIABLE_IO_29' is still live.
> ui.m:196:   
> ui.m:196:   In clause for `run_loop(in, in, out, di, uo)':
> ui.m:196:   in argument 4 of call to predicate `ui.run_loop'/5:
> ui.m:196:   unique-mode error: the called procedure would clobber its
> argument,
> ui.m:196:   but variable `STATE_VARIABLE_IO_30' is still live.
> 
> 
> I don't understand what it means by 'still live'. I am threading the !IO
> world state through this run loop, passing it into the callback code, but
> on the tail-back into the next iteration, well, I don't understand what
> the actual issue is.
> 
> Seeking explanation!


Cheers,
Volker

_______________________________________________
users mailing list
[email protected]
https://lists.mercurylang.org/listinfo/users
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEE6QXGh82Ov3+2nrxp+K4ydFOsHoUFAmS1Uj8ACgkQ+K4ydFOs
HoWJ/xAAoxTIjaW74S6Ft8Mkz/6IEaPLuS0q7QcF9LcIMI5xFgrna1qycG44seSr
rwXBPu4Vi0u3oekMqCaPRFQ5KjULoyoaRsS+fMg1V1eRl9+DKAItemi621pxH1Om
sacLB4Mi8Wia/I7P+QUBzKpFrlQ7dVp7o0GIPi/FF1x8eeYlKS7pfMxVEpPG4Yda
ZPHsMdORcC6PlP+J2cgUsuedrOg3jQ+QnFrONauYjqICc2GBRIP9yYfGv+0uJg3p
/p9xRuAqLo5p0lwq4DPqCvWAJc92PPSCLIiCPI6KGHqyRQHP0ISMGrLDqqF49SHl
zGRKswX/Wu7EoabOX9S5VhJQLbnE34HQUkdeK35s8Uh2/fYdQJfiQvrcq4uL2Agz
/1yaBa1GZPIPsnhvFS9r4zVYKANX8Czkqffi0ApjezxHPB9U3hWz3AeGbRybKbwV
XLd4UAmDlI1Ms2+IM3+WGjPmVtgYqyudmrCsjZnuOtW+KfJrbEBeemYIfiTwUbzX
kz4rC6epSKXUF9N1s+JjQPZadty/d98panTTA2CmVuETqxKAFBxygv1LC+QKV9GL
WlNCyj5ifhVnQrSuHm8X9e+50Ugw1l1XzMUn9MPcj9IkfkJN38d6m+E6601nfGdI
7dLfsSubcIAMA/3jCNXdAkK0CnbtjtUZSqLvHmML20jPcSGQqII=
=EHDY
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.