Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

40
LINES

< > BotCompany Repo | #1002815 // GNU Prolog Test 2 (loading text)

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Uses 419K of libraries. Click here for Pure Java version (99L/1K/4K).

!752

!1002813 // gnu prolog

import gnu.prolog.vm.*;
import gnu.prolog.term.*;
import gnu.prolog.database.*;

static int query(Interpreter intp, Term term) ctex {
  try {
    Interpreter.Goal goal = intp.prepareGoal(term);
	  ret intp.execute(goal);
	  // todo: stop goal?
	 } catch (Exception e) {
	   print("fail " + e);
	   ret 0;
	 }
}

p {
  new Environment env;
  
  S streamName = "someinput";
  Reader reader = new StringReader("here.");
  
  new PrologTextLoader(env.getPrologTextLoaderState(), reader, streamName);
  
	List<PrologTextLoaderError> errors = env.getLoadingErrors();
	for (PrologTextLoaderError error : errors) {
		printStackTrace(error);
	}

  Interpreter interpreter = env.createInterpreter();
  env.runInitialization(interpreter);
  
  //print(interpreter.runOnce(AtomTerm.get("here")));
  //print(interpreter.runOnce(AtomTerm.get("there")));
  print(query(interpreter, AtomTerm.get("true")));
  print(query(interpreter, AtomTerm.get("there")));
  print(query(interpreter, AtomTerm.get("here")));
}

Author comment

Began life as a copy of #1002814

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

Comments [hide]

ID Author/Program Comment Date
1212 stefan Ok, KINDA works... 2016-02-27 01:50:51

add comment

Snippet ID: #1002815
Snippet name: GNU Prolog Test 2 (loading text)
Eternal ID of this version: #1002815/1
Text MD5: e87edd51ec87a42405a593bcefd6b89f
Transpilation MD5: b9157e4b71db63b8f3a43e977ef4e27c
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-02-27 01:50:26
Source code size: 1063 bytes / 40 lines
Pitched / IR pitched: No / No
Views / Downloads: 849 / 1043
Referenced in: #1002816 - GNU Prolog Test 3 (var assignments)
#3000382 - Answer for ferdie (>> t = 1, f = 0)
#3000383 - Answer for funkoverflow (>> t=1, f=0 okay)