- "extent": last valid index
"""
- head = tm.address()
- tm.cue_leftmost()
- tape_data = [tm.read(n) for n in range(0 ,tm.extent + 1)]
+ tape = tm.tape()
+ tape_data = [tm.tape()[n] for n in range(0 ,len(tape.length))]
obj = {
"tape" : tape_data
- pretty
"""
p = builtins.print
-
- class DemoTM:
- def __init__(self) -> None:
- self._tape = [1 ,None ,"three"]
- self._head_position = 1 # on the None cell
-
- @property
- def extent(self) -> int: return len(self._tape) - 1
- def address(self) -> int: return self._head_position
- def cue_leftmost(self) -> None: self._head_position = 0
- def can_step(self ,n: int = 1) -> bool:
- return 0 <= self._head_position + n <= self.extent
- def step(self ,n: int = 1) -> None:
- self._head_position += n
- def read(self ,n: int = 0) -> Any:
- return self._tape[self._head_position + n]
- def write(self ,value: Any ,n: int = 0) -> None:
- self._tape[self._head_position + n] = value
- def entangle(self) -> "DemoTM":
- tm = DemoTM()
- tm._tape = self._tape
- tm._head_position = self._head_position
- return tm
-
- tm = DemoTM()
+ tm = TM_ND_A([1 ,None ,"three"])
p("json.is_a_TM examples:")
p(" is_a_TM(tm) ->" ,is_a_TM(tm))
self._head_position: int = 0
# ----------------------------------------------------------------------
- @property
def extent(self) -> int: return self._extent
def tape(self) -> Any: return self._tape
def where(self) -> int: return self._head_position