Różnice
Różnice między wybraną wersją a wersją aktualną.
|
|
pl:miw:logtalktojavaexample [2019/06/27 15:50] |
pl:miw:logtalktojavaexample [2019/06/27 15:50] (aktualna) |
| Kod Javy : |
| <code java> |
| |
| package scr.View; |
| import jpl.*; |
| |
| public class LogTalkCaller { |
| |
| public LogTalkCaller() { |
| |
| |
| JPL.setDefaultInitArgs( |
| new String[] { |
| "pl", |
| "-f", "none", |
| "-g", "set_prolog_flag(debug_on_error,false)", |
| "-q", |
| "-nosignals" |
| } |
| ); |
| |
| |
| Query q = new Query("['lib/logtalkLoad.pl']."); |
| |
| |
| if (!q.hasSolution()) { |
| //RuntimeException e = new RuntimeException("error loading logtalk"); |
| System.out.println("A miało być tak pięknie.."); |
| }else { |
| System.out.println("Hurray!"); |
| |
| Query loadControler = new Query("logtalk_load", |
| new Term[]{ |
| new Atom("src/Controler/logTalkControler") |
| } |
| ); |
| |
| |
| System.out.println("Loaded?" + (loadControler.hasSolution()? "Tak":"A mialo byc tak pieknie...")); |
| |
| |
| askLogTalk.hasSolution(); |
| |
| } |
| |
| } |
| |
| public boolean askLogTalk(String query, String var) { |
| Query askLgt = new Query("logTalkControler::"+query + "(" + var +")."); |
| |
| return askLgt.hasSolution(); |
| } |
| /** |
| * @param args |
| */ |
| public static void main(String[] args) { |
| // TODO Auto-generated method stub |
| LogTalkCaller cal = new LogTalkCaller(); |
| ; |
| |
| System.out.println("Is 'a' a proper TestValue?:" |
| + (cal.askLogTalk("testValue", "a")?"YES":"NO!")); |
| |
| System.out.println("Is 'b' a proper TestValue?:" |
| + (cal.askLogTalk("testValue", "b")?"YES":"NO!")); |
| } |
| |
| } |
| |
| </code> |
| |
| <code prolog> |
| |
| :-object(logTalkControler). |
| :-public(toString/0). |
| :-public(testValue/1). |
| |
| test(a). |
| test(b). |
| test(c). |
| value(a). |
| |
| testValue(X) :- |
| test(X), |
| value(X). |
| |
| :-end_object. |
| |
| |
| </code> |