<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;">Absolutely perfect Zoltan, thanks again! <div>Implemented and tested already,</div><div><br></div><div><div><font face="Monaco"><span style="font-style: normal;">:- type inclusion_type</span></font></div><div><font face="Monaco"><span style="font-style: normal;"> ---> req</span></font></div><div><font face="Monaco"><span style="font-style: normal;"> ; req_once</span></font></div><div><font face="Monaco"><span style="font-style: normal;"> ; incl</span></font></div><div><font face="Monaco"><span style="font-style: normal;"> ; incl_once.</span></font></div><div><font face="Monaco"><span style="font-style: normal;"><br></span></font></div><div><font face="Monaco"><span style="font-style: normal;">:- pred syntax_include(location::in, lsnode::in, checked::out) is det.</span></font></div><div><font face="Monaco"><span style="font-style: normal;">:- pred syntax_include_once(location::in, lsnode::in, checked::out) is det.</span></font></div><div><font face="Monaco"><span style="font-style: normal;">:- pred syntax_require(location::in, lsnode::in, checked::out) is det.</span></font></div><div><font face="Monaco"><span style="font-style: normal;">:- pred syntax_require_once(location::in, lsnode::in, checked::out) is det.</span></font></div><div><font face="Monaco"><span style="font-style: normal;"><br></span></font></div><div><font face="Monaco"><span style="font-style: normal;">syntax_include(Pos, Body, Out) :-</span></font></div><div><font face="Monaco"><span style="font-style: normal;"> tr_inclusions(Pos, Body, include_form_error, incl, Out).</span></font></div><div><font face="Monaco"><span style="font-style: normal;"><br></span></font></div><div><font face="Monaco"><span style="font-style: normal;">syntax_include_once(Pos, Body, Out) :-</span></font></div><div><font face="Monaco"><span style="font-style: normal;"> tr_inclusions(Pos, Body, include_form_error, incl_once, Out).</span></font></div><div><font face="Monaco"><span style="font-style: normal;"><br></span></font></div><div><font face="Monaco"><span style="font-style: normal;">syntax_require(Pos, Body, Out) :-</span></font></div><div><font face="Monaco"><span style="font-style: normal;"> tr_inclusions(Pos, Body, require_form_error, req, Out).</span></font></div><div><font face="Monaco"><span style="font-style: normal;"><br></span></font></div><div><font face="Monaco"><span style="font-style: normal;">syntax_require_once(Pos, Body, Out) :-</span></font></div><div><font face="Monaco"><span style="font-style: normal;"> tr_inclusions(Pos, Body, require_form_error, req_once, Out).</span></font></div><div><br></div><div><br></div><div><br><blockquote type="cite"><div>On 5 Nov 2022, at 09:00, Sean Charles (emacstheviking) <objitsu@gmail.com> wrote:</div><br class="Apple-interchange-newline"><div><div>Yes, that would def. work!<br><br>:D<br><br>Thanks Zoltan, sometimes the obvious things aren't that obvious...<br><br>Sean<br><br><br><blockquote type="cite">On 5 Nov 2022, at 08:58, Zoltan Somogyi <zoltan.somogyi@runbox.com> wrote:<br><br><br><br>On Sat, 5 Nov 2022 08:44:52 +0000, "Sean Charles (emacstheviking)" <objitsu@gmail.com> wrote:<br><br><blockquote type="cite">The idea was to take the above function and refactor like this, passing in the term...<br><br>tr_inclusions(Pos, Body, Term, Out) :-<br> Len = list.length(Body),<br> ( if Len > 0 then<br> convert_terms(Body, Res),<br> (<br> Res = ok(TrInst),<br> Out = ok(Term)<br> ;<br> Res = error(Errors),<br> Out = error(Errors)<br> )<br> else<br> Out = checkfail(Pos, require_form_error)<br> ).<br><br>... tr_inclusions(Pos, Body, t_require(Pos, HOLE), Out)<br><br>but I can't use an unbound variable on those constructors<br>as they have to be fully instatiated and how would I know<br>where to put TrInst anyway when composing the returned value?<br></blockquote><br>It is possible to express this in Mercury, but that does not matter,<br>because the compiler cannot modecheck code that fills in<br>partially instantiated data structures.<br><br>What you want seems to be a way to use the same code<br>to handle four constructs for which the code is all but identical,<br>differing only in the function symbol you want to wrap around<br>two terms. You can do that using code like this:<br><br>:- type require_kind<br> ---> rk_req<br> ; rk_req_once<br> ; rk_incl<br> ; rk_incl_once.<br><br>syntax_require(Pos, Kind, Body, Out) :-<br> Len = list.length(Body),<br> ( if Len > 0 then<br> convert_terms(Body, Res),<br> (<br> Res = ok(TrInst),<br> ( Kind = rk_req, Req = t_require(Pos, TrInst)<br> ; Kind = rk_req_one, Req = t_require_once(Pos, TrInst)<br> ; Kind = rk_incl, Req = t_include(Pos, TrInst)<br> ; Kind = rk_incl_once, Req = t_include_once(Pos, TrInst)<br> ),<br> Out = ok(Req)<br> ;<br> Res = error(Errors),<br> Out = error(Errors)<br> )<br> else<br> Out = checkfail(Pos, require_form_error)<br> ).<br><br>This is not quite as elegant, but it should work.<br><br>Zoltan.<br></blockquote><br></div></div></blockquote></div><br></div></body></html>