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

43
LINES

< > BotCompany Repo | #1014418 // Things that should be => Questions (OK)

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

Download Jar. Libraryless. Click here for Pure Java version (7949L/54K).

!7

p-autorestart {
  new Matches m;
  for (S s : printIterate(mL("Things that should be"))) {
    temp tempIndent();
    //if "... should always be ..."
    //printIndent("I'm asking: Are \*$1*/ \*$2*/?");
    
    // Find question
    S q = lookupNL(mechMap("Should => Question"), s);
    if (q == null) continue with print("No question found");
    print(q);
    
    // Find code
    S code = lookupNL(mechMap("Question => Iteration"), q);
    if (code == null) continue with print("No code found");
    print(code);
    
    // Parse Forall
    L<S> tok = javaTok(code);
    int i = tok_forall(tok, m);
    if (i < 0) continue with print("No forall found");
    print("For each " + $1 + ": " + $2);
    
    S innerCode = $2;
    L<S> tok2 = javaTok($1);
    S var = assertIdentifier(lastToken(tok2));
    S entity = trimJoin(dropLastToken(tok2));
    
    S entityList = lookupNL(mechMap("Entity => List that lists all instances"), entity);
    if (entityList == null) continue with print("No entity list found");
    L<S> entities = mL(entityList);
    print("Have " + n2(entities, "entity", "entities") + " of type " + quote(entity) + "!");
    
    new L<S> questions;
    for (S e : entities) {
      printIndent("QUESTION: " + addAndReturn(questions, jreplace(innerCode, var, e)));
    }
    
    appendToMechList("Things that should be | Questions", questions);
  }
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1014418
Snippet name: Things that should be => Questions (OK)
Eternal ID of this version: #1014418/25
Text MD5: 4efcf926a13a09bff2ee157fa4bc2982
Transpilation MD5: 2cd48a8fb2825209af41e5153d50d10d
Author: stefan
Category: javax / a.i.
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-04-21 18:54:47
Source code size: 1421 bytes / 43 lines
Pitched / IR pitched: No / No
Views / Downloads: 587 / 1557
Version history: 24 change(s)
Referenced in: [show references]