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

74
LINES

< > BotCompany Repo | #1016856 // Develop From Examples v1 [Dyn Module, tries standard functions, OK]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Libraryless. Click here for Pure Java version (17715L/130K).

!7

!include once #1017126 // transpileRaw

sclass DevelopFromExamples > DynTextArea {
  S whatToTry;
  transient ReliableSingleThread rst = new(r think);

  JComponent visualize() {
    ret withCenteredButtons(centerAndSouthWithMargins(
      jhsplit(super.visualize(), dm_printLogComponent()),
      jsection("Stuff to try", onEnter(dm_fieldTextField('whatToTry), rst))), "Fresh", rThread fresh, "Think", rst);
  }
  
  void fresh {
    forgetTranspiledStandardFunctions(words(whatToTry));
    loadFunctions_clearCache();
    rst.trigger();
  }
  
  void think {
    clearPrintLog();
    loadFunctions_preferDiskCache();
    
    S text = rtrimAll(getText());
    Pair<File, Bool> examplesFile = ai_makeExamplesFile(text);
    if (examplesFile.b) print("Wrote: " + f2s(examplesFile.a));
    new L<Pair<S>> examples;
    bool eqic = false;
    
    L<S> lines = tlftj(text);
    if (eq(first(lines), "splitAtEmptyLines"))
      lines = splitAtEmptyLines(text);
      
    for (S line : lines) pcall {
      if (eqic(line, "eqic")) eqic = true;
      L<S> l = splitAtDoubleArrow_bothDirections(line);
      if (l(l) == 2) addPair(examples,
        tok_multiLineQuotesToStandardQuotes(first(l)),
        safeCanonicalizeStructure(tok_multiLineQuotesToStandardQuotes(second(l))));
    }
    
    final File logFile = replaceExtension(examplesFile.a, ".log");
    final LineBuffer lineBuffer = new(voidfunc(S line) { appendToFile(logFile, line + "\n") });
    temp tempInterceptPrint(func(S s) -> Bool { lineBuffer.append(s); true; });
    
    print(localDateWithMilliseconds());
    print("Thinking about " + n2(examples, "example"));
    new LinkedHashSet<S> thingsThatWork;
    F2<O, O, Bool> equalsFunction = eqic
      ? func(O a, O b) -> Bool { eqic((S) a, (S) b) }
      : func(O a, O b) -> Bool { eq(a, b) };
    for (fS s : words(whatToTry))
      if (isStandardFunction(s)) {
        F1<S, S> f = func(S in) -> S { struct(callAndMake_orDirect(s, unstruct(in))) };
        T3<S, S, O> counterExample = worksOnAllExamples_returnCounterExample(f, examples, equalsFunction);
        if (counterExample == null)
          print("WORKS: " + addAndReturn(thingsThatWork, s));
        else {
          print("Nope: " + s);
          bool exc = counterExample.c instanceof Throwable;
          print((exc ? "Exception on:    "
                     : "Wrong result on: ") + sfu(counterExample.a));
          print(       "Expected:        " + sfu(counterExample.b));
          if (exc)
            printStackTrace((Throwable) counterExample.c);
          else
            print(     "         Result: " + sfu(counterExample.c));
        }
      }
    print("\nDone. " + (empty(thingsThatWork) ? "Nothing works." : "Things that work: " + joinWithComma(thingsThatWork)));
    print();
  }
}

Author comment

Began life as a copy of #1016846

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1016856
Snippet name: Develop From Examples v1 [Dyn Module, tries standard functions, OK]
Eternal ID of this version: #1016856/35
Text MD5: 04378da0d2339e5239cf9690f3039dab
Transpilation MD5: c59d54802766bd6280e98b4411cf68a2
Author: stefan
Category: javax / a.i.
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-07-13 17:36:32
Source code size: 2859 bytes / 74 lines
Pitched / IR pitched: No / No
Views / Downloads: 392 / 1249
Version history: 34 change(s)
Referenced in: [show references]