<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Zoltan, Julien,<div class=""><br class=""></div><div class="">Thank you for your replies. I don’t think my application will remain ’small’ going forward but the one mitigating feature is that the values I want to save into the IO state are never going to change; they are the option_table values from a successful call to getopt, i.e. one where there were no unrecognised options and none that required immediate service and then termination e.g. help / version / list targets.</div><div class=""><br class=""></div><div class="">Excellent then, I shall happily save my constant data into IO state and see how it goes.</div><div class=""><br class=""></div><div class="">I do have one error I cannot figure out yet… I attempted to re-code my ‘debug_on’ predicate to use IO instead of the Options and I get an error I cannot yet figure out ( again :| )…</div><div class=""><br class=""></div><div class="">The exports:</div><div class=""><br class=""></div><div class=""><div style="color: rgb(36, 41, 46); background-color: rgb(199, 237, 204); font-size: 12px; line-height: 18px; white-space: pre;" class=""><div class=""><span style="color: #000000;" class="">:-</span><span style="color: #0000ff;" class=""> func</span> debug_on<span style="color: #000000;" class="">(</span>felt_options<span style="color: #000000;" class="">)</span> <span style="color: #000000;" class="">=</span> bool<span style="color: #000000;" class="">.</span></div><div class=""><span style="color: #000000;" class="">:-</span><span style="color: #0000ff;" class=""> func</span> debug_on<span style="color: #000000;" class="">(</span>io<span style="color: #000000;" class="">::</span>di<span style="color: #000000;" class="">,</span> io<span style="color: #000000;" class="">::</span>uo<span style="color: #000000;" class="">)</span> <span style="color: #000000;" class="">=</span> bool<span style="color: #000000;" class="">.   % LINE 28, see error message below.</span></div><br class=""></div><div><br class=""></div><div>and the code:</div><div><br class=""></div><div><div style="color: rgb(36, 41, 46); background-color: rgb(199, 237, 204); font-size: 12px; line-height: 18px; white-space: pre;" class=""><div class=""><span style="color: #008000;" class="">    % helper: is debug_mode on or off ?</span></div><div class=""><span style="color: #008000;" class="">    %</span></div><div class="">debug_on<span style="color: #000000;" class="">(</span>Options<span style="color: #000000;" class="">)</span> <span style="color: #000000;" class="">=</span> Mode <span style="color: #000000;" class="">:-</span></div><div class="">    Mode <span style="color: #000000;" class="">=</span> getopt.lookup_bool_option<span style="color: #000000;" class="">(</span>Options<span style="color: #000000;" class="">,</span> options.debug_mode<span style="color: #000000;" class="">).</span></div><br class=""><div class="">debug_on<span style="color: #000000;" class="">(!</span>IO<span style="color: #000000;" class="">)</span> <span style="color: #000000;" class="">=</span> Mode <span style="color: #000000;" class="">:-</span></div><div class="">    io.get_globals<span style="color: #000000;" class="">(</span>Options<span style="color: #000000;" class="">,</span> <span style="color: #000000;" class="">!</span>IO<span style="color: #000000;" class="">),</span></div><div class="">    Mode <span style="color: #000000;" class="">=</span> getopt.lookup_bool_option<span style="color: #000000;" class="">(</span>Options<span style="color: #000000;" class="">,</span> options.debug_mode<span style="color: #000000;" class="">).</span></div><br class=""></div></div><div><br class=""></div><div>and I get the error message:</div><div><br class=""></div><div><div>➜  f2 git:(develop) ✗ make</div><div>mmc -s hlc.gc -O4 -E --make felt</div><div>Making Mercury/int3s/options.int3</div><div>options.m:028: Error: some but not all arguments have modes.</div><div>options.m:028:   The argument without a mode is the return value.</div><div>** Error making `Mercury/int3s/options.int3'.</div><div>make: *** [felt] Error 1</div><div><br class=""></div><div><br class=""></div><div>Help! I am confused because it looks identical to the declaration on the previous line except it uses IO not the option_table...</div><div><br class=""></div></div><div><br class=""></div><div><br class=""></div><div><br class=""><blockquote type="cite" class=""><div class="">On 26 Apr 2021, at 07:36, Zoltan Somogyi <<a href="mailto:zoltan.somogyi@runbox.com" class="">zoltan.somogyi@runbox.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class=""><br class=""><br class="">On Mon, 26 Apr 2021 07:16:52 +0100, "Sean Charles (emacstheviking)" <<a href="mailto:objitsu@gmail.com" class="">objitsu@gmail.com</a>> wrote:<br class=""><blockquote type="cite" class="">Is it a —wise— idea to consider using globals on the IO State?<br class=""></blockquote><br class="">We initially thought so, and wrote the compiler that way.<br class=""><br class="">We later realized that beyond a certain complexity, it was simply<br class="">less error-prone to pass the globals explicitly to every part of the code<br class="">that needed it, even though it required writing more code.<br class="">The compiler now consistently passes the globals *separately*<br class="">from the I/O state, except maybe in the very initial startup code.<br class="">(I don't know for sure, I haven't looked at that code in a long time.)<br class=""><br class="">The problem with consistently storing the globals in the I/O state<br class="">is debugging. When you are looking at a call that updates the<br class="">I/O state, you cannot be certain whether that call also updated<br class="">the globals, unless you inspect both the callee *and its entire<br class="">call tree*. In a small program, that is not too much of a burden;<br class="">in a large program, it is. Getting such things wrong can cause bugs<br class="">that are annoyingly hard to track down. Writing explicit code<br class="">to pass the globals is a tiny bit of extra work in the usual case,<br class="">but can save a lot unpleasant debugging.<br class=""><br class="">So the answer to your question is: if you are sure that your program<br class="">will always remain small, then yes; otherwise, no.<br class=""><br class="">Zoltan.<br class=""><br class=""></div></div></blockquote></div><br class=""></div></body></html>