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

68
LINES

< > BotCompany Repo | #1002761 // SNL Logic Engine 5, factored out LogicEngine

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

Libraryless. Click here for Pure Java version (4525L/29K/93K).

!759

static S codeSnippetID = "#1002758";
static Lisp code;
static new L<Lisp> memory;
static LogicEngine engine;

!include #1002759 // LogicEngine

static class MyEngine extends LogicEngine {
  *(Lisp code, L<Lisp> memory) {
    super(code, memory);
  }
  
  public boolean yo(Lisp snl, SNLMatches m) {
    if (super.yo(snl, m))
      ret true;
    
    new SNLMatches mInner;
   
    if (snlMatch2("[the > length < of < string < S] < is < L < characters", snl, mInner)) { // TODO: variable renaming?
      S s = snlGetString(mInner.map, "S");
      putMatchX(m.map, mInner.map, "L", lstr(s));
      ret true;
    }
    
    ret false;
  }
}

p {
  code = snlToTree(loadSnippet(codeSnippetID));
  print(getProgramID() + ": parse result = " + code);
  load("memory");
}

synchronized answer {
  if (!attn()) ret null;
  
  if (match("log " + parseSnippetID(programID()), s))
    ret engine == null ? "nullie haven't run yet": slackSnippet(fromLines(engine.log));
  
  if (match("memory " + parseSnippetID(programID()), s))
    ret slackSnippet(snlAllToText(memory));
  
  // convert to SNL first
  s = or((S) callOpt/*Safe*/(getBot ("#1002700"), "naiveSNL", s), s);
  Lisp in = snlToTree(s);
  
  Lisp statement = snlToTree("user < says < [" + snlFromTree(in) + "]");
  engine = new MyEngine(code, memory) {
    void saveMemory() {
      save("memory");
    }
  };
  engine.stmAdd(statement);
  
  L<Lisp> out = engine.run();
  if (nempty(out))
    ret "[SNL: " + snlFromTree(in) + "])\n" + snlAllToText(out);
}

static Lisp quickrun(L<Lisp> memory, S userInput) {
  engine = new LogicEngine(code, memory);
  Lisp statement = snlToTree("user < says < [" + userInput + "]");
  engine.stmAdd(statement);
  ret snlMakeJuxta(engine.run());
}

Author comment

Began life as a copy of #1002751

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

No comments. add comment

Snippet ID: #1002761
Snippet name: SNL Logic Engine 5, factored out LogicEngine
Eternal ID of this version: #1002761/1
Text MD5: f8d7318419e38962ae798552b536dc2d
Transpilation MD5: 41ef1048130f8303346a47e294825ee4
Author: stefan
Category: eleu / nl
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-02-22 19:42:22
Source code size: 1805 bytes / 68 lines
Pitched / IR pitched: No / No
Views / Downloads: 603 / 850
Referenced in: [show references]