Demonstration of TraceTrancform, ListFunction, and IndexBase

ID: 147

				
					using uCalcSoftware;

var uc = new uCalc();
var t = uc.NewTransformer();
t.DefaultRuleSet.RewindOnChange = true;
t.FromTo("AddUp({x})", "{x}");
t.FromTo("AddUp({x}, {y})", "({x} + AddUp({y}))");

Console.WriteLine(t.TraceTransform("AddUp(1, 2, 3, 4)").ListFunction("$'Step {Index}: {x}\n'"));

// 0 is the default IndexBase.  Here we will use 1 instead.
// So it will now start with "Step: 1" instead of "Step: 0"
Console.WriteLine("--- Now with IndexBase = 1 ---");
Console.WriteLine(t.TraceTransform("AddUp(1, 2, 3, 4)").ListFunction("$'Step {Index} of {Count}: {x}\n'").IndexBase(1));
				
			
Step 0: AddUp(1, 2, 3, 4)
Step 1: (1 + AddUp(2, 3, 4))
Step 2: (1 + (2 + AddUp(3, 4)))
Step 3: (1 + (2 + (3 + AddUp(4))))
Step 4: (1 + (2 + (3 + 4)))

--- Now with IndexBase = 1 ---
Step 1 of 5: AddUp(1, 2, 3, 4)
Step 2 of 5: (1 + AddUp(2, 3, 4))
Step 3 of 5: (1 + (2 + AddUp(3, 4)))
Step 4 of 5: (1 + (2 + (3 + AddUp(4))))
Step 5 of 5: (1 + (2 + (3 + 4)))
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   auto t = uc.NewTransformer();
   t.DefaultRuleSet().RewindOnChange(true);
   t.FromTo("AddUp({x})", "{x}");
   t.FromTo("AddUp({x}, {y})", "({x} + AddUp({y}))");

   cout << t.TraceTransform("AddUp(1, 2, 3, 4)").ListFunction("$'Step {Index}: {x}\n'") << endl;

   // 0 is the default IndexBase.  Here we will use 1 instead.
   // So it will now start with "Step: 1" instead of "Step: 0"
   cout << "--- Now with IndexBase = 1 ---" << endl;
   cout << t.TraceTransform("AddUp(1, 2, 3, 4)").ListFunction("$'Step {Index} of {Count}: {x}\n'").IndexBase(1) << endl;
}
				
			
Step 0: AddUp(1, 2, 3, 4)
Step 1: (1 + AddUp(2, 3, 4))
Step 2: (1 + (2 + AddUp(3, 4)))
Step 3: (1 + (2 + (3 + AddUp(4))))
Step 4: (1 + (2 + (3 + 4)))

--- Now with IndexBase = 1 ---
Step 1 of 5: AddUp(1, 2, 3, 4)
Step 2 of 5: (1 + AddUp(2, 3, 4))
Step 3 of 5: (1 + (2 + AddUp(3, 4)))
Step 4 of 5: (1 + (2 + (3 + AddUp(4))))
Step 5 of 5: (1 + (2 + (3 + 4)))
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t = uc.NewTransformer()
      t.DefaultRuleSet.RewindOnChange = true
      t.FromTo("AddUp({x})", "{x}")
      t.FromTo("AddUp({x}, {y})", "({x} + AddUp({y}))")
      
      Console.WriteLine(t.TraceTransform("AddUp(1, 2, 3, 4)").ListFunction("$'Step {Index}: {x}"+vbCrLf+"'"))
      
      '// 0 is the default IndexBase.  Here we will use 1 instead.
      '// So it will now start with "Step: 1" instead of "Step: 0"
      Console.WriteLine("--- Now with IndexBase = 1 ---")
      Console.WriteLine(t.TraceTransform("AddUp(1, 2, 3, 4)").ListFunction("$'Step {Index} of {Count}: {x}"+vbCrLf+"'").IndexBase(1))
   End Sub
End Module
				
			
Step 0: AddUp(1, 2, 3, 4)
Step 1: (1 + AddUp(2, 3, 4))
Step 2: (1 + (2 + AddUp(3, 4)))
Step 3: (1 + (2 + (3 + AddUp(4))))
Step 4: (1 + (2 + (3 + 4)))

--- Now with IndexBase = 1 ---
Step 1 of 5: AddUp(1, 2, 3, 4)
Step 2 of 5: (1 + AddUp(2, 3, 4))
Step 3 of 5: (1 + (2 + AddUp(3, 4)))
Step 4 of 5: (1 + (2 + (3 + AddUp(4))))
Step 5 of 5: (1 + (2 + (3 + 4)))