summaryrefslogtreecommitdiff
path: root/ocaml/lib/nock.ml
diff options
context:
space:
mode:
authorpolwex <polwex@sortug.com>2025-10-06 21:27:31 +0700
committerpolwex <polwex@sortug.com>2025-10-06 21:27:31 +0700
commit6ce2c5919f36776fe8aea711b94bbd2d64c8207a (patch)
treef79796c7ea188ed25a2bb0642bebe6dc0d05409c /ocaml/lib/nock.ml
parentbcbd110b17b3c9bcb0e28e28fd33388f1c954a27 (diff)
going in circles man
Diffstat (limited to 'ocaml/lib/nock.ml')
-rw-r--r--ocaml/lib/nock.ml90
1 files changed, 74 insertions, 16 deletions
diff --git a/ocaml/lib/nock.ml b/ocaml/lib/nock.ml
index 670b12b..28cecf9 100644
--- a/ocaml/lib/nock.ml
+++ b/ocaml/lib/nock.ml
@@ -64,14 +64,65 @@ let rec nock_on bus fol =
| 2 ->
(* *[subject formula new_subject] - evaluate with new subject *)
+ (* C evaluates tail first, then head - must match this order! *)
if not (is_cell gal) then (
if should_trace then Printf.eprintf "[Nock:%d] Op2: gal not cell\n%!" !trace_depth;
raise Exit
);
- let b_gal = head gal in
let c_gal = tail gal in
- let seb = nock_on bus b_gal in
- let nex = nock_on bus c_gal in
+ let b_gal = head gal in
+
+ (* Debug: log what formulas we're evaluating *)
+ if should_trace && !trace_depth <= 2 then begin
+ Printf.eprintf "[Nock:%d-DEBUG] Op2 about to evaluate:\n%!" !trace_depth;
+ Printf.eprintf " b_gal (for subject): %s\n%!"
+ (if is_cell b_gal then
+ let h = head b_gal in
+ if is_atom h then
+ (match h with Atom n -> "[" ^ Z.to_string n ^ " ...]" | _ -> "[?]")
+ else "[cell ...]"
+ else "not-cell");
+ Printf.eprintf " c_gal (for formula): %s\n%!"
+ (if is_cell c_gal then
+ let h = head c_gal in
+ if is_atom h then
+ (match h with Atom n -> "[" ^ Z.to_string n ^ " ...]" | _ -> "[?]")
+ else "[cell ...]"
+ else "not-cell")
+ end;
+
+ let nex = nock_on bus c_gal in (* Tail first like C *)
+
+ if should_trace && !trace_depth <= 2 then begin
+ Printf.eprintf "[Nock:%d-DEBUG] Op2 computed formula:\n%!" !trace_depth;
+ Printf.eprintf " nex opcode: %s\n%!"
+ (if is_cell nex then
+ let h = head nex in
+ if is_atom h then
+ (match h with Atom n -> Z.to_string n | _ -> "?")
+ else "cell"
+ else "atom")
+ end;
+
+ let seb = nock_on bus b_gal in (* Head second like C *)
+
+ if should_trace && !trace_depth <= 2 then begin
+ Printf.eprintf "[Nock:%d-DEBUG] Op2 FINAL CHECK:\n%!" !trace_depth;
+ Printf.eprintf " seb (subject) from b_gal=[0 %s]\n%!"
+ (match b_gal with
+ | Cell (Atom _, Atom n) -> Z.to_string n
+ | _ -> "?");
+ Printf.eprintf " nex (formula) from c_gal=[0 %s], nex opcode = %s\n%!"
+ (match c_gal with
+ | Cell (Atom _, Atom n) -> Z.to_string n
+ | _ -> "?")
+ (if is_cell nex then
+ let h = head nex in
+ if is_atom h then (match h with Atom n -> Z.to_string n | _ -> "?")
+ else "cell"
+ else "NOT-A-CELL!")
+ end;
+
nock_on seb nex
| 3 ->
@@ -165,21 +216,28 @@ let rec nock_on bus fol =
| 10 ->
(* hint - in reference implementation, hints are mostly ignored *)
- if should_trace then Printf.eprintf "[Nock:%d] Op10: hint (gal is %s)\n%!" !trace_depth
- (if is_cell gal then "cell" else "atom");
+ (* Two forms: [10 [[b c] d]] and [10 [b c]] *)
+ if not (is_cell gal) then (
+ if should_trace then Printf.eprintf "[Nock:%d] Op10: gal not cell\n%!" !trace_depth;
+ raise Exit
+ );
+ let p_gal = head gal in (* First part: hint tag or [tag value] *)
+ let q_gal = tail gal in (* Second part: formula *)
+
+ (* Determine which form we have *)
let nex =
- if is_cell gal then begin
- (* [[hint-tag hint-value] formula] *)
- let hint_part = head gal in
- let formula = tail gal in
- if should_trace then Printf.eprintf "[Nock:%d] Op10: hint_part is %s, formula is %s\n%!" !trace_depth
- (if is_cell hint_part then "cell" else "atom")
- (if is_cell formula then "cell" else "atom");
- formula
+ if is_cell p_gal then begin
+ (* Form 1: [10 [[b c] d]] - full hint with value *)
+ (* p_gal = [b c], q_gal = d (formula) *)
+ if should_trace then Printf.eprintf "[Nock:%d] Op10: full hint, formula is %s\n%!" !trace_depth
+ (if is_cell q_gal then "cell" else "atom");
+ q_gal (* Execute the formula, ignore hint *)
end else begin
- (* [hint-tag formula] where hint-value is implicit *)
- if should_trace then Printf.eprintf "[Nock:%d] Op10: implicit hint\n%!" !trace_depth;
- gal
+ (* Form 2: [10 [b c]] - hint with implicit value *)
+ (* p_gal = b (hint tag), q_gal = c (formula) *)
+ if should_trace then Printf.eprintf "[Nock:%d] Op10: simple hint, formula is %s\n%!" !trace_depth
+ (if is_cell q_gal then "cell" else "atom");
+ q_gal (* Execute the formula, ignore hint *)
end
in
nock_on bus nex