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

54
LINES

< > BotCompany Repo | #1001844 // SO (developing)

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

Libraryless. Click here for Pure Java version (852L/6K/19K).

1  
!752
2  
3  
m {
4  
  // subject, object (S/O can be verbs, nouns, anything)
5  
  static class SO {
6  
    S s, o;
7  
    int value; // 1 = asserted as true, -1 = asserted as false
8  
    
9  
    *(S *s, S *o) {}
10  
    *(S *s, S *o, int *value) {}
11  
    *() {}
12  
    
13  
    public boolean equals(O _o) {
14  
      if (!(_o instanceof SO)) ret false;
15  
      SO x = cast _o;
16  
      ret eq(s, x.s) && eq(o, x.o);
17  
    }
18  
  }
19  
  
20  
  static new L<SO> data;
21  
  
22  
  static void store(S s, S o, int value) {
23  
    data.add(new SO(s, o, value));
24  
  }
25  
  
26  
  static int query(S s, S o) {
27  
    int i = data.indexOf(new SO(s, o));
28  
    ret i >= 0 ? data.get(i).value : 0;
29  
  }
30  
  
31  
  static S answer(S s) {
32  
    new Matches m;
33  
    if (match("query * *", s, m))
34  
      ret string(query(m.unq(0), m.unq(1)));
35  
    if (match("assert * *", s, m)) {
36  
      store(m.unq(0), m.unq(1), 1);
37  
      ret "OK.";
38  
    }
39  
    if (match("assertnot * *", s, m)) {
40  
      store(m.unq(0), m.unq(1), -1);
41  
      ret "OK.";
42  
    }
43  
    ret null;
44  
  }
45  
  
46  
  p {
47  
    store("we can wait", "1 second", 1);
48  
    store("we can wait", "60 seconds", -1);
49  
    assertEq(1, query("we can wait", "1 second"));
50  
    assertEq(-1, query("we can wait", "60 seconds"));
51  
    assertEq(0, query("we can wait", "10 seconds"));
52  
    print("OK!");
53  
  }
54  
}

Author comment

Began life as a copy of #1001841

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1001844
Snippet name: SO (developing)
Eternal ID of this version: #1001844/1
Text MD5: af24bc7c49aa03bf0291e2c5343b311c
Transpilation MD5: 854fe94955d64b78e0fa5e7f7b0a19f5
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-11-24 19:16:25
Source code size: 1280 bytes / 54 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 551 / 824
Referenced in: [show references]