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

34
LINES

< > BotCompany Repo | #1007403 // Guesser & Improver [dev.]

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

Libraryless. Click here for Pure Java version (735L/5K/18K).

1  
!7
2  
3  
sclass Improver<A, B> {
4  
  O guesser; // func(A) -> B
5  
  new HashMap<A, B> examples;
6  
  new HashSet<A> errorExamples;
7  
  new O error;
8  
  
9  
  B get(A a) {
10  
    if (errorExamples.contains(a)) fail();
11  
    if (examples.containsKey(a))
12  
      ret examples.get(a);
13  
    try {
14  
      B b = (B) callF(guesser, a);
15  
      examples.put(a, b);
16  
      ret b;
17  
    } catch e {
18  
      errorExamples.add(a);
19  
      throw rethrow(e);
20  
    }
21  
  }
22  
  
23  
  void addExample(A a, B b) {
24  
    examples.put(a, b);
25  
    errorExamples.remove(a);
26  
  }
27  
}
28  
29  
p {
30  
  new Improver i;
31  
  print("hello => " + i.get("hello"));
32  
  i.addExample("hello", "world");
33  
  print("hello => " + i.get("hello"));
34  
}

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: #1007403
Snippet name: Guesser & Improver [dev.]
Eternal ID of this version: #1007403/1
Text MD5: c1c84d1b80f65962440f76f8082a6d67
Transpilation MD5: 354cff236daaa8bc5fb2cb63ea23bf19
Author: stefan
Category: javax / a.i.
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-03-22 18:25:09
Source code size: 678 bytes / 34 lines
Pitched / IR pitched: No / No
Views / Downloads: 518 / 604
Referenced in: [show references]