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).

1  
srecord noeq BStackComputeAllWithPrintStruct<A>(VStack.Computable<A> f) {
2  
  settable int maxBacktracks = 10;
3  
  settable int maxStepsPerBacktrack = 10;
4  
  gettable new L<A> results;
5  
  
6  
  settable IBStack<A> stack;
7  
  
8  
  *(IBStack<A> *stack, VStack.Computable<A> *f) {}
9  
  
10  
  L<A> get() {
11  
    // Make a stack with our computation
12  
    if (stack == null)
13  
      stack = new BStack<A>(f);
14  
    else
15  
      stack.push(f);
16  
  
17  
    repeat maxBacktracks {
18  
      // Get first or next result of function
19  
      A result = stack.nextResultWithPrintStruct(maxStepsPerBacktrack);
20  
      results.add(result);
21  
      print("Result: " + result);
22  
    
23  
      // Ask the stack to backtrack to get another result
24  
      stack = stack.backtrack();
25  
    
26  
      // If there is no more result, print message and exit
27  
      if (stack == null) {
28  
        print("No further result");
29  
        break;
30  
      }
31  
    
32  
      // There is another result, so continue loop
33  
    }
34  
    
35  
    ret results;
36  
  }
37  
}

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: 132 / 220
Version history: 3 change(s)
Referenced in: [show references]