diff options
Diffstat (limited to 'js/scripting-lang/tests/turing-completeness/02_recursion_demo.txt')
-rw-r--r-- | js/scripting-lang/tests/turing-completeness/02_recursion_demo.txt | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/js/scripting-lang/tests/turing-completeness/02_recursion_demo.txt b/js/scripting-lang/tests/turing-completeness/02_recursion_demo.txt new file mode 100644 index 0000000..9d25b1c --- /dev/null +++ b/js/scripting-lang/tests/turing-completeness/02_recursion_demo.txt @@ -0,0 +1,24 @@ +/* Recursion Demonstration */ + +..out "=== Recursion: Unlimited Computation Power ==="; + +/* Simple countdown */ +countdown : n -> when n is 0 then "zero" _ then countdown (n - 1); +count_result : countdown 3; +..assert count_result = "zero"; +..out "Countdown: reaches zero"; + +/* Factorial */ +fact : n -> when n is 0 then 1 _ then n * (fact (n - 1)); +fact5 : fact 5; +..assert fact5 = 120; +..out "Factorial(5) = 120"; + +/* Power function */ +pow : x n -> when n is 0 then 1 _ then x * (pow x (n - 1)); +pow_result : pow 2 5; +..assert pow_result = 32; +..out "Power(2, 5) = 32"; + +..out "---"; +..out "✅ Recursion enables unlimited computation depth"; \ No newline at end of file |