
Raganwald's Tooling for Turing Machines - matt4077
https://leanpub.com/tooling
======
gwern
(So is this April Fools or not?)

~~~
braythwayt
Not a joke.

------
braythwayt
Author here. This is a work-in-progress.

Ask Me Anything.

~~~
defen
Great idea for a book.

1) What "level" of programmer will this be pitched at? e.g. No experience
programming, regular "working programmer" with no theory background, someone
with an undergrad CS degree, someone with 20 years of industry experience,
etc.

2) Have you decided on the Turing machine yet? Will the interpreter be
provided as a "given" or will the reader have to write an interpreter in a
higher-level language first? e.g. I'm imagining something that reads a state
table description and a representation of an input tape, performs the work,
and then hopefully stops and outputs the tape.

~~~
braythwayt
Like JavaScript Allongé, I am planning for it to be readable by someone with
just a smattering of programming familiarity. But also like JavaScript
Allongé, I hope for a fairly substantial learning slope.

I don’t imagine writing the first interpreter will be onerous. Here’s one I
wrote specifically to be “pessimum” without being gratuitously so:

    
    
      const aMachine = (() => {
        const HALT = 'HALT';
        const LEFT = 2;
        const RIGHT = 3;
    
        function kiss4({ description, tape: _tape }) {
          const tape = Array.from(_tape);
    
          let tapeIndex = 0;
          let currentState = description[0][0];
    
          while (true) {
            if (tapeIndex < 0) {
              console.log('moved off the left edge of the world');
              console.log({ tapeIndex, currentState, currentMark, tape: tape.join(' ') });
              return tape;
            }
    
            const currentMark = tape[tapeIndex];
    
            const rule = description.find(([state, mark]) => state === currentState && mark === currentMark);
    
            if (rule == null) {
              if (currentState !== HALT) {
                console.log('no rule for this state and mark');
                console.log({ tapeIndex, currentState, currentMark, tape: tape.join(' ') });
              }
              return tape;
            }
    
            const [_, __, nextState, action] = rule;
    
            if (action === LEFT) {
              --tapeIndex;
            } else if (action === RIGHT) {
              ++tapeIndex;
              if (tape[tapeIndex] == null) tape[tapeIndex] = 0;
            } else if ([0, 1].includes(action)) {
              tape[tapeIndex] = action;
            }
    
            currentState = nextState;
          }
        }
    
        return Object.assign(
          ({ description, tape = [] }) => kiss4({ description, tape }),
          { constants: { LEFT, RIGHT, HALT } }
        );
      })();

------
spenrose
Fun! Two thoughts: if I recall correctly, Turing lays out progenitors of
STDOUT and system libraries. Do you touch on them? Also, do you refer to
Petzold's wonderful The Annotated Turing? [1]

[1] [http://theannotatedturing.com](http://theannotatedturing.com)

~~~
braythwayt
I probably will refer to The Annotated Turing. Although to be clear, this book
will not be about computability.

------
matt4077
For those unfamiliar with the author: he is one of about a dozen people I can
can remember, where I immediately knew "wow, this guy is smarter than you, and
almost as funny. Let's enjoy this"[1].

He's also a good example for the yiddish concept of "Mensch".

continue here: [http://raganwald.com](http://raganwald.com)

[1]: Bragging not intended–it just seems to me like the difference must be
fairly large in any direction before I consciously notice it.

