diff options
author | polwex <polwex@sortug.com> | 2025-10-06 17:07:33 +0700 |
---|---|---|
committer | polwex <polwex@sortug.com> | 2025-10-06 17:07:33 +0700 |
commit | a4615148975bed241ae26ffa2655dc9c407107d8 (patch) | |
tree | bd127b13f0027cd2870b8f016c5658465785d3df /ocaml/test/test_life_formula.ml | |
parent | 256376afffe66faa239a6a6aaebb8f68a9c6cbe4 (diff) |
maybe now maybe now
Diffstat (limited to 'ocaml/test/test_life_formula.ml')
-rw-r--r-- | ocaml/test/test_life_formula.ml | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/ocaml/test/test_life_formula.ml b/ocaml/test/test_life_formula.ml new file mode 100644 index 0000000..722154b --- /dev/null +++ b/ocaml/test/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 |