<html><head><meta http-equiv="content-type" content="text/html; charset=us-ascii"></head><body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;">Mark, Zoltan, thanksz for your time.<div><br></div><div>Mark, your solution seems a good one for me.</div><div><br></div><div>I also later saw thaqt as the module mutable initialisation occursa before I call my explicit lo\ad, that in fact it was never going to work as I had though anyway!</div><div><br></div><div>Zoltan, case "A" is me: one time init. of fonts, for lifetime of application then unload and quit on user command.</div><div><br></div><div>I do recall at least one or two instances in the manuals about the penalty for "lying to the compiler" !</div><div><br></div><div>So, I shall use the same techniques I used inmy POC video space shooter game and make sure I never lie to the compiler, after all, it's got my back!</div><div><br></div><div>Thanks all.</div><div>Happy belated 2025 too.</div><div><br></div><div>My 6th year begind as a Mercury user IIRC.<br id="lineBreakAtBeginningOfMessage"><div><br><blockquote type="cite"><div>On 16 Feb 2025, at 11:38, Sean Charles (emacstheviking) <objitsu@gmail.com> wrote:</div><br class="Apple-interchange-newline"><div><meta http-equiv="content-type" content="text/html; charset=us-ascii"><div style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;">Hello,<div><br></div><div>I have a not insignificant binding to Raylib now, and during a recent bit of experimental coding, I decided on trying a different way to manage assets, in this case fonts.</div><div><br></div><div><div><font face="CutiveMono-Regular">:- import_module raylib.</font></div><div><span style="font-family: CutiveMono-Regular;">:- type font_state</span></div><div><font face="CutiveMono-Regular">    --->    font_state(</font></div><div><font face="CutiveMono-Regular">                default :: rfont,</font></div><div><font face="CutiveMono-Regular">                main    :: rfont</font></div><div><font face="CutiveMono-Regular">            ).</font></div></div><div><span style="font-family: CutiveMono-Regular;">:- mutable(fstate, maybe(font_state), no, ground, [untrailed]).</span></div><div><br></div><div>I am forced to initialise to `no` because until the Raylib library is initialised, loading fonts doesn't work, however, I have experimented with a second version of load_font in my binding that does not use !IO:</div><div><br></div><div><div><font face="CutiveMono-Regular">   1162</font></div><div><font face="CutiveMono-Regular">   1163 :- pragma foreign_proc(</font></div><div><font face="CutiveMono-Regular">   1164     "C", load_font2(FontName::in, Out::out),</font></div><div><font face="CutiveMono-Regular">   1165     [ promise_pure, will_not_call_mercury, will_not_throw_exception</font></div><div><font face="CutiveMono-Regular">   1166     , will_not_modify_trail, thread_safe, does_not_affect_liveness</font></div><div><font face="CutiveMono-Regular">   1167     ],</font></div><div><font face="CutiveMono-Regular">   1168     "</font></div><div><font face="CutiveMono-Regular">   1169         void* p = MR_GC_malloc_uncollectable(sizeof(Font));</font></div><div><font face="CutiveMono-Regular">   1170         Out = p;</font></div><div><font face="CutiveMono-Regular">   1171         Font font = LoadFont(FontName);</font></div><div><font face="CutiveMono-Regular">   1172         memcpy(p, &font, sizeof(Font));</font></div><div><font face="CutiveMono-Regular">   1173     ").</font></div></div><div><br></div><div>They both work, and it means that I can now load fonts by adding an initialise call to the module and then loading fonts without having an !IO context. I think I might change the mutable to be a `univ` on the grounds that after module initialisation, I know it will contain a fully populated `font_state`. I envisaged the new call looking something like this:</div><div><br></div><div><div><span style="font-family: CutiveMono-Regular;">:- mutable(fstate, font_state,</span></div><div><span style="font-family: CutiveMono-Regular;">       font_state(</span></div><div><span style="font-family: CutiveMono-Regular;">           load_default_font,</span></div><div><span style="font-family: CutiveMono-Regular;">           load_a_font("path/to/main/font.ttf")</span></div><div><span style="font-family: CutiveMono-Regular;">       ),</span></div><div><span style="font-family: CutiveMono-Regular;">       ground,</span></div><div><span style="font-family: CutiveMono-Regular;">       [untrailed]</span></div><div><span style="font-family: CutiveMono-Regular;">).</span></div></div><div><span style="font-family: CutiveMono-Regular;"><br></span></div><div><font face=".SF NS">...but I would have to write a function shim as well</font></div><div><font face=".SF NS"><br></font></div><div><font face="CutiveMono-Regular">:- func load_a_font(string::in) = (rfont::out) is det.</font></div><div><font face="CutiveMono-Regular">load_a_font(Path) = F :-</font></div><div><font face="CutiveMono-Regular">    load_font(Path, F).  % No !IO context!</font></div><div><span style="font-family: CutiveMono-Regular;"><br></span></div><div><span style="font-family: CutiveMono-Regular;"><br></span></div><div>Sorry for rambling thus far, but my question is this: if I remove "!IO" from all of my binding to Raylib, what price might I pay in my code? The Raylib environment is hidden inside the library, any allocations it does are not known to Mercury, so what possible problems might I face if Mercury sees the same bunch of `det` calls but they don't need IO state in and out? Is that "lying" to Mercury in such a way as it could cause subtle issues, I am writing an IDE so it's a non-trivial project.</div><div><br></div><div>Or should I only remove IO from the asset loading functions?</div><div><br></div><div>I am just looking for ideas / advice etc on how to proceed such that I don;t inadvertently cause myself issues by lying to the compiler.</div><div><br></div><div>Thanks,</div><div>Sean.</div><div><br></div></div></div></blockquote></div><br></div></body></html>