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

37
LINES

< > BotCompany Repo | #1035388 // BStackComputeAllWithPrintStruct

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (24249L/148K).

srecord noeq BStackComputeAllWithPrintStruct<A>(VStack.Computable<A> f) {
  settable int maxBacktracks = 10;
  settable int maxStepsPerBacktrack = 10;
  gettable new L<A> results;
  
  settable IBStack<A> stack;
  
  *(IBStack<A> *stack, VStack.Computable<A> *f) {}
  
  L<A> get() {
    // Make a stack with our computation
    if (stack == null)
      stack = new BStack<A>(f);
    else
      stack.push(f);
  
    repeat maxBacktracks {
      // Get first or next result of function
      A result = stack.nextResultWithPrintStruct(maxStepsPerBacktrack);
      results.add(result);
      print("Result: " + result);
    
      // Ask the stack to backtrack to get another result
      stack = stack.backtrack();
    
      // If there is no more result, print message and exit
      if (stack == null) {
        print("No further result");
        break;
      }
    
      // There is another result, so continue loop
    }
    
    ret results;
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1035388
Snippet name: BStackComputeAllWithPrintStruct
Eternal ID of this version: #1035388/4
Text MD5: 37811febce4609115b87e86e663c3b47
Transpilation MD5: 237382ea191abb48248685c8562018b1
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-05-06 00:57:07
Source code size: 991 bytes / 37 lines
Pitched / IR pitched: No / No
Views / Downloads: 131 / 217
Version history: 3 change(s)
Referenced in: #1003674 - Standard Classes + Interfaces (LIVE continued in #1034167)
#1035427 - pstackComputeAll - get all results from probabilistic function