Warning: session_start(): open(/var/lib/php/sessions/sess_l3popuo1v9sa98o0ok251i4pgm, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
!7
!include once #1017126 // transpileRaw
sclass DevelopFromExamples > DynTextArea {
S whatToTry;
transient ReliableSingleThread rst = new(r think);
transient volatile PlanInMotion currentPlan;
transient int delay = 0; //2000; // to see stuff
JComponent visualize() {
final JLabel lblStatus = jlabel();
awtEvery(lblStatus, 100, r { main.setText(lblStatus, planStatus()) });
ret withCenteredButtons(centerAndSouthWithMargins(
jhsplit(super.visualize(), dm_printLogComponent()),
vstackWithSpacing(
jsection("Stuff to try", onEnter(dm_fieldTextField('whatToTry), rst)),
lblStatus
)), "Fresh", rThread fresh, "Think", rst, "[disabled] Cancel", r cancel);
}
S planStatus() {
PlanInMotion plan = currentPlan;
if (plan == null) ret " ";
ret "Steps done: " + l(plan.doneSteps) + ". Steps planned: " + l(plan.plannedSteps);
}
void cancel {
PlanInMotion plan = currentPlan;
if (plan != null) plan.cancelled = true;
}
void fresh {
dm_refreshTranspiler();
forgetTranspiledStandardFunctions(words(whatToTry));
loadFunctions_clearCache();
rst.trigger();
}
class Thinker {
new PlanInMotion plan;
new L> examples;
F2 equalsFunction;
new LinkedHashSet thingsThatWork;
void go {
currentPlan = plan;
temp tempAfterwards(r { currentPlan = null; });
temp tempEnableButton(findButton(dm_vis(), "Cancel"));
clearPrintLog();
loadFunctions_preferDiskCache();
S text = rtrimAll(getText());
Pair examplesFile = ai_makeExamplesFile(text);
if (examplesFile.b) print("Wrote: " + f2s(examplesFile.a));
bool eqic = false;
L lines = tlftj(text);
if (eq(first(lines), "splitAtEmptyLines"))
lines = splitAtEmptyLines(text);
for (S line : lines) pcall {
if (eqic(line, "eqic")) eqic = true;
L 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"));
equalsFunction = eqic
? func(O a, O b) -> Bool { eqic((S) a, (S) b) }
: func(O a, O b) -> Bool { eq(a, b) };
// Make plan
fL functionsToTry = uniquify(standardFunctionsOnly(words(whatToTry)));
for (fS s : functionsToTry) addToPlan(s);
for (Runnable r : plan.master())
callF(r);
print("\n" + (plan.cancelled ? "Cancelled" : "Done") + " after " + n2(plan.doneSteps, "step") + ". " +
(empty(thingsThatWork) ? (plan.cancelled ? "Nothing worked so far." : "Nothing works.") : (plan.cancelled ? "Things that worked so far: " : "Things that work: ") + joinWithComma(thingsThatWork)));
print();
}
void addToPlan(S s) {
plan.add(r {
sleep(delay);
F1 f = functionFromText(s);
func(S in) -> S { struct(callAndMake_orDirect(s, unstruct(in))) };
T3 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));
}
});
}
}
void think {
if (currentPlan != null) ret;
new Thinker().go();
}
F1 functionFromText(fS s) {
ret func(S in) -> S { struct(callAndMake_orDirect(s, unstruct(in))) };
}
}