<div dir="ltr">You can use if then else to make it det.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, 5 Jul 2019 at 09:10, emacstheviking <<a href="mailto:objitsu@gmail.com">objitsu@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Spoke too soon! FUll source and error output....it's beyond my little bear brain this time of night...I thought that by declaring char_type as cc_multi the compiler would NOT think it would have multiple solutions as I committed to the first one as the only solution?!?!<div><br></div><div><font face="courier new, monospace">fl1.m:020: In `char_loop'(di, uo):<br>fl1.m:020: error: determinism declaration not satisfied.<br>fl1.m:020: Declared `det', inferred `multi'.<br>fl1.m:027: Call to `fl1.char_type'(in, out) can succeed more than once.<br>fl1.m:027: Error: call to predicate `fl1.char_type'/2 with determinism<br>fl1.m:027: `cc_multi' occurs in a context which requires all solutions.<br>** Error making `Mercury/cs/fl1.c'.<br></font></div><div><br></div><div>and the code</div><div><br></div><div> :- pred char_loop(io::di, io::uo) is det.<br> char_loop(!IO) :-<br> read_char(C, !IO),<br> (<br> C = eof<br> ;<br> C = ok(C2),<br> char_type(C2, CType),<br> chartype_s(CType, CTypeStr),<br> format("%c %d %s\n", [c(C2), i(char.to_int(C2)), s(CTypeStr)], !IO),<br> char_loop(!IO)<br> ;<br> C = error(ErrorCode),<br> io.format("%s...\n", [s(io.error_message(ErrorCode))], !IO)<br> ).<br><br>:- type chartype<br> ---> p_open<br> ; p_close<br> ; c_general.<br><br>:- pred char_type(char::in, chartype::out) is cc_multi.<br>char_type(')', p_open).<br>char_type('(', p_close).<br>char_type(_, c_general).<br><br>:- pred chartype_s(chartype::in, string::out) is det.<br>chartype_s(p_open, "general").<br>chartype_s(p_close, "popen").<br>chartype_s(c_general, "pclose").<br></div><div><br></div><div>Going to sleep on it...</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, 4 Jul 2019 at 23:46, emacstheviking <<a href="mailto:objitsu@gmail.com" target="_blank">objitsu@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Thanks Richard!</div><div><br></div>That is so obvious when you see it. I am thinking like a Haskell hacker this evening for sure.<div>I changed it to "cc_multi" and it compiled ANd did what I expected / wanted.</div><div><br></div><div>In my prolog code I have a cut after each match to commit (cc_multi!!!) to that and no more....OMG (trust me I have to be desparate to even think that acronym) it really does match !!! I am going to stick that response on a post-it under my monitor for a whole month!</div><div><br></div><div>Currently re-reading section 6 of the manual...sigh...these are the times when I just know that a formal education might have helped me stumble and fall a little less.</div><div><br></div><div>Thanks again,</div><div>Sean.</div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, 4 Jul 2019 at 23:40, Richard O'Keefe <<a href="mailto:raoknz@gmail.com" target="_blank">raoknz@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-family:monospace,monospace"><span style="font-family:Arial,Helvetica,sans-serif">char_type(')', p_open).</span><br style="font-family:Arial,Helvetica,sans-serif"><span style="font-family:Arial,Helvetica,sans-serif">char_type('(', p_close).</span><br style="font-family:Arial,Helvetica,sans-serif"><span style="font-family:Arial,Helvetica,sans-serif">char_type(_, c_general).</span><br></div><div class="gmail_default" style="font-family:monospace,monospace"><span style="font-family:Arial,Helvetica,sans-serif"><br></span></div><div class="gmail_default" style="font-family:monospace,monospace"><span style="font-family:Arial,Helvetica,sans-serif">')' matches two clauses, the first and last.</span></div><div class="gmail_default" style="font-family:monospace,monospace"><span style="font-family:Arial,Helvetica,sans-serif">'(' matches two clauses, the second and last.</span></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, 5 Jul 2019 at 10:24, emacstheviking <<a href="mailto:objitsu@gmail.com" target="_blank">objitsu@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">To paraphrase Neo, "I know Prolog".<div><br></div><div>but I don't know Mercury and I am struggling to figure out this error....I am porting some old SWI code and it boils down to the fact that I obvuisly don't truly understand what "det" means! Here is the code both as discrete disjunctive clauses and a single big disjunct:</div><div><br></div><div>:- pred char_type(char::in, chartype::out) is det.<br><br></div><div>char_type(')', p_open).<br>char_type('(', p_close).<br>char_type(_, c_general).<br><br>char_type(C, T) :-<br> (<br> C = '(', T = p_open<br> ; C = ')', T = p_close<br> ; C = _, T = c_general<br> ).<br></div><div><br></div><div>and here is the compiler output:</div><div><br></div><div>fl1.m:049: In `char_type'(in, out):<br>fl1.m:049: error: determinism declaration not satisfied.<br>fl1.m:049: Declared `det', inferred `multi'.<br>fl1.m:056: Disjunction has multiple clauses with solutions.<br></div><div><br></div><div>Now...I understand why (I think) this happens: it's because the final matching disjuny can match more than one character value hence the multiple (multi) classification by the compiler BUT he calling loop seeks merely to convert a character into a character type.</div><div><br></div><div>Is this "cc_multi" in disguise as if the character is not one of the ones explicitly tested for then I will commit to the first choice as it will be a "general" character i.e. one with no special meaning to my little lexer.</div><div><br></div><div>Thank you,</div><div>Sean.</div><div><br></div></div>
_______________________________________________<br>
users mailing list<br>
<a href="mailto:users@lists.mercurylang.org" target="_blank">users@lists.mercurylang.org</a><br>
<a href="https://lists.mercurylang.org/listinfo/users" rel="noreferrer" target="_blank">https://lists.mercurylang.org/listinfo/users</a><br>
</blockquote></div>
</blockquote></div>
</blockquote></div>
_______________________________________________<br>
users mailing list<br>
<a href="mailto:users@lists.mercurylang.org" target="_blank">users@lists.mercurylang.org</a><br>
<a href="https://lists.mercurylang.org/listinfo/users" rel="noreferrer" target="_blank">https://lists.mercurylang.org/listinfo/users</a><br>
</blockquote></div>