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).

!7

sclass Improver<A, B> {
  O guesser; // func(A) -> B
  new HashMap<A, B> examples;
  new HashSet<A> errorExamples;
  new O error;
  
  B get(A a) {
    if (errorExamples.contains(a)) fail();
    if (examples.containsKey(a))
      ret examples.get(a);
    try {
      B b = (B) callF(guesser, a);
      examples.put(a, b);
      ret b;
    } catch e {
      errorExamples.add(a);
      throw rethrow(e);
    }
  }
  
  void addExample(A a, B b) {
    examples.put(a, b);
    errorExamples.remove(a);
  }
}

p {
  new Improver i;
  print("hello => " + i.get("hello"));
  i.addExample("hello", "world");
  print("hello => " + i.get("hello"));
}

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: 517 / 602
Referenced in: [show references]