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

1  
!7
2  
3  
!include once #1017126 // transpileRaw
4  
5  
sclass DevelopFromExamples > DynTextArea {
6  
  S whatToTry;
7  
  transient ReliableSingleThread rst = new(r think);
8  
9  
  JComponent visualize() {
10  
    ret withCenteredButtons(centerAndSouthWithMargins(
11  
      jhsplit(super.visualize(), dm_printLogComponent()),
12  
      jsection("Stuff to try", onEnter(dm_fieldTextField('whatToTry), rst))), "Fresh", rThread fresh, "Think", rst);
13  
  }
14  
  
15  
  void fresh {
16  
    forgetTranspiledStandardFunctions(words(whatToTry));
17  
    loadFunctions_clearCache();
18  
    rst.trigger();
19  
  }
20  
  
21  
  void think {
22  
    clearPrintLog();
23  
    loadFunctions_preferDiskCache();
24  
    
25  
    S text = rtrimAll(getText());
26  
    Pair<File, Bool> examplesFile = ai_makeExamplesFile(text);
27  
    if (examplesFile.b) print("Wrote: " + f2s(examplesFile.a));
28  
    new L<Pair<S>> examples;
29  
    bool eqic = false;
30  
    
31  
    L<S> lines = tlftj(text);
32  
    if (eq(first(lines), "splitAtEmptyLines"))
33  
      lines = splitAtEmptyLines(text);
34  
      
35  
    for (S line : lines) pcall {
36  
      if (eqic(line, "eqic")) eqic = true;
37  
      L<S> l = splitAtDoubleArrow_bothDirections(line);
38  
      if (l(l) == 2) addPair(examples,
39  
        tok_multiLineQuotesToStandardQuotes(first(l)),
40  
        safeCanonicalizeStructure(tok_multiLineQuotesToStandardQuotes(second(l))));
41  
    }
42  
    
43  
    final File logFile = replaceExtension(examplesFile.a, ".log");
44  
    final LineBuffer lineBuffer = new(voidfunc(S line) { appendToFile(logFile, line + "\n") });
45  
    temp tempInterceptPrint(func(S s) -> Bool { lineBuffer.append(s); true; });
46  
    
47  
    print(localDateWithMilliseconds());
48  
    print("Thinking about " + n2(examples, "example"));
49  
    new LinkedHashSet<S> thingsThatWork;
50  
    F2<O, O, Bool> equalsFunction = eqic
51  
      ? func(O a, O b) -> Bool { eqic((S) a, (S) b) }
52  
      : func(O a, O b) -> Bool { eq(a, b) };
53  
    for (fS s : words(whatToTry))
54  
      if (isStandardFunction(s)) {
55  
        F1<S, S> f = func(S in) -> S { struct(callAndMake_orDirect(s, unstruct(in))) };
56  
        T3<S, S, O> counterExample = worksOnAllExamples_returnCounterExample(f, examples, equalsFunction);
57  
        if (counterExample == null)
58  
          print("WORKS: " + addAndReturn(thingsThatWork, s));
59  
        else {
60  
          print("Nope: " + s);
61  
          bool exc = counterExample.c instanceof Throwable;
62  
          print((exc ? "Exception on:    "
63  
                     : "Wrong result on: ") + sfu(counterExample.a));
64  
          print(       "Expected:        " + sfu(counterExample.b));
65  
          if (exc)
66  
            printStackTrace((Throwable) counterExample.c);
67  
          else
68  
            print(     "         Result: " + sfu(counterExample.c));
69  
        }
70  
      }
71  
    print("\nDone. " + (empty(thingsThatWork) ? "Nothing works." : "Things that work: " + joinWithComma(thingsThatWork)));
72  
    print();
73  
  }
74  
}

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: 449 / 1332
Version history: 34 change(s)
Referenced in: [show references]