View genesis.es6
// This two-dimensional Turing Machine starts in the upper-left-hand corner of the
// tableau and counts the number of 1s surrounding a center cell, and
// then determines whether the centre cell should be born, survive, or die.
const life = [
['start', 0, 'ul-zero', Move(RIGHT)],
['start', 1, 'ul-one', Move(RIGHT)],
['ul-zero', 1, 'uc-one', Move(RIGHT)],
['ul-zero', 0, 'uc-zero', Move(RIGHT)],
View two-dimensional-turing-machines.js
// inherently FIXED size, not infinite
// works by compiling both the description (a/k/a program)
// and the tape (a/k/a data), then decompiling the tape when done.
// takes a tape of square length (e.g. 32x32)
// description instructions look like this:
//
// [currentState, match, nextState, ...instructions].
//
// Instructions can be Write(mark), Move(UP), Move(DOWN), Move(LEFT), and Move(RIGHT)
// The instructions are compiled for a Turning Machine that supports annotations
View multiply.es6
// Multiplies two numbers
//
// The numbers are encoded as strings of `1`s separated by a single `0`
//
// e.g. 2x3 => 6
// [1, 1, 0, 1, 1, 1] => [1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1]
//
// Dependencies:
// - The TM must understand aribtrary tape marks (numbers *and* strings)
// - The TM must allow sequences of instructions e.g. Write(1), Move(LEFT)
View doubly-infinite-tape.es6
// A decorator that compiles a program written for a bi-directionally
// infinite tape, into a program for a unidirectionally
// infinite tape.
//
// Requires a machine that accepts a description written in quintupes
// [ [currentState, currentMark, nextState, markToWrite, direction], ... ]
//
// The machine it decorates must have properties for LEFT and RIGHT,
// representing the possible moves,and HELT, a conventional special state for
// (what else) halting.
View trampolines.es6
// See http://raganwald.com/2013/03/28/trampolines-in-javascript.html
function trampoline (fn) {
return function trampolined (...args) {
let result = fn.apply(this, args);
while (result instanceof Function) {
result = result();
}
View curated-links-to-javascript-allonge.md
View execute_array_of_functions.js
var a = [
function () { console.log(1); },
function () { console.log(2); },
function () { console.log(3); }
];
a.forEach(Function.prototype.call.bind(Function.prototype.call));
View hash_sieve.es6
function * multiplesOf (startingWith, n) {
let number = startingWith;
while (true) {
yield number;
number = number + n;
}
}
class HashSieve {
View naïve.es6
function * nullEveryNth (skipFirst, n, iterable) {
const iterator = iterable[Symbol.iterator]();
yield * take(skipFirst, iterator);
while (true) {
yield * take(n - 1, iterator);
iterator.next();
yield null;
}