<div dir="ltr">OK, my "game" is progressing and I want to deal with the SDL events in the main event / render loop.<div>The event loop checks for a single SDL event like so:<br></div><div><div style="color:rgb(48,48,48);font-size:12px;line-height:16px;white-space:pre"><br><div><span style="color:rgb(0,128,0)">    %--------------------------------------------------------------------------</span></div><div><span style="color:rgb(0,128,0)">    %</span></div><div><span style="color:rgb(0,128,0)">    % Event Loop</span></div><div><span style="color:rgb(0,128,0)">    %</span></div><div><span style="color:rgb(100,100,100)">:-</span><span style="color:rgb(0,0,255)"> pred</span> event_loop<span style="color:rgb(100,100,100)">(</span>app_state<span style="color:rgb(100,100,100)">::</span>in<span style="color:rgb(100,100,100)">,</span> app_state<span style="color:rgb(100,100,100)">::</span>out<span style="color:rgb(100,100,100)">,</span> bool<span style="color:rgb(100,100,100)">::</span>out<span style="color:rgb(100,100,100)">,</span> io<span style="color:rgb(100,100,100)">::</span>di<span style="color:rgb(100,100,100)">,</span> io<span style="color:rgb(100,100,100)">::</span>uo<span style="color:rgb(100,100,100)">)</span> <span style="color:rgb(0,0,255)">is</span> <span style="color:rgb(0,0,255)">det</span><span style="color:rgb(100,100,100)">.</span></div><br><div>event_loop<span style="color:rgb(100,100,100)">(</span>Ain<span style="color:rgb(100,100,100)">,</span> Aout<span style="color:rgb(100,100,100)">,</span> Quit<span style="color:rgb(100,100,100)">,</span> <span style="color:rgb(100,100,100)">!</span>IO<span style="color:rgb(100,100,100)">)</span> <span style="color:rgb(100,100,100)">:-</span></div><div>    sdl_pollevent<span style="color:rgb(100,100,100)">(</span>MEv<span style="color:rgb(100,100,100)">,</span> <span style="color:rgb(100,100,100)">!</span>IO<span style="color:rgb(100,100,100)">),</span></div><div>    <span style="color:rgb(100,100,100)">(</span></div><div>        MEv  <span style="color:rgb(100,100,100)">=</span> <span style="color:rgb(0,0,255)">no</span><span style="color:rgb(100,100,100)">,</span></div><div>        Quit <span style="color:rgb(100,100,100)">=</span> <span style="color:rgb(0,0,255)">no</span><span style="color:rgb(100,100,100)">,</span></div><div>        Ain  <span style="color:rgb(100,100,100)">=</span> Aout</div><div>    <span style="color:rgb(100,100,100)">;</span></div><div>        MEv <span style="color:rgb(100,100,100)">=</span> <span style="color:rgb(0,0,255)">yes</span><span style="color:rgb(100,100,100)">(</span>Event<span style="color:rgb(100,100,100)">),</span></div><div>        <span style="color:rgb(100,100,100)">(</span></div><div>            if                Event <span style="color:rgb(100,100,100)">=</span> quit_event</div><div>            then          Ain   <span style="color:rgb(100,100,100)">=</span> Aout<span style="color:rgb(100,100,100)">,</span></div><div>                Quit  <span style="color:rgb(100,100,100)">=</span> <span style="color:rgb(0,0,255)">yes</span></div><div>            else</div><div>                handle_event<span style="color:rgb(100,100,100)">(</span>Event<span style="color:rgb(100,100,100)">,</span> Ain<span style="color:rgb(100,100,100)">,</span> Aout<span style="color:rgb(100,100,100)">,</span> <span style="color:rgb(100,100,100)">!</span>IO<span style="color:rgb(100,100,100)">),</span></div><div>                Quit  <span style="color:rgb(100,100,100)">=</span> <span style="color:rgb(0,0,255)">no</span></div><div>        <span style="color:rgb(100,100,100)">)</span></div><div>    <span style="color:rgb(100,100,100)">).</span></div><br>And here is the individual event processing.</div><div style="color:rgb(48,48,48);font-size:12px;line-height:16px;white-space:pre"><br><div><span style="color:rgb(0,128,0)">    %--------------------------------------------------------------------------</span></div><div><span style="color:rgb(0,128,0)">    %</span></div><div><span style="color:rgb(0,128,0)">    % HandleA Single Event</span></div><div><span style="color:rgb(0,128,0)">    %</span></div><div><span style="color:rgb(100,100,100)">:-</span><span style="color:rgb(0,0,255)"> pred</span> handle_event<span style="color:rgb(100,100,100)">(</span>sdl_event<span style="color:rgb(100,100,100)">::</span>in<span style="color:rgb(100,100,100)">,</span> app_state<span style="color:rgb(100,100,100)">::</span>in<span style="color:rgb(100,100,100)">,</span> app_state<span style="color:rgb(100,100,100)">::</span>out<span style="color:rgb(100,100,100)">,</span> io<span style="color:rgb(100,100,100)">::</span>di<span style="color:rgb(100,100,100)">,</span> io<span style="color:rgb(100,100,100)">::</span>uo<span style="color:rgb(100,100,100)">)</span> <span style="color:rgb(0,0,255)">is</span> <span style="color:rgb(0,0,255)">det</span><span style="color:rgb(100,100,100)">.</span></div><br><div>handle_event<span style="color:rgb(100,100,100)">(</span>E<span style="color:rgb(100,100,100)">,</span> A<span style="color:rgb(100,100,100)">,</span> A<span style="color:rgb(100,100,100)">,</span> <span style="color:rgb(100,100,100)">!</span>IO<span style="color:rgb(100,100,100)">)</span> <span style="color:rgb(100,100,100)">:-</span></div><div>    <span style="color:rgb(100,100,100)">(</span> if E <span style="color:rgb(100,100,100)">=</span> key_up<span style="color:rgb(100,100,100)">(</span>_A<span style="color:rgb(100,100,100)">,</span> _B<span style="color:rgb(100,100,100)">)</span> then</div><div>        format<span style="color:rgb(100,100,100)">(</span><span style="color:rgb(163,21,21)">"keyup:\n"</span><span style="color:rgb(100,100,100)">,</span> <span style="color:rgb(100,100,100)">[],</span> <span style="color:rgb(100,100,100)">!</span>IO<span style="color:rgb(100,100,100)">)</span></div><br><div>    else if E <span style="color:rgb(100,100,100)">=</span> filedrop_event<span style="color:rgb(100,100,100)">(</span>F<span style="color:rgb(100,100,100)">)</span> then</div><div>        format<span style="color:rgb(100,100,100)">(</span><span style="color:rgb(163,21,21)">"File drop: %s\n"</span><span style="color:rgb(100,100,100)">,</span> <span style="color:rgb(100,100,100)">[</span>s<span style="color:rgb(100,100,100)">(</span>F<span style="color:rgb(100,100,100)">)],</span> <span style="color:rgb(100,100,100)">!</span>IO<span style="color:rgb(100,100,100)">)</span></div><div style="color:rgb(48,48,48);font-size:12px;line-height:16px;white-space:pre"><br></div>   % ... more if then else checks as events are added <br><div>    else</div><div>        format<span style="color:rgb(100,100,100)">(</span><span style="color:rgb(163,21,21)">"dont care:\n"</span><span style="color:rgb(100,100,100)">,</span> <span style="color:rgb(100,100,100)">[],</span> <span style="color:rgb(100,100,100)">!</span>IO<span style="color:rgb(100,100,100)">)</span></div><div>    <span style="color:rgb(100,100,100)">).</span></div></div></div><div><br></div><div>Every time I use multiple predicates with (_,..) as the event it says I have multiple solutions but then I tried to make handle_event cc_multi as there can be only one event at a time and it can only be one type of event. I guess I am just confused trying to implement some kind of event handler that grows as I need it and doesn't want to have code for all possible eventualites right from the start as I don't know what events I want to process yet!</div><div><br></div><div>So, is the if-then-else the only way of creating a "det" predicate that effectively swallows the multiple solutions into a deterministic bucket ?</div><div><br></div><div>I am probably doing this all the wrong way!</div><div><br></div><div><br></div></div>