diff --git a/packages/web/docs/core-schemas/programs/tracing-examples.ts b/packages/web/docs/core-schemas/programs/tracing-examples.ts index 12013c33e..08cb5f8df 100644 --- a/packages/web/docs/core-schemas/programs/tracing-examples.ts +++ b/packages/web/docs/core-schemas/programs/tracing-examples.ts @@ -72,18 +72,16 @@ code { result = add(3, 4); }`; -export const recursiveCount = `name Counter; +export const mutualRecursion = `name EvenOdd; define { - function succ(n: uint256) -> uint256 { - return n + 1; + function isEven(n: uint256) -> uint256 { + if (n == 0) { return 1; } + else { return isOdd(n - 1); } }; - function count(n: uint256, target: uint256) -> uint256 { - if (n < target) { - return count(succ(n), target); - } else { - return n; - } + function isOdd(n: uint256) -> uint256 { + if (n == 0) { return 0; } + else { return isEven(n - 1); } }; } @@ -96,5 +94,5 @@ create { } code { - result = count(0, 5); + result = isEven(4); }`; diff --git a/packages/web/docs/core-schemas/programs/tracing.mdx b/packages/web/docs/core-schemas/programs/tracing.mdx index 125ae3c8f..a22c6551d 100644 --- a/packages/web/docs/core-schemas/programs/tracing.mdx +++ b/packages/web/docs/core-schemas/programs/tracing.mdx @@ -10,7 +10,7 @@ import { thresholdCheck, multipleStorageSlots, functionCallAndReturn, - recursiveCount, + mutualRecursion, } from "./tracing-examples"; # Tracing execution @@ -96,15 +96,15 @@ trace. Watch for **invoke** contexts on the JUMP into `add` and source={functionCallAndReturn} /> -Recursive calls produce nested invoke/return pairs. In this -example, `count` calls `succ` and then calls itself repeatedly -until `n` reaches `target`. Each recursive call adds a frame +Mutual recursion produces alternating invoke/return pairs. In +this example, `isEven` and `isOdd` call each other, bouncing +back and forth until `n` reaches zero. Each call adds a frame to the call stack: As you step through, three phases are visible: