[mercury-users] Couple of questions about my program
Vladimir Gubarkov
xonixx at gmail.com
Wed Feb 16 07:22:23 AEDT 2011
Hi,
I have written brainfuck interpreter on mercury. You can see the source code
here:
http://www.xonix.info/2011/02/brainfuck-mercury.html (warning: text is in
russian, but code is in mercury, however =) )
google translated:
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
My questions are next:
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
:- mode ast(out, in, out) is multi.
compilation gives me:
D:\stuff\test\mercury\bf>..\mmc_.bat bf
Making Mercury\int3s\bf.int3
Making Mercury\ints\bf.int
Making Mercury\cs\bf.c
Uncaught Mercury exception:
Software Error: unique_modes.m: Unexpected: call to implied mode?
Stack dump not available in this grade.
Error: system command received signal 1.
** Error making `Mercury\cs\bf.c'.
2) Compilation gives me warning message:
bf.m:261: In `opt_defaults'(out, out):
bf.m:261: warning: determinism declaration could be tighter.
bf.m:261: Declared `nondet', inferred `multi'.
But if I change mode to multi it won't compile at all:
bf.m:278: In clause for `main(di, uo)':
bf.m:278: in argument 1 of call to predicate `getopt.process_options'/4:
bf.m:278: mode error: variable `V_16' has instantiatedness
bf.m:278: `unique(getopt.option_ops(/* unique */(pred((ground >> ground),
bf.m:278: (free >> ground)) is semidet), /* unique */(pred((ground >>
bf.m:278: ground), (free >> ground)) is semidet), /* unique */(pred((free
>>
bf.m:278: ground), (free >> ground)) is multi)))',
bf.m:278: expected instantiatedness was
bf.m:278: `bound(getopt.option_ops((pred((ground >> ground), (free >>
bf.m:278: ground)) is semidet), (pred((ground >> ground), (free >>
ground))
bf.m:278: is semidet), (pred((free >> ground), (free >> ground)) is
nondet))
bf.m:278: ; getopt.option_ops((pred((ground >> ground), (free >> ground))
is
bf.m:278: semidet), (pred((ground >> ground), (free >> ground)) is
semidet),
bf.m:278: (pred((free >> ground), (free >> ground)) is nondet),
(pred((ground
bf.m:278: >> ground), (ground >> ground), (ground >> ground), (free >>
bf.m:278: ground)) is semidet)) ; getopt.option_ops_multi((pred((ground >>
bf.m:278: ground), (free >> ground)) is semidet), (pred((ground >>
ground),
bf.m:278: (free >> ground)) is semidet), (pred((free >> ground), (free >>
bf.m:278: ground)) is multi)) ; getopt.option_ops_multi((pred((ground >>
bf.m:278: ground), (free >> ground)) is semidet), (pred((ground >>
ground),
bf.m:278: (free >> ground)) is semidet), (pred((free >> ground), (free >>
bf.m:278: ground)) is multi), (pred((ground >> ground), (ground >>
ground),
bf.m:278: (ground >> ground), (free >> ground)) is semidet)))'.
For more information, recompile with `-E'.
Error: system command received signal 1.
** Error making `Mercury\cs\bf.c'.
I believe this behaviour is not correct.
3) As you can see, I'm using
one_solution(Pred, Solution) :-
solutions(Pred, [Solution|_]).
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?
Here is mercury version I'm using:
Mercury Compiler, version 10.04.2, configured for i686-pc-mingw32
Copyright (C) 1993-2010 The University of Melbourne
Usage: mmc [<options>] <arguments>
Use `mmc --help' for more information.
Thank you,
Sincerely yours,
Vladimir
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/users/attachments/20110215/be335288/attachment.html>
More information about the users
mailing list