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

86
LINES

< > BotCompany Repo | #1002746 // SNL Logic Engine 3 (C is a Language)

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

Libraryless. Click here for Pure Java version (4316L/28K/89K).

1  
!759
2  
3  
static S codeSnippetID = "#1002745";
4  
static Lisp code;
5  
static new L<Lisp> memory;
6  
7  
static new L<S> log;
8  
9  
p {
10  
  code = snlToTree(loadSnippet(codeSnippetID));
11  
  print(getProgramID() + ": parse result = " + code);
12  
  load("memory");
13  
}
14  
15  
static Lisp snlMatchFirst(Lisp pat, L<Lisp> list, SNLMatches m) {
16  
  for (Lisp l : list)
17  
    if (snlMatch2(pat, l, m))
18  
      ret l;
19  
  ret null;
20  
}
21  
22  
static Lisp scanMem(Lisp pat, SNLMatches m) {
23  
  ret snlMatchFirst(pat, memory, m);
24  
}
25  
26  
static Lisp scanMem(S pat, SNLMatches m) {
27  
  ret snlMatchFirst(snlToTree_cached(pat), memory, m);
28  
}
29  
30  
static void memorize(Lisp l) {
31  
  if (!memory.contains(l)) {
32  
    memory.add(l);
33  
    save("memory");
34  
  }
35  
}
36  
37  
static boolean yo(Lisp snl, SNLMatches m) {
38  
  if (scanMem(snl, m) != null)
39  
    ret true;
40  
41  
  if (snlMatch2("i < don't < know < X", snl, m))
42  
    ret scanMem("* < said < X < is < *", m) == null; // TODO: vars probably don't work
43  
44  
  ret false;
45  
}
46  
47  
!include #1002750 // new LThread
48  
49  
static Lisp runSingle(Lisp statement, Lisp code) {
50  
  log.add("runSingle " + code);
51  
  LThread thread = new LThread(code);
52  
  thread.log = log;
53  
  thread.statements.add(statement);
54  
  print("Statements: " + structure(thread.statements));
55  
  ret thread.run() ? first(thread.output) : null;
56  
}
57  
58  
static Lisp runMulti(Lisp statement, Lisp code) {
59  
  assertTrue(isJuxta(code));
60  
  for (Lisp sub : code) {
61  
    Lisp l = runSingle(statement, sub);
62  
    if (l != null) ret l;
63  
  }
64  
  ret null;
65  
}
66  
67  
answer {
68  
  if (!attn()) ret null;
69  
  
70  
  if (match("log " + parseSnippetID(programID()), s))
71  
    ret slackSnippet(fromLines(log));
72  
  
73  
  if (match("memory " + parseSnippetID(programID()), s))
74  
    ret slackSnippet(structureLines(memory));
75  
  
76  
  log.clear();
77  
  
78  
  // convert to SNL first
79  
  s = or((S) callOpt/*Safe*/(getBot ("#1002700"), "naiveSNL", s), s);
80  
  Lisp in = snlToTree(s);
81  
  
82  
  Lisp statement = snlToTree("user < says < [" + snlFromTree(in) + "]");
83  
  Lisp out = isJuxta(code) ? runMulti(statement, code) : runSingle(statement, code);
84  
  if (out != null)
85  
    ret "[SNL: " + snlFromTree(in) + "]\n" + snlToText(out);
86  
}

Author comment

Began life as a copy of #1002733

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: #1002746
Snippet name: SNL Logic Engine 3 (C is a Language)
Eternal ID of this version: #1002746/1
Text MD5: 33202dfba0496e02fb2a9d3c9d418801
Transpilation MD5: 8160b929123682e078758341e7538de1
Author: stefan
Category: eleu / nl
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-02-19 21:56:11
Source code size: 2135 bytes / 86 lines
Pitched / IR pitched: No / No
Views / Downloads: 693 / 659
Referenced in: [show references]