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

65
LINES

< > BotCompany Repo | #706 // Learn to use "ls"

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (2069L/15K/48K).

!636
!standard functions
!1000346 // "case" as a variable name

!class _javax 19

main {
  static Class solver;
  
  psvm {
    solver = hotwire("#704"); // embed solver!
    set(solver, "testJava", false);
    new Learner lNumFiles;
    File dir = makeTempDirectory();

    for (int i = 0; i < 5; i++) {
      create(dir, "file" + (i+1));
      String in = ls(dir.getPath());
      Integer out = i+1;
      lNumFiles.learn(in, out);
    }

    lNumFiles.done();
    
    String home = System.getProperty("user.home");
    System.out.println("Files in home directory (" + home + "): " + lNumFiles.processIn(ls(home)));
  }

  static File makeTempDirectory() {
    return _javax.TempDirMaker_make();
  }

  static class Learner {
    new StringBuilder buf;
    int count;
    Object case;
    
    void learn(String in, Object out) {
      buf.append("in: " + quote(in) + "\n");
      buf.append("out: " + quote(String.valueOf(out)) + "\n");
      if (++count == 2) buf.append("--\n");
    }

    void done() {
      case = call(solver, "parse", buf.toString());
      call(solver, "calculate", case);
    }
    
    Object processIn(String in) {
      return call(case, "processIn", in);
    }
  }

  static void create(File dir, String name) ctex {
    saveTextFile(new File(dir, name).getPath(), "");
  }

  static String run(String cmd) ctex {
    return _javax.backtick(cmd);
  }
  
  static String ls(String dir) {
    return run("ls " + dir);
  }
}

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

Comments [hide]

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

add comment

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