Libraryless. Click here for Pure Java version (2069L/15K/48K).
1 | !636 |
2 | !standard functions |
3 | !1000346 // "case" as a variable name |
4 | |
5 | !class _javax 19 |
6 | |
7 | main { |
8 | static Class solver; |
9 | |
10 | psvm { |
11 | solver = hotwire("#704"); // embed solver! |
12 | set(solver, "testJava", false); |
13 | new Learner lNumFiles; |
14 | File dir = makeTempDirectory(); |
15 | |
16 | for (int i = 0; i < 5; i++) { |
17 | create(dir, "file" + (i+1)); |
18 | String in = ls(dir.getPath()); |
19 | Integer out = i+1; |
20 | lNumFiles.learn(in, out); |
21 | } |
22 | |
23 | lNumFiles.done(); |
24 | |
25 | String home = System.getProperty("user.home"); |
26 | System.out.println("Files in home directory (" + home + "): " + lNumFiles.processIn(ls(home))); |
27 | } |
28 | |
29 | static File makeTempDirectory() { |
30 | return _javax.TempDirMaker_make(); |
31 | } |
32 | |
33 | static class Learner { |
34 | new StringBuilder buf; |
35 | int count; |
36 | Object case; |
37 | |
38 | void learn(String in, Object out) { |
39 | buf.append("in: " + quote(in) + "\n"); |
40 | buf.append("out: " + quote(String.valueOf(out)) + "\n"); |
41 | if (++count == 2) buf.append("--\n"); |
42 | } |
43 | |
44 | void done() { |
45 | case = call(solver, "parse", buf.toString()); |
46 | call(solver, "calculate", case); |
47 | } |
48 | |
49 | Object processIn(String in) { |
50 | return call(case, "processIn", in); |
51 | } |
52 | } |
53 | |
54 | static void create(File dir, String name) ctex { |
55 | saveTextFile(new File(dir, name).getPath(), ""); |
56 | } |
57 | |
58 | static String run(String cmd) ctex { |
59 | return _javax.backtick(cmd); |
60 | } |
61 | |
62 | static String ls(String dir) { |
63 | return run("ls " + dir); |
64 | } |
65 | } |
download show line numbers debug dex old transpilations
Travelled to 16 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, hxnwyiuffukg, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt
ID | Author/Program | Comment | Date |
---|---|---|---|
817 | #1000610 (pitcher) | 2015-08-19 17:22:04 | |
793 | stefan | Featured: http://tinybrain.blog.de/2015/08/19/tinybrain-learns-to-use-unix-commands-20708263/ | 2015-08-19 17:29:41 |
790 | stefan | It actually works :)
"file1 file2 file3 file4 file5 " => "5" == CASE direct == Full examples: 5, splitPoint: 2, half examples: 0 Solved! . LChange(f=RFToLines, base=LFixedFunction(f=FLength)) Files in home directory (/root): 68 | 2015-08-19 17:17:07 |
789 | #1000604 (pitcher) | 2015-08-20 15:28:24 |
Snippet ID: | #706 |
Snippet name: | Learn to use "ls" |
Eternal ID of this version: | #706/1 |
Text MD5: | f5c8e2393c86209230330b06e715d2f6 |
Transpilation MD5: | 19e4665efda584ee498bec5a4912d715 |
Author: | stefan |
Category: | |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2015-08-20 18:03:24 |
Source code size: | 1518 bytes / 65 lines |
Pitched / IR pitched: | No / Yes |
Views / Downloads: | 935 / 979 |
Referenced in: | [show references] |