Notes |
|
|
Ignore merTst.zip, better solution(attempted) in all_files.zip
java_calls_mercury 478>cd ~/Desktop/all_files/java_calls_mercury/
java_calls_mercury 479>ls
JavaMain.java Makefile java_main_int.m mercury_lib.init mercury_lib.m mercury_main.m
java_calls_mercury 479>make
mmc --grade java --make libmercury_lib
Making Mercury/int3s/mercury_lib.int3
Making Mercury/ints/mercury_lib.int
Making Mercury/javas/jmercury/mercury_lib.java
mercury_lib.m:101: In `arbitraryWrd'(out, in, out):
mercury_lib.m:101: warning: determinism declaration could be tighter.
mercury_lib.m:101: Declared `nondet', inferred `semidet'.
mercury_lib.m:106: In `impWrd'(out, in, out):
mercury_lib.m:106: warning: determinism declaration could be tighter.
mercury_lib.m:106: Declared `nondet', inferred `semidet'.
Making Java class files
Note: Mercury/javas/jmercury/mercury_lib.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Making mercury_lib.jar
...
The code, edgar2.m, i.e. parse/2 works just fine, see edgar2.bash to compile.
Now splice parse/2 into mercury_lib.m, use the JavaMain.java with my modifications.
make...
<error>
Not sure what is going on.
Thanks. |
|
|
|
Try to satisfy compiler when making edgar2.m a library.
Hypothesis for fixing: Reduce modes.
Works without being a library, doesn't work being a library.
(because error it complains about are mode errors.)
Now,
main det
parse det
edgarParse semidet
zeroOrOne semidet
numX semidet ;; but code has reduced functionality
1) How do I write the numX, keeping semidet?
% Call input predicate Pred for X number of times-- depending upon length of list.
:- pred numX( pred(string, list(string), list(string)),
list(string), % H, T, [H|T]
list(string), % Input, implicit
list(string)). % Consumed, implicit
%% How do I write this funcitonality with semidet, i.e., adding other two clauses?
%% Compiler complains, args must be after --> then {...}
:- mode numX(in(pred(out, in, out) is semidet), out, in, out) is semidet.
numX(Pred, [H|T]) --> call(Pred, H), numX(Pred, T), { T \= [] }.
%numX(Pred, [H]) --> call(Pred, H).
%numX(_, []) --> [].
2) edgarParse OK for now, but I want multiple edgarParse(Ret), so I how would I add more clauses and still keep semidet? I want each edgarParse rule to succeed 1 time, or 0 times, not multiple times.
:- pred edgarParse(string, list(string), list(string)).
:- mode edgarParse(out, in, out) is semidet. % 1 or 0 times; I don't want multiple times
edgarParse(Ret) -->
zeroOrMore(anyWrd, _), impWrd(Ac), zeroOrMore(anyWrd, _),
{
formattedStr([Ac], Ret)
}.
% Cannot add another one, without changing to nondet.
edgarParse(Ret) -->
impWrd(Ac), zeroOrMore(anyWrd, _),
{
formattedStr([Ac], Ret)
}.
Idea is that, if these two problems are fixed, then I can make this into a library, and run without
runtime errors.
Thanks. |
|
|
(0000665)
|
wangp
|
2014-04-30 11:40
|
|
The all_files test seems to work for me:
one_parse() gives value = sales increased
one_parse() gives value = Failed to parse input sentence.
About semidet, you will need use an if-then-else to say that you do not want the other potential solutions. Therefore you need to write your predicate in one clause. |
|
|
|
Compiler errors abound; changing one thing, results in a new error.
Here is the latest attempt:
:- pred zeroOrMore(pred(string, list(string), list(string)), string,
list(string), % Input
list(string)). % Consumed
:- mode zeroOrMore(in(pred(out,in,out) is semidet), out, in, out) is semidet.
zeroOrMore(Pred, Ret) --> numX(Pred, NumX),
{
(if
length(NumX, 0)
then
Ret = ""
else
lstToStr(NumX, "", Ret)
)
}.
% Call input predicate Pred for X number of times-- depending upon length of list.
:- pred numX( pred(string, list(string), list(string)),
list(string), % H, T, [H|T]
list(string), % Input, implicit
list(string)). % Consumed, implicit
%% How do I write this funcitonality with semidet, i.e., adding other two clauses?
%% Compiler complains, args must be after --> then {...}
:- mode numX( in, out, in, out) is semidet.
%numX(Pred, [H|T]) --> call(Pred, H), numX(Pred, T), { T \= [] }.
%numX(Pred, [H]) --> call(Pred, H).
%numX(_, []) --> [].
numX(Pred, [H|T]) -->
if call(Pred, "if") % { [H|T] = Lst, T \= [] }
then call(Pred, H), numX(Pred, T)
else
(
if call(Pred, "if2") % { [H] = Lst }
then call(Pred, H)
else
call(Pred, T)
).
DCG clause:
if condClause then ifClause else elseClause.
All clauses, fine. Can {...} be interspersed anywhere, or just at the end?
No real mention of {} in DCG in documentation, just some examples.
Thanks. |
|
|
|
DCG escapes, { Goal }, are covered in section 2.12 of the reference manual. That section describes the source-to-source transformation that is used to expand DCGs. In particular it says:
{ Goal }
A brace-enclosed ordinary goal. Goal must be a valid goal.
Semantics: transform(V_in, V_out, { Goal }) = (Goal, V_out = V_in)
So, {...} can be placed around any non-DCG goal. I'm not sure what you mean by "just at the end".
What are the compiler errors that "abound"? And what is the code that causes them? (There are so many different pieces of code above that I can't make sense of them.) |
|
|
|
OK, thank you for the documentation.
Here is the mercury code:
% Call input predicate Pred for X number of times-- depending upon length of list.
:- pred numX( pred(string, list(string), list(string)), list(string),
list(string), list(string)
).
:- mode numX(in(pred(out,in,out) is semidet), out, in, out) is semidet.
% Mercury compiles OK, but a single line only, not 2 or 3 lines uncommented.
% numX(Pred, [H|T]) --> call(Pred, H), numX(Pred, T), { T \= [] }.
% numX(Pred, [H]) --> call(Pred, H).
% numX(_, []) --> [].
% Write comment code in swiprolog; example DCG lists.
% 29 ?- listing(numX).
% numX(A, [B|D], C, F) :-
% call(A, B, C, E),
% numX(A, D, E, G),
% D\=[],
% F=G.
% numX(A, [B], C, D) :-
% call(A, B, C, D).
% numX(_, [], A, A).
% Translate swiprolog in mercury, without using DCG.
%Mercury compiles OK, but just this line.
% numX(_, [], A, A). % compiles in mercury
%Mercury compiles OK, but just this line.
%numX(A, [B], C, D) :-
% call(A, B, C, D).
%Mercury compiles OK, but just this line.
% numX(A, [B|D], C, F) :-
% call(A, B, C, E),
% numX(A, D, E, G),
% D \= [],
% F = G.
% How do I translate the above 3 mercury predicates into a single numX/4 predicate, keeping semidet?
% if/then/else is NOT working.
Thanks. |
|
|
(0000679)
|
lpimmes
|
2014-05-04 08:18
(Last edited: 2014-05-04 08:19) |
|
numX/4 is working, and semidet.
edgarParse/4 is working, and semidet.
Therefore parse/2 is det.
In short, convert DCG to normal mercury which allows for proper if/then/else logic.
Next project (to do), see if same file can be converted to a library, having parse/2 in
the interface.
Thank you for everyone's time and effort.
Please feel free to try out the code, edgar2_works.m
|
|