(* Simple test of lifecycle formula on small noun *) open Nock_lib let () = (* Test subject: [[formula] payload] *) (* Formula: [7 [0 3] [0 1]] - compose: *[payload [0 1]] returns payload *) (* Payload: [42 99] *) let formula_slot2 = Noun.cell (Noun.atom 7) (Noun.cell (Noun.cell (Noun.atom 0) (Noun.atom 3)) (Noun.cell (Noun.atom 0) (Noun.atom 1))) in let payload = Noun.cell (Noun.atom 42) (Noun.atom 99) in let subject = Noun.cell formula_slot2 payload in (* Lifecycle formula: [2 [0 3] [0 2]] *) let formula = 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 "Subject: [[7 [0 3] [0 1]] [42 99]]\n"; Printf.printf "Subject mug: 0x%08lx\n" (Noun.mug subject); Printf.printf "Formula: [2 [0 3] [0 2]]\n"; Printf.printf "Formula mug: 0x%08lx\n\n" (Noun.mug formula); Printf.printf "Slot 2 of subject (formula): [7 [0 3] [0 1]] (mug=0x%08lx)\n" (Noun.mug formula_slot2); Printf.printf "Slot 3 of subject (payload): [42 99] (mug=0x%08lx)\n\n" (Noun.mug payload); Printf.printf "Running nock...\n"; Printf.printf "This should compute: *[[42 99] [7 [0 3] [0 1]]]\n"; Printf.printf "Which is: *[99 [0 1]] = 99\n\n"; let result = Nock.nock_on subject formula in Printf.printf "Result mug: 0x%08lx\n" (Noun.mug result); Printf.printf "Result: %s\n" (match result with | Noun.Atom { z; _ } -> Z.to_string z | Noun.Cell _ -> "cell")