Hi,<br>I have written brainfuck interpreter on mercury. You can see the source code here:<div><br><a href="http://www.xonix.info/2011/02/brainfuck-mercury.html" target="_blank">http://www.xonix.info/2011/02/brainfuck-mercury.html</a> (warning: text is in russian, but code is in mercury, however =) )<br>
<br></div><div>google translated: <a href="http://translate.google.com/translate?js=n&prev=_t&hl=ru&ie=UTF-8&layout=2&eotf=1&sl=ru&tl=en&u=http://www.xonix.info/2011/02/brainfuck-mercury.html" target="_blank">http://translate.google.com/translate?js=n&prev=_t&hl=ru&ie=UTF-8&layout=2&eotf=1&sl=ru&tl=en&u=http://www.xonix.info/2011/02/brainfuck-mercury.html</a><br>
<br>My questions are next:<br><br></div><div>1) I'm compiling the program with --infer-all option, so I believe compiler should infer all pred/mode declarations. However if I omit line<br><br>:- mode ast(out, in, out) is multi.</div>
<div><br></div><div>compilation gives me:</div><div><br></div><div><div>D:\stuff\test\mercury\bf>..\mmc_.bat bf</div><div>Making Mercury\int3s\bf.int3</div><div>Making Mercury\ints\<a href="http://bf.int">bf.int</a></div>
<div>Making Mercury\cs\bf.c</div><div>Uncaught Mercury exception:</div><div>Software Error: unique_modes.m: Unexpected: call to implied mode?</div><div>Stack dump not available in this grade.</div><div>Error: system command received signal 1.</div>
<div>** Error making `Mercury\cs\bf.c'.</div></div><div><br></div><div>2) Compilation gives me warning message:</div><div><br></div><div><div>bf.m:261: In `opt_defaults'(out, out):</div><div>bf.m:261:   warning: determinism declaration could be tighter.</div>
<div>bf.m:261:   Declared `nondet', inferred `multi'.</div></div><div><br></div><div>But if I change mode to multi it won't compile at all:</div><div><br></div><div><div>bf.m:278: In clause for `main(di, uo)':</div>
<div>bf.m:278:   in argument 1 of call to predicate `getopt.process_options'/4:</div><div>bf.m:278:   mode error: variable `V_16' has instantiatedness</div><div>bf.m:278:   `unique(getopt.option_ops(/* unique */(pred((ground >> ground),</div>
<div>bf.m:278:   (free >> ground)) is semidet), /* unique */(pred((ground >></div><div>bf.m:278:   ground), (free >> ground)) is semidet), /* unique */(pred((free >></div><div>bf.m:278:   ground), (free >> ground)) is multi)))',</div>
<div>bf.m:278:   expected instantiatedness was</div><div>bf.m:278:   `bound(getopt.option_ops((pred((ground >> ground), (free >></div><div>bf.m:278:   ground)) is semidet), (pred((ground >> ground), (free >> ground))</div>
<div>bf.m:278:   is semidet), (pred((free >> ground), (free >> ground)) is nondet))</div><div>bf.m:278:   ; getopt.option_ops((pred((ground >> ground), (free >> ground)) is</div><div>bf.m:278:   semidet), (pred((ground >> ground), (free >> ground)) is semidet),</div>
<div>bf.m:278:   (pred((free >> ground), (free >> ground)) is nondet), (pred((ground</div><div>bf.m:278:   >> ground), (ground >> ground), (ground >> ground), (free >></div><div>bf.m:278:   ground)) is semidet)) ; getopt.option_ops_multi((pred((ground >></div>
<div>bf.m:278:   ground), (free >> ground)) is semidet), (pred((ground >> ground),</div><div>bf.m:278:   (free >> ground)) is semidet), (pred((free >> ground), (free >></div><div>bf.m:278:   ground)) is multi)) ; getopt.option_ops_multi((pred((ground >></div>
<div>bf.m:278:   ground), (free >> ground)) is semidet), (pred((ground >> ground),</div><div>bf.m:278:   (free >> ground)) is semidet), (pred((free >> ground), (free >></div><div>bf.m:278:   ground)) is multi), (pred((ground >> ground), (ground >> ground),</div>
<div>bf.m:278:   (ground >> ground), (free >> ground)) is semidet)))'.</div><div>For more information, recompile with `-E'.</div><div>Error: system command received signal 1.</div><div>** Error making `Mercury\cs\bf.c'.</div>
</div><div><br></div><div>I believe this behaviour is not correct.</div><div><br></div><div>3) As you can see, I'm using</div><div><br></div><div><div>one_solution(Pred, Solution) :-</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>solutions(Pred, [Solution|_]).</div>
</div><div><br></div><div>for finding the only solution for parsing by DCG. But I believe this is not optimal as it searches for ALL solutions, then SORTS them, and only after - returns the first one. My question is - how could I (and could I?) change my code to get first working solution?</div>
<div> </div><div><br></div><div>Here is mercury version I'm using:</div><div><br></div><div><div>Mercury Compiler, version 10.04.2, configured for i686-pc-mingw32</div><div>Copyright (C) 1993-2010 The University of Melbourne</div>
<div>Usage: mmc [<options>] <arguments></div><div>Use `mmc --help' for more information.</div></div><div><br>Thank you,</div><div>Sincerely yours,</div><div>Vladimir</div>