summaryrefslogtreecommitdiff
path: root/ocaml/test/old/test_life_formula.ml
diff options
context:
space:
mode:
Diffstat (limited to 'ocaml/test/old/test_life_formula.ml')
-rw-r--r--ocaml/test/old/test_life_formula.ml48
1 files changed, 48 insertions, 0 deletions
diff --git a/ocaml/test/old/test_life_formula.ml b/ocaml/test/old/test_life_formula.ml
new file mode 100644
index 0000000..722154b
--- /dev/null
+++ b/ocaml/test/old/test_life_formula.ml
@@ -0,0 +1,48 @@
+(* Test lifecycle formula on atom 0 *)
+
+open Nock_lib
+
+let () =
+ Printf.printf "Testing lifecycle formula [2 [0 3] [0 2]] on atom 0\n\n%!";
+
+ (* Build the lifecycle formula *)
+ let lyf = Noun.cell (Noun.atom 2)
+ (Noun.cell
+ (Noun.cell (Noun.atom 0) (Noun.atom 3))
+ (Noun.cell (Noun.atom 0) (Noun.atom 2))) in
+
+ Printf.printf "Formula: [2 [0 3] [0 2]]\n%!";
+ Printf.printf "Subject: 0 (null)\n\n%!";
+
+ (* Try running it *)
+ begin try
+ let result = Nock.nock_on (Noun.atom 0) lyf in
+ Printf.printf "✓ SUCCESS! Result: %s\n%!" (match result with
+ | Noun.Atom z -> Z.to_string z
+ | Noun.Cell _ -> "[cell]")
+ with
+ | Noun.Exit ->
+ Printf.printf "✗ FAILED with Nock Exit\n%!";
+
+ (* Let's trace through the formula step by step *)
+ Printf.printf "\nStep-by-step trace:\n%!";
+ Printf.printf "Formula: *[0 [2 [0 3] [0 2]]]\n%!";
+ Printf.printf "Opcode 2: *[a [2 b c]] = *[*[a b] *[a c]]\n%!";
+ Printf.printf " b = [0 3]\n%!";
+ Printf.printf " c = [0 2]\n%!";
+ Printf.printf "\n*[a b] = *[0 [0 3]] = slot 3 of atom 0\n%!";
+
+ (* Try slot 3 on atom 0 *)
+ begin try
+ let s3 = Noun.slot (Z.of_int 3) (Noun.atom 0) in
+ Printf.printf " slot 3 of 0 = %s (unexpected!)\n%!" (match s3 with
+ | Noun.Atom z -> Z.to_string z
+ | Noun.Cell _ -> "[cell]")
+ with Noun.Exit ->
+ Printf.printf " slot 3 of 0 = ERROR (as expected)\n%!"
+ end;
+
+ Printf.printf "\nThis proves the formula CANNOT work on atom 0!\n%!"
+ | e ->
+ Printf.printf "✗ FAILED with: %s\n%!" (Printexc.to_string e)
+ end