scope test_BStack /* Goal: Java code with backtracking, like this, to return 4 different values: S color = "black" or "white"; S shape = "circle" or "square"; return "A " + color + " " + shape; */ sclass #OneBranch extends VStackComputableWithStep { S color; void step(VStack stack) { cast stack to BStack; if (step == 0) { step = 1; stack.options(this, ivf1WithToString("black", f -> f.color = "black"), ivf1WithToString("white", f -> f.color = "white")); } else stack.return("Color is " + color); } } sclass #TwoBranches extends VStackComputableWithStep { S color, shape; void step(VStack stack) { cast stack to BStack; if (step == 0) { step = 1; print("Creating options at step 0"); stack.options(this, ivf1WithToString("black", f -> f.color = "black"), ivf1WithToString("white", f -> f.color = "white")); } else if (step == 1) { step = 2; print("Creating options at step 1"); stack.options(this, ivf1WithToString("circle", f -> f.shape = "circle"), ivf1WithToString("square", f -> f.shape = "square")); } else stack.return("A " + color + " " + shape); } } svoid test_BStack() { test_BStack_oneBranch(); test_BStack_twoBranches(); } svoid test_BStack_oneBranch() { assertEqualsVerbose( ll("Color is black", "Color is white"), new BStackComputeAllWithPrintStruct(new OneBranch)!); } svoid test_BStack_twoBranches() { assertEqualsVerbose( ll("A black circle", "A black square", "A white circle", "A white square"), new BStackComputeAllWithPrintStruct(new TwoBranches)!); }