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

94
LINES

< > BotCompany Repo | #1008522 // Analysis Tree [Include]

JavaX fragment (include)

abstract sclass Op extends F1 {}

sclass ApplySF extends Op {
  S name;
  int pos;
  L args;
  
  *() {}
  *(S *name) { args = ll(); }
  *(S *name, int *pos, O... args) { this.args = asList(args); }
  
  O get(O o) {
    L args = cloneList(this.args);
    args.add(pos, o);
    ret makeAndCall(name, toObjectArray(args));
  }
}

sclass ApplyFunc extends Op {
  S code;
  
  *() {}
  *(S code) { this.code = trim(code); }
  
  O get(O o) {
    ret evalFuncWithImportExport(code, o);
  }
}

sclass MapSF extends Op {
  Op op;

  *() {}
  *(Op *op) {}

  O get(O o) {
    ret map(op, (Collection) o);
  }
}

sclass Operation {
  Op op;
  Data result;
  
  *() {}
  *(Op *op) {}
}

sclass Data {
  O data;
  PersistableThrowable error;
  new L<Operation> operations;
  
  *() {}
  *(O *data) {}
}

static Data initial;

svoid printTree(Data data) {
  if (data == null) { print("-"); ret; }
  if (data.error != null) print("Error: " + data.error);
  else {
    print_noNL("Data: ");
    if (data.data instanceof Collection)
      print_noNL("[" + l(data.data) + "] ");
    else if (data.data instanceof S) {
      int n = numLines((S) data.data);
      if (n > 1) print_noNL("[" + n + " lines] ");
    }
    print(shorten(struct(data.data)));
  }
  print_threadIndentPlus();
  try {
    int i = 0;
    for (Operation op : data.operations) {
      print("Op " + (++i) + ": " + struct(op.op));
      printTree(op.result);
    }
  } finally {
    print_threadIndentMinus();
  }
}

static Data doOp(Data data, Op theOp) {
  Operation op = new Operation(theOp);
  data.operations.add(op);
  try {
    op.result = new Data(op.op.get(data.data));
  } catch e {
    op.result = nu(Data, error := persistableThrowable(e));
  }
  ret op.result;
}

Author comment

Began life as a copy of #1008513

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1008522
Snippet name: Analysis Tree [Include]
Eternal ID of this version: #1008522/9
Text MD5: 90de1a0c244b3a29493a1d28ab5207c8
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-05-21 15:26:00
Source code size: 1826 bytes / 94 lines
Pitched / IR pitched: No / No
Views / Downloads: 439 / 879
Version history: 8 change(s)
Referenced in: #1008513 - Analysis Tree [WORKS]
#1008523 - Analysis Tree Persistence Test [WORKS]
#1008524 - Diff The Inq [OK]