.
authorThomas Walker Lynch <eknp9n@reasoningtechnology.com>
Tue, 2 Dec 2025 06:31:48 +0000 (06:31 +0000)
committerThomas Walker Lynch <eknp9n@reasoningtechnology.com>
Tue, 2 Dec 2025 06:31:48 +0000 (06:31 +0000)
shared/authored/dir-walk/JSON.py
shared/authored/dir-walk/TapeMachine.py
shared/authored/dir-walk/duck.py

index 3b910f3..f944cfb 100755 (executable)
@@ -5,7 +5,11 @@ from __future__ import annotations
 from typing import Any
 import json as pyjson
 import duck
+import TapeMachine
+
 import builtins
+p = builtins.print
+
 
 # ----------------------------------------------------------------------
 def to_JSON_TM(
@@ -21,15 +25,15 @@ def to_JSON_TM(
   """
 
   tape = tm.tape()
-  tape_data = [tm.tape()[n] for n in range(0 ,len(tape.length))]
+  tape_data = [tape[n] for n in range(len(tape))]
 
   obj = {
     "tape"  : tape_data
-    ,"head" : tm.address()
-    ,"extent": tm.extent
+    ,"head" : tm.where()
+    ,"extent": tm.extent()
   }
 
-  return pyjson.dumps(tm ,ensure_ascii=False)
+  return pyjson.dumps(obj ,ensure_ascii=False)
 
 
 # ----------------------------------------------------------------------
@@ -45,7 +49,7 @@ def print_TM(
   out = pyjson.dumps(parsed ,indent=2 ,ensure_ascii=False)
   prefix = " " * indent
   for line in out.split("\n"):
-    print(prefix + line)
+    p(prefix + line)
 
 
 # ----------------------------------------------------------------------
@@ -71,7 +75,7 @@ def pretty_TM(
   while True:
     v = tm1.read()
 
-    if tm1.address() == tm0.address():
+    if tm1.where() == tm0.where():
       mark = "*"
     elif v is None:
       mark = "␀"
@@ -79,7 +83,7 @@ def pretty_TM(
       mark = " "
 
     s = "" if v is None else str(v)
-    print(f"{prefix}{mark}{s}")
+    p(f"{prefix}{mark}{s}")
 
     if not tm1.can_step(): break
     tm1.step()
@@ -97,7 +101,7 @@ def is_a_TM(
       read
       can_step
       step
-      address
+      where
 
   These are exactly what pretty_TM() uses.
   """
@@ -108,7 +112,7 @@ def is_a_TM(
     ,"read"
     ,"can_step"
     ,"step"
-    ,"address"
+    ,"where"
   )
 
 # ----------------------------------------------------------------------
@@ -127,7 +131,7 @@ def print(
     print_TM(value ,indent)
   else:
     prefix = " " * indent
-    print(prefix + str(value))
+    p(prefix + str(value))
 
 
 # ----------------------------------------------------------------------
@@ -152,7 +156,7 @@ def pretty(
 
   # JSON primitive: str, int, float, bool, None
   if isinstance(value ,(str ,int ,float ,bool)) or value is None:
-    print(prefix + str(value))
+    p(prefix + str(value))
     return
 
   # Try to JSON-dump; if it fails, wrap in {"value": repr}
@@ -166,7 +170,7 @@ def pretty(
   # Pretty-print JSON
   out = pyjson.dumps(parsed ,indent=2 ,ensure_ascii=False)
   for line in out.split("\n"):
-    print(prefix + line)
+    p(prefix + line)
 
 
 
@@ -182,8 +186,7 @@ def CLI() -> None:
     - print
     - pretty
   """
-  p = builtins.print
-  tm = TM_ND_A([1 ,None ,"three"])
+  tm = TapeMachine.TM_ND_A([1 ,None ,"three"])
 
   p("json.is_a_TM examples:")
   p("  is_a_TM(tm)   ->" ,is_a_TM(tm))
index 438e00d..0dbccef 100644 (file)
@@ -40,11 +40,10 @@ class TM_ND_A:
   def         write(self ,value: Any ,n: int = 0) -> None: self._tape[self._head_position + n] = value
 
   # because this is an ND machine it is safe to entangle heads
-  def entangle(self) -> "TapeMachine":
-    """Create an entangled copy: shared tape, independent head_position."""
-    new_tm = object.__new__(TapeMachine)
-    new_tm._tape = self._tape
-    new_tm._length = self._length
-    new_tm._head_position = self._head_position
-    return new_tm
+  def entangle(self) -> "TM_ND_A":
+    tm = object.__new__(TM_ND_A)
+    tm._tape = self._tape
+    tm._extent = self._extent
+    tm._head_position = self._head_position
+    return tm
 
index cc086d6..d1b3188 100755 (executable)
@@ -2,7 +2,7 @@
 # -*- mode: python; coding: utf-8; python-indent-offset: 2; indent-tabs-mode: nil -*-
 
 from typing import Any, Optional
-
+import builtins
 
 # ----------------------------------------------------------------------
 def class_of(