From 327e4002b137699b178de51e2904f5e52f1783bf Mon Sep 17 00:00:00 2001 From: Thomas Walker Lynch Date: Tue, 2 Dec 2025 06:31:48 +0000 Subject: [PATCH] . --- shared/authored/dir-walk/JSON.py | 31 ++++++++++++++----------- shared/authored/dir-walk/TapeMachine.py | 13 +++++------ shared/authored/dir-walk/duck.py | 2 +- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/shared/authored/dir-walk/JSON.py b/shared/authored/dir-walk/JSON.py index 3b910f3..f944cfb 100755 --- a/shared/authored/dir-walk/JSON.py +++ b/shared/authored/dir-walk/JSON.py @@ -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)) diff --git a/shared/authored/dir-walk/TapeMachine.py b/shared/authored/dir-walk/TapeMachine.py index 438e00d..0dbccef 100644 --- a/shared/authored/dir-walk/TapeMachine.py +++ b/shared/authored/dir-walk/TapeMachine.py @@ -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 diff --git a/shared/authored/dir-walk/duck.py b/shared/authored/dir-walk/duck.py index cc086d6..d1b3188 100755 --- a/shared/authored/dir-walk/duck.py +++ b/shared/authored/dir-walk/duck.py @@ -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( -- 2.20.1