View Issue Details [ Jump to Notes ] | [ Issue History ] [ Print ] | ||||||||
ID | Project | Category | View Status | Date Submitted | Last Update | ||||
---|---|---|---|---|---|---|---|---|---|
0000325 | mercury | Bug | public | 2014-04-22 14:33 | 2014-06-20 11:00 | ||||
Reporter | lpimmes | ||||||||
Assigned To | wangp | ||||||||
Priority | urgent | Severity | major | Reproducibility | always | ||||
Status | closed | Resolution | no change required | ||||||
Platform | iMac | OS | OSX 10.9.2 | OS Version | |||||
Product Version | |||||||||
Target Version | Fixed in Version | ||||||||
Summary | 0000325: Mercury code works via command line, when ported to java, output fails. | ||||||||
Description | Create netbeans mercuryTst, Copy Mercury/javas/jmercury/edgar2.java to src directory. Compile code; it does compile. Run: output fails, when it should work. See code uploaded. | ||||||||
Steps To Reproduce | mmc --make --fully-strict -s java -E -v -O 0 --use-subdirs edgar2 CORRECT OUTPUT: edgar2a 466>./edgar2 company sales increased a lot sales increased edgar2a 466>./edgar2 company sales Failed to parse input sentence. edgar2a 467> | ||||||||
Additional Information | edgar2a 467>mmc -version mercury_compile: invalid grade `ion' Mercury Compiler, version 14.01, configured for x86_64-apple-darwin13.1.0 See merTst.zip for java and m files. Thanks. | ||||||||
Tags | No tags attached. | ||||||||
Attached Files |
|
Notes | |
lpimmes (reporter) 2014-04-23 05:01 |
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. |
lpimmes (reporter) 2014-04-29 18:05 |
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. |
wangp (developer) 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. |
lpimmes (reporter) 2014-05-01 01:18 |
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. |
juliensf (administrator) 2014-05-01 02:04 |
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.) |
lpimmes (reporter) 2014-05-04 01:29 |
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. |
lpimmes (reporter) 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 |
Issue History | |||
Date Modified | Username | Field | Change |
---|---|---|---|
2014-04-22 14:33 | lpimmes | New Issue | |
2014-04-22 14:33 | lpimmes | File Added: merTst.zip | |
2014-04-23 04:58 | lpimmes | File Added: all_files.zip | |
2014-04-23 05:01 | lpimmes | Note Added: 0000662 | |
2014-04-29 17:53 | lpimmes | File Added: edgar2.m | |
2014-04-29 18:05 | lpimmes | Note Added: 0000664 | |
2014-04-30 11:40 | wangp | Note Added: 0000665 | |
2014-05-01 01:18 | lpimmes | Note Added: 0000670 | |
2014-05-01 02:04 | juliensf | Note Added: 0000671 | |
2014-05-04 01:29 | lpimmes | Note Added: 0000678 | |
2014-05-04 08:15 | lpimmes | File Added: edgar2_works.m | |
2014-05-04 08:18 | lpimmes | Note Added: 0000679 | |
2014-05-04 08:19 | lpimmes | Note Edited: 0000679 | View Revisions |
2014-06-20 11:00 | wangp | Status | new => closed |
2014-06-20 11:00 | wangp | Assigned To | => wangp |
2014-06-20 11:00 | wangp | Resolution | open => no change required |