CosmicOS full message

0introduce numbers (in unary notation)MATH
1introduce equality for unary numbersMATH
2now introduce other relational operatorsMATH
3introduce the NOT logical operatorMATH
4introduce additionMATH
5introduce subtractionMATH
6introduce multiplicationMATH
7introduce non-unary representation of numbersMATH
8show some syntax variantsMATH
9show local assignmentMATH
10demonstrate existence of memoryMATH
11use equality for truth valuesMATH
12show mechanisms for branchingMATH
13introduce the AND logical operatorMATH
14introduce the OR logical operatorMATH
15illustrate pairsMATH
16introduce mutable objects, and side-effectsMATH
17illustrate lists and some list operatorsMATH
18describe changes to the implicit interpreter to allow new special formsHACK
19introduce sugar for letMATH
20build up functions of several variablesMATH
21show map function for applying a function across the elements of a listMATH
22end of part 1, start of part 2NOTE
23show an example of recursive evaluationMATH
24some pure lambda calculus definitions - optionalMATH
25introduce universal quantifierMATH
26introduce existential quantifierMATH
27introduce logical implicationMATH
28introduce sets and set membershipMATH
29introduce graph structuresMATH
30show how to execute a sequence of instructionsMATH
31introduce environment/hashmap structureMATH
32introduce simple mutable structuresOBJECT
33introduce method handler wrappersOBJECT
34introduce turing machine modelTURING
35introduce simple form of typing, for ease of documentation.OBJECT
36an example object -- a 2D pointOBJECT
37an example object -- a containerOBJECT
38expressing inheritanceOBJECT
39adding a special form for classesOBJECT
40wrapper class for cellsOBJECT
41playing around with doors and roomsMUD
42end of part 2, start of part 3NOTE
43simulating unless gatesGATE
44testing alternate primer based on gates: cos_not circuitGATE
45testing alternate primer based on gates: cos_and circuitGATE
46testing alternate primer based on gates: cos_or circuitGATE
47testing alternate primer based on gates: cos_nor circuitGATE
48testing alternate primer based on gates: cos_osc circuitGATE
49testing alternate primer based on gates: cos_sr circuitGATE
50testing alternate primer based on gates: cos_d circuitGATE
51probing networks of unless gatesGATE
52end of part 3, start of part 4NOTE
53a mechanism for referring to parts of the messageSELF
54some preparatory work for integrating with Java codeJAVA
55class translation 'COS_JavaTest'JAVA
56check that automatic conversion is workableJAVA
57another simple little text-adventure spaceMUD
58native implementation of a Java list, hash classesJAVA
59testing the JList classJAVA
60basic iterator implementationJAVA
61class translation 'COS_JDoor'JAVA
62class translation 'COS_JThing'JAVA
63class translation 'COS_JRoom'JAVA
64class translation 'COS_JNamed'JAVA
65class translation 'COS_JWorld'JAVA
66class translation 'COS_JRobo'JAVA
67test JRoom, JDoor, JThing, etcJAVA

#   Author: Paul Fitzpatrick, paulfitz@csail.mit.edu
#   Copyright (c) 2005 Paul Fitzpatrick
#
#   This file is part of CosmicOS.
#
#   CosmicOS is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   CosmicOS is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with CosmicOS; if not, write to the Free Software
#   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#

0. introduce numbers (in unary notation)

# Here we count up from zero, go through some primes, etc. There is some
# syntax around the numbers, but that doesn't need to be understood at
# this point. We give numbers in a tweaked unary format, rather than the
# encoding used in the main body of the message.
intro is:int;
203210011132233hear
is:int | unary 0;
21001113023210101032032233hear
is:int | unary 1 0;
21001113023210101032132032233hear
is:int | unary 1 1 0;
21001113023210101032132132032233hear
is:int | unary 1 1 1 0;
21001113023210101032132132132032233hear
is:int | unary 1 1 1 1 0;
21001113023210101032132132132132032233hear
is:int | unary 1 1 1 1 1 0;
2100111302321010103213213213213213203...hear
is:int | unary 1 1 1 1 1 1 0;
2100111302321010103213213213213213213...hear
is:int | unary 1 1 1 1 1 1 1 0;
2100111302321010103213213213213213213...hear
is:int | unary 1 1 1 1 1 1 1 1 0;
2100111302321010103213213213213213213...hear
is:int | unary 1 1 1 1 1 1 1 1 1 0;
2100111302321010103213213213213213213...hear
is:int | unary 1 1 1 1 1 1 1 1 1 1 0;
2100111302321010103213213213213213213...hear
is:int | unary 1 1 1 1 1 1 1 1 1 1 1 0;
2100111302321010103213213213213213213...hear
is:int | unary 1 1 1 1 1 1 1 1 1 1 1 1 0;
2100111302321010103213213213213213213...hear
is:int | unary 1 1 1 1 1 1 1 1 1 1 1 1 1 0;
2100111302321010103213213213213213213...hear
is:int | unary 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0;
2100111302321010103213213213213213213...hear
is:int | unary 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0;
2100111302321010103213213213213213213...hear
intro is:square;
203210111132233hear
is:square | unary 0;
21011113023210101032032233hear
is:square | unary 1 0;
21011113023210101032132032233hear
is:square | unary 1 1 1 1 0;
21011113023210101032132132132132032233hear
is:square | unary 1 1 1 1 1 1 1 1 1 0;
2101111302321010103213213213213213213...hear
is:square | unary 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0;
2101111302321010103213213213213213213...hear
is:square | unary 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0;
2101111302321010103213213213213213213...hear
intro is:prime;
203210110132233hear
is:prime | unary 1 1 0;
21011013023210101032132132032233hear
is:prime | unary 1 1 1 0;
21011013023210101032132132132032233hear
is:prime | unary 1 1 1 1 1 0;
2101101302321010103213213213213213203...hear
is:prime | unary 1 1 1 1 1 1 1 0;
2101101302321010103213213213213213213...hear
is:prime | unary 1 1 1 1 1 1 1 1 1 1 1 0;
2101101302321010103213213213213213213...hear
is:prime | unary 1 1 1 1 1 1 1 1 1 1 1 1 1 0;
2101101302321010103213213213213213213...hear
is:prime | unary 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0;
2101101302321010103213213213213213213...hear
is:prime | unary 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0;
2101101302321010103213213213213213213...hear
is:prime | unary 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0;
2101101302321010103213213213213213213...hear
is:prime | unary 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0;
2101101302321010103213213213213213213...hear
is:prime | unary 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0;
2101101302321010103213213213213213213...hear

1. introduce equality for unary numbers

# The intro operator does nothing essential, and could be omitted - it just
# tags the first use of a new operator. The = operator is introduced
# alongside a duplication of unary numbers.  The meaning will not quite by
# nailed down until we see other relational operators.
intro =;
20321032233hear
= (unary 1 0) (unary 1 0);
2103221010103213203322101010321320332233hear
= (unary 1 1 0) (unary 1 1 0);
2103221010103213213203322101010321321...hear
= (unary 1 1 1 0) (unary 1 1 1 0);
2103221010103213213213203322101010321...hear
= (unary 1 1 1 1 0) (unary 1 1 1 1 0);
2103221010103213213213213203322101010...hear
= (unary 1 1 1 1 1 0) (unary 1 1 1 1 1 0);
2103221010103213213213213213203322101...hear
= (unary 1 1 1 1 1 1 0) (unary 1 1 1 1 1 1 0);
2103221010103213213213213213213203322...hear
= (unary 1 1 1 1 1 1 1 0) (unary 1 1 1 1 1 1 1 0);
2103221010103213213213213213213213203...hear
= (unary 1 1 1 1 1 1 1 1 0) (unary 1 1 1 1 1 1 1 1 0);
2103221010103213213213213213213213213...hear
= (unary 1 0) (unary 1 0);
2103221010103213203322101010321320332233hear
= (unary 1 1 1 1 1 1 0) (unary 1 1 1 1 1 1 0);
2103221010103213213213213213213203322...hear
= (unary 1 1 0) (unary 1 1 0);
2103221010103213213203322101010321321...hear

2. now introduce other relational operators

# After this lesson, it should be clear what contexts < > and = are
# appropriate in.
intro >;
20321132233hear
intro <;
2032132233hear
= (unary 1 0) (unary 1 0);
2103221010103213203322101010321320332233hear
< (unary 1 0) (unary 1 1 0);
2132210101032132033221010103213213203...hear
< (unary 1 0) (unary 1 1 1 0);
2132210101032132033221010103213213213...hear
< (unary 1 0) (unary 1 1 1 1 0);
2132210101032132033221010103213213213...hear
> (unary 1 1 0) (unary 1 0);
2113221010103213213203322101010321320...hear
= (unary 1 1 0) (unary 1 1 0);
2103221010103213213203322101010321321...hear
< (unary 1 1 0) (unary 1 1 1 0);
2132210101032132132033221010103213213...hear
< (unary 1 1 0) (unary 1 1 1 1 0);
2132210101032132132033221010103213213...hear
> (unary 1 1 1 0) (unary 1 0);
2113221010103213213213203322101010321...hear
> (unary 1 1 1 0) (unary 1 1 0);
2113221010103213213213203322101010321...hear
= (unary 1 1 1 0) (unary 1 1 1 0);
2103221010103213213213203322101010321...hear
< (unary 1 1 1 0) (unary 1 1 1 1 0);
2132210101032132132132033221010103213...hear
> (unary 1 1 1 1 0) (unary 1 0);
2113221010103213213213213203322101010...hear
> (unary 1 1 1 1 0) (unary 1 1 0);
2113221010103213213213213203322101010...hear
> (unary 1 1 1 1 0) (unary 1 1 1 0);
2113221010103213213213213203322101010...hear
= (unary 1 1 1 1 0) (unary 1 1 1 1 0);
2103221010103213213213213203322101010...hear
# Some random examples
> (unary 1 1 1 1 0) (unary 1 1 1 0);
2113221010103213213213213203322101010...hear
> (unary 1 1 1 0) (unary 0);
2113221010103213213213203322101010320...hear
> (unary 1 0) (unary 0);
2113221010103213203322101010320332233hear
> (unary 1 1 1 1 1 1 1 1 0) (unary 0);
2113221010103213213213213213213213213...hear
> (unary 1 1 1 1 1 1 1 0) (unary 1 1 1 1 1 1 0);
2113221010103213213213213213213213203...hear
> (unary 1 1 1 1 1 1 0) (unary 1 1 0);
2113221010103213213213213213213203322...hear
> (unary 1 1 1 1 1 0) (unary 0);
2113221010103213213213213213203322101...hear
> (unary 1 1 1 1 1 1 1 1 1 0) (unary 1 1 1 1 0);
2113221010103213213213213213213213213...hear
> (unary 1 1 1 1 1 0) (unary 1 0);
2113221010103213213213213213203322101...hear
> (unary 1 1 0) (unary 0);
2113221010103213213203322101010320332233hear
> (unary 1 1 1 0) (unary 1 0);
2113221010103213213213203322101010321...hear
< (unary 1 1 1 1 1 1 1 0) (unary 1 1 1 1 1 1 1 1 1 0);
2132210101032132132132132132132132033...hear
< (unary 1 1 1 0) (unary 1 1 1 1 1 1 0);
2132210101032132132132033221010103213...hear
< (unary 1 1 0) (unary 1 1 1 0);
2132210101032132132033221010103213213...hear
< (unary 1 1 0) (unary 1 1 1 1 0);
2132210101032132132033221010103213213...hear
< (unary 0) (unary 1 0);
213221010103203322101010321320332233hear
< (unary 0) (unary 1 1 1 1 1 1 1 1 1 1 0);
2132210101032033221010103213213213213...hear
< (unary 0) (unary 1 1 1 0);
2132210101032033221010103213213213203...hear
< (unary 0) (unary 1 1 1 1 0);
2132210101032033221010103213213213213...hear
< (unary 1 1 1 1 0) (unary 1 1 1 1 1 1 0);
2132210101032132132132132033221010103...hear
< (unary 0) (unary 1 1 0);
213221010103203322101010321321320332233hear
< (unary 1 0) (unary 1 1 1 1 1 1 1 1 0);
2132210101032132033221010103213213213...hear
# A few more random examples
> (unary 1 1 1 1 1 0) (unary 1 1 1 1 0);
2113221010103213213213213213203322101...hear
> (unary 1 1 1 1 1 0) (unary 1 1 1 0);
2113221010103213213213213213203322101...hear
< (unary 1 0) (unary 1 1 0);
2132210101032132033221010103213213203...hear
> (unary 1 1 1 1 0) (unary 1 1 0);
2113221010103213213213213203322101010...hear
> (unary 1 1 1 1 1 0) (unary 0);
2113221010103213213213213213203322101...hear
> (unary 1 1 1 1 0) (unary 1 0);
2113221010103213213213213203322101010...hear
< (unary 1 0) (unary 1 1 1 0);
2132210101032132033221010103213213213...hear
> (unary 1 1 1 1 0) (unary 0);
2113221010103213213213213203322101010...hear
> (unary 1 1 0) (unary 1 0);
2113221010103213213203322101010321320...hear
< (unary 1 1 1 0) (unary 1 1 1 1 1 0);
2132210101032132132132033221010103213...hear
> (unary 1 1 1 1 0) (unary 1 1 1 0);
2113221010103213213213213203322101010...hear

3. introduce the NOT logical operator

intro not;
203210032233hear
= (unary  0) (unary  0);
2103221010103203322101010320332233hear
not | < (unary  0) (unary  0);
2100302321322101010320332210101032033...hear
not | > (unary  0) (unary  0);
2100302321132210101032033221010103203...hear
= (unary  1 1 1 1 0) (unary  1 1 1 1 0);
2103221010103213213213213203322101010...hear
not | < (unary  1 1 1 1 0) (unary  1 1 1 1 0);
2100302321322101010321321321321320332...hear
not | > (unary  1 1 1 1 0) (unary  1 1 1 1 0);
2100302321132210101032132132132132033...hear
= (unary  1 1 1 1 1 1 0) (unary  1 1 1 1 1 1 0);
2103221010103213213213213213213203322...hear
not | < (unary  1 1 1 1 1 1 0) (unary  1 1 1 1 1 1 0);
2100302321322101010321321321321321321...hear
not | > (unary  1 1 1 1 1 1 0) (unary  1 1 1 1 1 1 0);
2100302321132210101032132132132132132...hear
= (unary  1 1 0) (unary  1 1 0);
2103221010103213213203322101010321321...hear
not | < (unary  1 1 0) (unary  1 1 0);
2100302321322101010321321320332210101...hear
not | > (unary  1 1 0) (unary  1 1 0);
2100302321132210101032132132033221010...hear
= (unary  1 1 1 0) (unary  1 1 1 0);
2103221010103213213213203322101010321...hear
not | < (unary  1 1 1 0) (unary  1 1 1 0);
2100302321322101010321321321320332210...hear
not | > (unary  1 1 1 0) (unary  1 1 1 0);
2100302321132210101032132132132033221...hear
not | = (unary  1 1 1 0) (unary  1 1 1 1 1 1 1 1 1 1 0);
2100302321032210101032132132132033221...hear
< (unary  1 1 1 0) (unary  1 1 1 1 1 1 1 1 1 1 0);
2132210101032132132132033221010103213...hear
not | > (unary  1 1 1 0) (unary  1 1 1 1 1 1 1 1 1 1 0);
2100302321132210101032132132132033221...hear
not | = (unary  1 1 1 1 1 0) (unary  1 1 1 1 1 1 1 0);
2100302321032210101032132132132132132...hear
< (unary  1 1 1 1 1 0) (unary  1 1 1 1 1 1 1 0);
2132210101032132132132132132033221010...hear
not | > (unary  1 1 1 1 1 0) (unary  1 1 1 1 1 1 1 0);
2100302321132210101032132132132132132...hear
not | = (unary  1 0) (unary  1 1 0);
2100302321032210101032132033221010103...hear
< (unary  1 0) (unary  1 1 0);
2132210101032132033221010103213213203...hear
not | > (unary  1 0) (unary  1 1 0);
2100302321132210101032132033221010103...hear
not | = (unary  0) (unary  1 1 1 1 1 0);
2100302321032210101032033221010103213...hear
< (unary  0) (unary  1 1 1 1 1 0);
2132210101032033221010103213213213213...hear
not | > (unary  0) (unary  1 1 1 1 1 0);
2100302321132210101032033221010103213...hear
not | = (unary  1 1 1 1 1 1 1 1 0) (unary  1 1 1 1 1 1 1 1 1 1 1 1 1 1 0);
2100302321032210101032132132132132132...hear
< (unary  1 1 1 1 1 1 1 1 0) (unary  1 1 1 1 1 1 1 1 1 1 1 1 1 1 0);
2132210101032132132132132132132132132...hear
not | > (unary  1 1 1 1 1 1 1 1 0) (unary  1 1 1 1 1 1 1 1 1 1 1 1 1 1 0);
2100302321132210101032132132132132132...hear
not | = (unary  1 1 1 1 1 1 1 1 1 1 1 0) (unary  1 1 1 1 1 1 0);
2100302321032210101032132132132132132...hear
> (unary  1 1 1 1 1 1 1 1 1 1 1 0) (unary  1 1 1 1 1 1 0);
2113221010103213213213213213213213213...hear
not | < (unary  1 1 1 1 1 1 1 1 1 1 1 0) (unary  1 1 1 1 1 1 0);
2100302321322101010321321321321321321...hear
not | = (unary  1 1 1 1 1 1 1 1 1 1 1 1 0) (unary  1 1 0);
2100302321032210101032132132132132132...hear
> (unary  1 1 1 1 1 1 1 1 1 1 1 1 0) (unary  1 1 0);
2113221010103213213213213213213213213...hear
not | < (unary  1 1 1 1 1 1 1 1 1 1 1 1 0) (unary  1 1 0);
2100302321322101010321321321321321321...hear
not | = (unary  1 1 1 1 1 1 1 1 1 1 0) (unary  1 1 1 1 1 1 1 0);
2100302321032210101032132132132132132...hear
> (unary  1 1 1 1 1 1 1 1 1 1 0) (unary  1 1 1 1 1 1 1 0);
2113221010103213213213213213213213213...hear
not | < (unary  1 1 1 1 1 1 1 1 1 1 0) (unary  1 1 1 1 1 1 1 0);
2100302321322101010321321321321321321...hear
not | = (unary  1 1 1 1 0) (unary  0);
2100302321032210101032132132132132033...hear
> (unary  1 1 1 1 0) (unary  0);
2113221010103213213213213203322101010...hear
not | < (unary  1 1 1 1 0) (unary  0);
2100302321322101010321321321321320332...hear
not | = (unary  1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0) (unary  1 1 1 1 1 1 1 1 1 0);
2100302321032210101032132132132132132...hear
> (unary  1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0) (unary  1 1 1 1 1 1 1 1 1 0);
2113221010103213213213213213213213213...hear
not | < (unary  1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0) (unary  1 1 1 1 1 1 1 1 1 0);
2100302321322101010321321321321321321...hear

4. introduce addition

intro +;
2032101032233hear
= (unary  1 1 0) | + (unary  0) (unary  1 1 0);
2103221010103213213203302321010322101...hear
= (unary  1 1 1 1 1 0) | + (unary  1 1 1 1 0) (unary  1 0);
2103221010103213213213213213203302321...hear
= (unary  1 1 0) | + (unary  1 1 0) (unary  0);
2103221010103213213203302321010322101...hear
= (unary  1 1 1 1 0) | + (unary  0) (unary  1 1 1 1 0);
2103221010103213213213213203302321010...hear
= (unary  1 1 1 1 0) | + (unary  1 1 1 0) (unary  1 0);
2103221010103213213213213203302321010...hear
= (unary  1 1 1 0) | + (unary  1 0) (unary  1 1 0);
2103221010103213213213203302321010322...hear
= (unary  0) | + (unary  0) (unary  0);
2103221010103203302321010322101010320...hear
= (unary  1 1 1 1 0) | + (unary  1 1 1 1 0) (unary  0);
2103221010103213213213213203302321010...hear
= (unary  1 1 1 0) | + (unary  1 1 0) (unary  1 0);
2103221010103213213213203302321010322...hear
= (unary  1 1 1 1 0) | + (unary  1 1 1 1 0) (unary  0);
2103221010103213213213213203302321010...hear

5. introduce subtraction

intro -;
2032101132233hear
= (unary  0) | - (unary  1 1 0) (unary  1 1 0);
2103221010103203302321011322101010321...hear
= (unary  1 1 1 1 0) | - (unary  1 1 1 1 1 0) (unary  1 0);
2103221010103213213213213203302321011...hear
= (unary  1 1 0) | - (unary  1 1 0) (unary  0);
2103221010103213213203302321011322101...hear
= (unary  0) | - (unary  1 1 1 1 0) (unary  1 1 1 1 0);
2103221010103203302321011322101010321...hear
= (unary  1 1 1 0) | - (unary  1 1 1 1 0) (unary  1 0);
2103221010103213213213203302321011322...hear
= (unary  1 0) | - (unary  1 1 1 0) (unary  1 1 0);
2103221010103213203302321011322101010...hear
= (unary  0) | - (unary  0) (unary  0);
2103221010103203302321011322101010320...hear
= (unary  1 1 1 1 0) | - (unary  1 1 1 1 0) (unary  0);
2103221010103213213213213203302321011...hear
= (unary  1 1 0) | - (unary  1 1 1 0) (unary  1 0);
2103221010103213213203302321011322101...hear
= (unary  1 1 1 1 0) | - (unary  1 1 1 1 0) (unary  0);
2103221010103213213213213203302321011...hear

6. introduce multiplication

intro *;
2032100132233hear
= (unary  0) | * (unary  0) (unary  0);
2103221010103203302321001322101010320...hear
= (unary  0) | * (unary  0) (unary  1 0);
2103221010103203302321001322101010320...hear
= (unary  0) | * (unary  0) (unary  1 1 0);
2103221010103203302321001322101010320...hear
= (unary  0) | * (unary  0) (unary  1 1 1 0);
2103221010103203302321001322101010320...hear
= (unary  0) | * (unary  1 0) (unary  0);
2103221010103203302321001322101010321...hear
= (unary  1 0) | * (unary  1 0) (unary  1 0);
2103221010103213203302321001322101010...hear
= (unary  1 1 0) | * (unary  1 0) (unary  1 1 0);
2103221010103213213203302321001322101...hear
= (unary  1 1 1 0) | * (unary  1 0) (unary  1 1 1 0);
2103221010103213213213203302321001322...hear
= (unary  0) | * (unary  1 1 0) (unary  0);
2103221010103203302321001322101010321...hear
= (unary  1 1 0) | * (unary  1 1 0) (unary  1 0);
2103221010103213213203302321001322101...hear
= (unary  1 1 1 1 0) | * (unary  1 1 0) (unary  1 1 0);
2103221010103213213213213203302321001...hear
= (unary  1 1 1 1 1 1 0) | * (unary  1 1 0) (unary  1 1 1 0);
2103221010103213213213213213213203302...hear
= (unary  0) | * (unary  1 1 1 0) (unary  0);
2103221010103203302321001322101010321...hear
= (unary  1 1 1 0) | * (unary  1 1 1 0) (unary  1 0);
2103221010103213213213203302321001322...hear
= (unary  1 1 1 1 1 1 0) | * (unary  1 1 1 0) (unary  1 1 0);
2103221010103213213213213213213203302...hear
= (unary  1 1 1 1 1 1 1 1 1 0) | * (unary  1 1 1 0) (unary  1 1 1 0);
2103221010103213213213213213213213213...hear
= (unary  0) | * (unary  0) (unary  1 0);
2103221010103203302321001322101010320...hear
= (unary  1 1 1 0) | * (unary  1 1 1 0) (unary  1 0);
2103221010103213213213203302321001322...hear
= (unary  0) | * (unary  1 1 0) (unary  0);
2103221010103203302321001322101010321...hear
= (unary  0) | * (unary  0) (unary  1 1 1 0);
2103221010103203302321001322101010320...hear
= (unary  1 1 1 0) | * (unary  1 1 1 0) (unary  1 0);
2103221010103213213213203302321001322...hear
= (unary  1 1 0) | * (unary  1 0) (unary  1 1 0);
2103221010103213213203302321001322101...hear
= (unary  0) | * (unary  0) (unary  0);
2103221010103203302321001322101010320...hear
= (unary  0) | * (unary  1 1 1 0) (unary  0);
2103221010103203302321001322101010321...hear
= (unary  0) | * (unary  1 1 0) (unary  0);
2103221010103203302321001322101010321...hear
= (unary  0) | * (unary  1 1 1 0) (unary  0);
2103221010103203302321001322101010321...hear

7. introduce non-unary representation of numbers

# Switch from unary numbers to another representation. The representation
# of numbers is now medium-specific (it used to be specified as binary),
# and can be fiddled with without affecting the rest of the message.
= 0 (unary 0);
210320322101010320332233hear
= 1 (unary 1 0);
210321322101010321320332233hear
= 2 (unary 1 1 0);
2103210322101010321321320332233hear
= 3 (unary 1 1 1 0);
2103211322101010321321321320332233hear
= 4 (unary 1 1 1 1 0);
21032100322101010321321321321320332233hear
= 5 (unary 1 1 1 1 1 0);
2103210132210101032132132132132132033...hear
= 6 (unary 1 1 1 1 1 1 0);
2103211032210101032132132132132132132...hear
= 7 (unary 1 1 1 1 1 1 1 0);
2103211132210101032132132132132132132...hear
= 8 (unary 1 1 1 1 1 1 1 1 0);
2103210003221010103213213213213213213...hear
= 9 (unary 1 1 1 1 1 1 1 1 1 0);
2103210013221010103213213213213213213...hear
= 10 (unary 1 1 1 1 1 1 1 1 1 1 0);
2103210103221010103213213213213213213...hear
= 11 (unary 1 1 1 1 1 1 1 1 1 1 1 0);
2103210113221010103213213213213213213...hear
= 12 (unary 1 1 1 1 1 1 1 1 1 1 1 1 0);
2103211003221010103213213213213213213...hear
= 13 (unary 1 1 1 1 1 1 1 1 1 1 1 1 1 0);
2103211013221010103213213213213213213...hear
= 14 (unary 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0);
2103211103221010103213213213213213213...hear
= 15 (unary 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0);
2103211113221010103213213213213213213...hear
= 1 (unary 1 0);
210321322101010321320332233hear
= 2 (unary 1 1 0);
2103210322101010321321320332233hear
= 4 (unary 1 1 1 1 0);
21032100322101010321321321321320332233hear
= 8 (unary 1 1 1 1 1 1 1 1 0);
2103210003221010103213213213213213213...hear
= 16 (unary 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0);
2103210000322101010321321321321321321...hear
= 5 (unary 1 1 1 1 1 0);
2103210132210101032132132132132132033...hear
= 14 (unary 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0);
2103211103221010103213213213213213213...hear
= 2 (unary 1 1 0);
2103210322101010321321320332233hear
= 3 (unary 1 1 1 0);
2103211322101010321321321320332233hear
= 0 (unary 0);
210320322101010320332233hear
= 13 (unary 1 1 1 1 1 1 1 1 1 1 1 1 1 0);
2103211013221010103213213213213213213...hear
= 11 (unary 1 1 1 1 1 1 1 1 1 1 1 0);
2103210113221010103213213213213213213...hear
= 1 (unary 1 0);
210321322101010321320332233hear
= 9 (unary 1 1 1 1 1 1 1 1 1 0);
2103210013221010103213213213213213213...hear
= 15 (unary 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0);
2103211113221010103213213213213213213...hear
= 8 (unary 1 1 1 1 1 1 1 1 0);
2103210003221010103213213213213213213...hear
= 7 (unary 1 1 1 1 1 1 1 0);
2103211132210101032132132132132132132...hear
= 6 (unary 1 1 1 1 1 1 0);
2103211032210101032132132132132132132...hear
= 4 (unary 1 1 1 1 0);
21032100322101010321321321321320332233hear
= 12 (unary 1 1 1 1 1 1 1 1 1 1 1 1 0);
2103211003221010103213213213213213213...hear
= 10 (unary 1 1 1 1 1 1 1 1 1 1 0);
2103210103221010103213213213213213213...hear
= (unary 1 1 1 1 1 1 1 1 1 0) | + (unary 1 1 1 1 1 1 0) (unary 1 1 1 0);
2103221010103213213213213213213213213...hear
= 9 | + 6 3;
21032100130232101032110321132233hear
= (unary 1 1 1 1 1 1 0) | + (unary 0) (unary 1 1 1 1 1 1 0);
2103221010103213213213213213213203302...hear
= 6 | + 0 6;
210321103023210103203211032233hear
= (unary 1 1 1 1 1 1 1 1 1 1 0) | + (unary 1 1 1 1 1 1 0) (unary 1 1 1 1 0);
2103221010103213213213213213213213213...hear
= 10 | + 6 4;
210321010302321010321103210032233hear
= (unary 1 1 1 1 1 0) | + (unary 1 1 1 0) (unary 1 1 0);
2103221010103213213213213213203302321...hear
= 5 | + 3 2;
210321013023210103211321032233hear
= (unary 1 0) | + (unary 1 0) (unary 0);
2103221010103213203302321010322101010...hear
= 1 | + 1 0;
21032130232101032132032233hear
= (unary 1 1 1 1 1 1 0) | + (unary 1 1 0) (unary 1 1 1 1 0);
2103221010103213213213213213213203302...hear
= 6 | + 2 4;
2103211030232101032103210032233hear
= (unary 1 1 1 1 1 1 1 1 1 1 1 1 0) | + (unary 1 1 1 1 1 1 0) (unary 1 1 1 1 1 1 0);
2103221010103213213213213213213213213...hear
= 12 | + 6 6;
210321100302321010321103211032233hear
= (unary 1 1 1 1 1 1 1 1 0) | + (unary 1 1 1 1 0) (unary 1 1 1 1 0);
2103221010103213213213213213213213213...hear
= 8 | + 4 4;
210321000302321010321003210032233hear
= (unary 0) | * (unary 0) (unary 1 1 0);
2103221010103203302321001322101010320...hear
= 0 | * 0 2;
210320302321001320321032233hear
= (unary 1 1 0) | * (unary 1 0) (unary 1 1 0);
2103221010103213213203302321001322101...hear
= 2 | * 1 2;
2103210302321001321321032233hear
= (unary 0) | * (unary 0) (unary 1 0);
2103221010103203302321001322101010320...hear
= 0 | * 0 1;
21032030232100132032132233hear
= (unary 0) | * (unary 1 1 1 0) (unary 0);
2103221010103203302321001322101010321...hear
= 0 | * 3 0;
210320302321001321132032233hear
= (unary 0) | * (unary 0) (unary 0);
2103221010103203302321001322101010320...hear
= 0 | * 0 0;
21032030232100132032032233hear
= (unary 0) | * (unary 1 0) (unary 0);
2103221010103203302321001322101010321...hear
= 0 | * 1 0;
21032030232100132132032233hear
= (unary 1 1 1 1 0) | * (unary 1 1 0) (unary 1 1 0);
2103221010103213213213213203302321001...hear
= 4 | * 2 2;
210321003023210013210321032233hear
= (unary 1 1 1 1 1 1 1 1 1 0) | * (unary 1 1 1 0) (unary 1 1 1 0);
2103221010103213213213213213213213213...hear
= 9 | * 3 3;
2103210013023210013211321132233hear

8. show some syntax variants

= 6 6;
210321103211032233hear
= 6 (+ 1 5);
21032110322101032132101332233hear
= 6 | + 1 5;
210321103023210103213210132233hear
= 6 | + 1 (+ 4 1);
2103211030232101032132210103210032133...hear
= 6 | + 1 | + 4 1;
2103211030232101032130232101032100321...hear
= 6 (+ 1 5);
21032110322101032132101332233hear
= (+ 3 3) (+ 1 5);
2103221010321132113322101032132101332233hear
= (+ 3 (- 5 2)) (+ 1 5);
2103221010321132210113210132103332210...hear
= (+ 3 | - 5 2) (+ 1 5);
2103221010321130232101132101321033221...hear
= (+ 3 | - 5 2) | + 1 5;
2103221010321130232101132101321033023...hear

9. show local assignment

assign x 1 | = (x) 1;
2111032100110321302321032210011033213...hear
assign x 2 | = (x) 2;
2111032100110321030232103221001103321...hear
assign x 3 | = (x) 3;
2111032100110321130232103221001103321...hear
assign x 3 | = 9 (* (x) (x));
2111032100110321130232103210013221001...hear
assign x 4 | = 16 (* (x) (x));
2111032100110321003023210321000032210...hear
assign x (+) | = 7 (x 4 3);
2111032100110322101033023210321113221...hear
assign x (+) | = 12 (x 6 6);
2111032100110322101033023210321100322...hear
assign x (+) | = 9 (x 7 2);
2111032100110322101033023210321001322...hear
assign x (-) | = 1 (x 4 3);
2111032100110322101133023210321322100...hear
assign x (-) | = 0 (x 6 6);
2111032100110322101133023210320322100...hear
assign x (-) | = 5 (x 7 2);
2111032100110322101133023210321013221...hear
assign x (*) | = 12 (x 4 3);
2111032100110322100133023210321100322...hear
assign x (*) | = 36 (x 6 6);
2111032100110322100133023210321001003...hear
assign x (*) | = 14 (x 7 2);
2111032100110322100133023210321110322...hear
assign x (=) | x 4 4;
2111032100110322103302321001103210032...hear
assign x (=) | x 4 (+ 2 2);
2111032100110322103302321001103210032...hear
assign x 1 | assign y 2 | = 3 (+ (x) (y));
2111032100110321302321110321100013210...hear
assign x 2 | assign y 7 | = 5 (- (y) (x));
2111032100110321030232111032110001321...hear
assign x (+) | assign y 3 | = 4 (x 1 (y));
2111032100110322101033023211103211000...hear
# Scoping and other odd corners.
= 2 | assign x 1 | + $x 1;
2103210302321110321001103213023210103...hear
= 1 | assign x 1 $x;
2103213023211103210011032132210321001...hear
= 14 | assign x 1 14;
2103211103023211103210011032132111032233hear
= 4 | assign x (assign y 3 | + 1 $y) $x;
2103210030232111032100110322111032110...hear
= 4 | assign x (assign x 3 | + 1 $x) $x;
2103210030232111032100110322111032100...hear
# Show alternate lookup syntax.
assign x 1 | = (x) 1;
2111032100110321302321032210011033213...hear
assign x 1 | = $x 1;
2111032100110321302321032210321001103...hear
assign x 4 | = 16 (* (x) (x));
2111032100110321003023210321000032210...hear
assign x 4 | = 16 (* $x $x);
2111032100110321003023210321000032210...hear
assign x 4 | = 16 | * $x $x;
2111032100110321003023210321000030232...hear
# Now for functions.
= 0 | (? x $x) 0;
2103203023221100321001103221032100110...hear
= 1 | (? x $x) 1;
2103213023221100321001103221032100110...hear
= 2 | (? x $x) 2;
2103210302322110032100110322103210011...hear
= 3 | (? x $x) 3;
2103211302322110032100110322103210011...hear
= 4 | (? x $x) 4;
2103210030232211003210011032210321001...hear
= 5 | (? x $x) 5;
2103210130232211003210011032210321001...hear
= 1 | (? x | + 1 $x) 0;
2103213023221100321001103023210103213...hear
= 2 | (? x | + 1 $x) 1;
2103210302322110032100110302321010321...hear
= 3 | (? x | + 1 $x) 2;
2103211302322110032100110302321010321...hear
= 4 | (? x | + 1 $x) 3;
2103210030232211003210011030232101032...hear
= 5 | (? x | + 1 $x) 4;
2103210130232211003210011030232101032...hear
= 6 | (? x | + 1 $x) 5;
2103211030232211003210011030232101032...hear
= 0 | (? x | * $x $x) 0;
2103203023221100321001103023210013221...hear
= 1 | (? x | * $x $x) 1;
2103213023221100321001103023210013221...hear
= 4 | (? x | * $x $x) 2;
2103210030232211003210011030232100132...hear
= 9 | (? x | * $x $x) 3;
2103210013023221100321001103023210013...hear
= 16 | (? x | * $x $x) 4;
2103210000302322110032100110302321001...hear
= 25 | (? x | * $x $x) 5;
2103211001302322110032100110302321001...hear
= 0 | (? y | * $y $y) 0;
2103203023221100321100013023210013221...hear
= 1 | (? y | * $y $y) 1;
2103213023221100321100013023210013221...hear
= 4 | (? y | * $y $y) 2;
2103210030232211003211000130232100132...hear
= 9 | (? y | * $y $y) 3;
2103210013023221100321100013023210013...hear
= 16 | (? y | * $y $y) 4;
2103210000302322110032110001302321001...hear
= 25 | (? y | * $y $y) 5;
2103211001302322110032110001302321001...hear
# Throw in a little mind-boggle.
= 0 | (? + | * $+ $+) 0;
2103203023221100321010302321001322103...hear
= 1 | (? + | * $+ $+) 1;
2103213023221100321010302321001322103...hear
= 4 | (? + | * $+ $+) 2;
2103210030232211003210103023210013221...hear
= 9 | (? + | * $+ $+) 3;
2103210013023221100321010302321001322...hear
= 16 | (? + | * $+ $+) 4;
2103210000302322110032101030232100132...hear
= 25 | (? + | * $+ $+) 5;
2103211001302322110032101030232100132...hear
= 0 | (? 5 | * $5 $5) 0;
2103203023221100321013023210013221032...hear
= 1 | (? 5 | * $5 $5) 1;
2103213023221100321013023210013221032...hear
= 4 | (? 5 | * $5 $5) 2;
2103210030232211003210130232100132210...hear
= 9 | (? 5 | * $5 $5) 3;
2103210013023221100321013023210013221...hear
= 16 | (? 5 | * $5 $5) 4;
2103210000302322110032101302321001322...hear
= 25 | (? 5 | * $5 $5) 5;
2103211001302322110032101302321001322...hear
# Functions in a box.
assign x (? y | * $y $y) | = 25 | x 5;
2111032100110322110032110001302321001...hear
assign x (? y | + $y 1) | = 6 | x 5;
2111032100110322110032110001302321010...hear
assign x (? x | + $x 1) | = 6 | x 5;
2111032100110322110032100110302321010...hear
assign y (? x | + $x 1) | = 6 | y 5;
2111032110001322110032100110302321010...hear
# Serve some curry.
= 52 | * 4 13;
210321101003023210013210032110132233hear
= 52 | (? x | * $x 4) 13;
2103211010030232211003210011030232100...hear
= 52 | (? x | ? y | * $x $y) 13 4;
2103211010030232211003210011030232110...hear
= 53 | (? x | ? y | + 1 | * $x $y) 13 4;
2103211010130232211003210011030232110...hear
assign z (? x | ? y | + 1 | * $x $y) | = 53 | z 13 4;
2111032110010322110032100110302321100...hear

10. demonstrate existence of memory

define meaning-of-life-universe-everything 39;
21101321100113210011132233hear
= 39 $meaning-of-life-universe-everything;
210321001113221032110011332233hear
= $meaning-of-life-universe-everything 39;
210322103211001133210011132233hear
define meaning-of-life-universe-everything 40;
21101321100113210100032233hear
= $meaning-of-life-universe-everything 40;
210322103211001133210100032233hear
define meaning-of-life-universe-everything | + 1 $meaning-of-life-universe-everything;
2110132110011302321010321322103211001...hear
= $meaning-of-life-universe-everything 41;
210322103211001133210100132233hear
assign x (+ 1 $meaning-of-life-universe-everything) | define meaning-of-life-universe-everything $x;
2111032100110322101032132210321100113...hear
= $meaning-of-life-universe-everything 42;
210322103211001133210101032233hear
define square | ? x | * $x $x;
2110132110100302321100321001103023210...hear
= 9 | square 3;
21032100130232110100321132233hear
= 81 | square 9;
2103210100013023211010032100132233hear
= 1 | square 1;
2103213023211010032132233hear
= 4 | square 2;
2103210030232110100321032233hear
= 0 | square 0;
2103203023211010032032233hear
define +:+ | ? x | + $x 1;
2110132110101302321100321001103023210...hear
= 4 | +:+ 3;
2103210030232110101321132233hear
= 10 | +:+ 9;
2103210103023211010132100132233hear
= 2 | +:+ 1;
21032103023211010132132233hear
= 3 | +:+ 2;
210321130232110101321032233hear
= 1 | +:+ 0;
2103213023211010132032233hear

11. use equality for truth values

# Not quite committing to a *type* for truth values in the message, side-stepping that issue until we really need to decide it.
define true | = 0 0;
2110132110110302321032032032233hear
define false | = 0 1;
2110132110111302321032032132233hear
= $true (= 2 2);
210322103211011033221032103210332233hear
= $true (> 4 2);
2103221032110110332211321003210332233hear
= $true (= 1 1);
2103221032110110332210321321332233hear
= $true (> 6 4);
21032210321101103322113211032100332233hear
= $true (< 3 4);
210322103211011033221321132100332233hear
= (= 5 5) $true;
21032210321013210133221032110110332233hear
= (= 3 3) $true;
210322103211321133221032110110332233hear
= (= 4 4) $true;
21032210321003210033221032110110332233hear
= (= 3 3) $true;
210322103211321133221032110110332233hear
= (= 0 0) $true;
2103221032032033221032110110332233hear
= $false (< 6 2);
210322103211011133221321103210332233hear
= $false (< 4 2);
210322103211011133221321003210332233hear
= $false (< 4 1);
21032210321101113322132100321332233hear
= $false (> 0 0);
2103221032110111332211320320332233hear
= $false (> 0 5);
210322103211011133221132032101332233hear
= (= 3 2) $false;
210322103211321033221032110111332233hear
= (> 2 3) $false;
210322113210321133221032110111332233hear
= (> 4 5) $false;
21032211321003210133221032110111332233hear
= (> 2 6) $false;
2103221132103211033221032110111332233hear
= (> 1 6) $false;
210322113213211033221032110111332233hear
= $true $true;
210322103211011033221032110110332233hear
= $false $false;
210322103211011133221032110111332233hear
not | = $true $false;
2100302321032210321101103322103211011...hear
not | = $false $true;
2100302321032210321101113322103211011...hear
= (> 4 2) (< 1 4);
210322113210032103322132132100332233hear
= (= 3 3) (< 3 5);
210322103211321133221321132101332233hear
= (= 0 0) (= 4 4);
210322103203203322103210032100332233hear
= (> 6 4) (< 3 5);
21032211321103210033221321132101332233hear
= (< 5 6) (< 0 2);
21032213210132110332213203210332233hear
= (= 5 1) (> 2 4);
2103221032101321332211321032100332233hear
= (> 4 6) (> 1 3);
2103221132100321103322113213211332233hear
= (> 2 5) (= 5 3);
21032211321032101332210321013211332233hear
= (< 2 1) (< 6 4);
21032213210321332213211032100332233hear
= (< 6 2) (> 4 5);
21032213211032103322113210032101332233hear
not | = (> 0 1) (= 0 0);
2100302321032211320321332210320320332233hear
not | = (< 6 4) (= 5 5);
2100302321032213211032100332210321013...hear
not | = (= 4 2) (> 1 0);
2100302321032210321003210332211321320...hear
not | = (> 5 6) (< 1 3);
2100302321032211321013211033221321321...hear
not | = (> 3 6) (> 5 4);
2100302321032211321132110332211321013...hear
not | = (= 2 2) (> 0 3);
2100302321032210321032103322113203211...hear
not | = (> 5 2) (= 2 3);
2100302321032211321013210332210321032...hear
not | = (> 4 1) (< 2 0);
2100302321032211321003213322132103203...hear
not | = (= 2 2) (< 3 2);
2100302321032210321032103322132113210...hear
not | = (< 0 1) (> 3 4);
2100302321032213203213322113211321003...hear

12. show mechanisms for branching

intro if;
2032111132233hear
= 28 | if (< 3 0) 24 28;
2103211100302321111322132113203321100...hear
= 27 | if (> 2 4) 29 27;
2103211011302321111322113210321003321...hear
= 29 | if (= 3 1) 20 29;
2103211101302321111322103211321332101...hear
= 21 | if (= 0 0) 21 26;
2103210101302321111322103203203321010...hear
= 29 | if (> 5 3) 29 23;
2103211101302321111322113210132113321...hear
= 26 | if (> 1 0) 26 22;
2103211010302321111322113213203321101...hear
= 21 | if (= 3 3) 21 27;
2103210101302321111322103211321133210...hear
= 23 | if (> 4 4) 25 23;
2103210111302321111322113210032100332...hear
define max | ? x | ? y | if (> $x $y) $x $y;
2110132111000302321100321001103023211...hear
define min | ? x | ? y | if (< $x $y) $x $y;
2110132111001302321100321001103023211...hear
= 0 | max 0 0;
2103203023211100032032032233hear
= 0 | min 0 0;
2103203023211100132032032233hear
= 1 | max 0 1;
2103213023211100032032132233hear
= 0 | min 0 1;
2103203023211100132032132233hear
= 2 | max 0 2;
210321030232111000320321032233hear
= 0 | min 0 2;
21032030232111001320321032233hear
= 1 | max 1 0;
2103213023211100032132032233hear
= 0 | min 1 0;
2103203023211100132132032233hear
= 1 | max 1 1;
2103213023211100032132132233hear
= 1 | min 1 1;
2103213023211100132132132233hear
= 2 | max 1 2;
210321030232111000321321032233hear
= 1 | min 1 2;
21032130232111001321321032233hear
= 2 | max 2 0;
210321030232111000321032032233hear
= 0 | min 2 0;
21032030232111001321032032233hear
= 2 | max 2 1;
210321030232111000321032132233hear
= 1 | min 2 1;
21032130232111001321032132233hear
= 2 | max 2 2;
2103210302321110003210321032233hear
= 2 | min 2 2;
2103210302321110013210321032233hear
# 'if' does not evaluate branch-not-taken, TODO show this.
define factorial | ? x | if (< $x 1) 1 | * $x | factorial | - $x 1;
2110132111010302321100321001103023211...hear
= 1 | factorial 1;
2103213023211101032132233hear
= 2 | factorial 2;
210321030232111010321032233hear
= 6 | factorial 3;
2103211030232111010321132233hear
= 24 | factorial 4;
2103211000302321110103210032233hear
= 120 | factorial 5;
210321111000302321110103210132233hear

13. introduce the AND logical operator

intro and;
203210132233hear
define and | ? x | ? y | if $x $y $false;
2110132101302321100321001103023211003...hear
not | and $false $false;
2100302321013221032110111332210321101...hear
not | and $false $true;
2100302321013221032110111332210321101...hear
not | and $true $false;
2100302321013221032110110332210321101...hear
and $true $true;
2101322103211011033221032110110332233hear
= $false | and $false $false;
2103221032110111330232101322103211011...hear
= $false | and $false $true;
2103221032110111330232101322103211011...hear
= $false | and $true $false;
2103221032110111330232101322103211011...hear
= $true | and $true $true;
2103221032110110330232101322103211011...hear
and (= 2 2) (> 4 2);
21013221032103210332211321003210332233hear
and (= 1 1) (> 6 4);
2101322103213213322113211032100332233hear
and (< 3 4) (= 5 5);
210132213211321003322103210132101332233hear
and (= 3 3) (= 4 4);
210132210321132113322103210032100332233hear
and (= 3 3) (= 0 0);
21013221032113211332210320320332233hear
and (< 5 7) (> 5 3);
210132213210132111332211321013211332233hear
and (> 5 4) (> 1 0);
2101322113210132100332211321320332233hear
and (> 3 0) (= 3 3);
210132211321132033221032113211332233hear
and (< 3 4) (< 3 6);
2101322132113210033221321132110332233hear
and (> 5 4) (> 5 4);
2101322113210132100332211321013210033...hear
not | and (> 6 4) (< 3 1);
2100302321013221132110321003322132113...hear
not | and (> 3 1) (> 3 3);
2100302321013221132113213322113211321...hear
not | and (= 0 0) (= 5 4);
2100302321013221032032033221032101321...hear
not | and (< 2 4) (> 4 6);
2100302321013221321032100332211321003...hear
not | and (= 3 3) (= 3 1);
2100302321013221032113211332210321132...hear
not | and (> 1 5) (< 3 6);
2100302321013221132132101332213211321...hear
not | and (< 6 2) (= 2 2);
2100302321013221321103210332210321032...hear
not | and (> 2 5) (= 5 5);
2100302321013221132103210133221032101...hear
not | and (< 6 2) (= 3 3);
2100302321013221321103210332210321132...hear
not | and (< 4 3) (> 5 2);
2100302321013221321003211332211321013...hear
not | and (< 5 4) (= 1 2);
2100302321013221321013210033221032132...hear
not | and (< 6 4) (= 5 1);
2100302321013221321103210033221032101...hear
not | and (> 2 6) (= 1 5);
2100302321013221132103211033221032132...hear
not | and (< 6 3) (= 2 3);
2100302321013221321103211332210321032...hear
not | and (< 6 4) (> 0 1);
2100302321013221321103210033221132032...hear
not | and (= 3 5) (< 4 1);
2100302321013221032113210133221321003...hear
not | and (= 4 1) (< 4 2);
2100302321013221032100321332213210032...hear
not | and (< 6 3) (= 3 0);
2100302321013221321103211332210321132...hear
not | and (< 4 2) (< 4 6);
2100302321013221321003210332213210032...hear
not | and (> 4 1) (< 5 2);
2100302321013221132100321332213210132...hear
not | and (> 0 1) (> 7 5);
2100302321013221132032133221132111321...hear
not | and (< 3 4) (> 3 6);
2100302321013221321132100332211321132...hear
not | and (> 1 2) (> 6 4);
2100302321013221132132103322113211032...hear
not | and (< 0 1) (= 4 5);
2100302321013221320321332210321003210...hear
and (< 4 6) (< 5 7);
210132213210032110332213210132111332233hear

14. introduce the OR logical operator

intro or;
203211032233hear
define or | ? x | ? y | if $x $true $y
2110132110302321100321001103023211003...hear
not | or $false $false;
2100302321103221032110111332210321101...hear
or $false $true;
2110322103211011133221032110110332233hear
or $true $false;
2110322103211011033221032110111332233hear
or $true $true;
2110322103211011033221032110110332233hear
= $false | or $false $false;
2103221032110111330232110322103211011...hear
= $true | or $false $true;
2103221032110110330232110322103211011...hear
= $true | or $true $false;
2103221032110110330232110322103211011...hear
= $true | or $true $true;
2103221032110110330232110322103211011...hear
or (= 2 2) (> 4 2);
21103221032103210332211321003210332233hear
or (= 1 1) (> 6 4);
2110322103213213322113211032100332233hear
or (< 3 4) (= 5 5);
211032213211321003322103210132101332233hear
or (= 3 3) (= 4 4);
211032210321132113322103210032100332233hear
or (= 3 3) (= 0 0);
21103221032113211332210320320332233hear
or (< 5 7) (> 5 3);
211032213210132111332211321013211332233hear
or (> 5 4) (> 1 0);
2110322113210132100332211321320332233hear
or (> 3 0) (= 3 3);
211032211321132033221032113211332233hear
or (< 3 4) (< 3 6);
2110322132113210033221321132110332233hear
or (> 5 4) (> 5 4);
2110322113210132100332211321013210033...hear
or (> 6 4) (< 3 1);
2110322113211032100332213211321332233hear
or (> 3 1) (> 3 3);
211032211321132133221132113211332233hear
or (= 0 0) (= 5 4);
2110322103203203322103210132100332233hear
or (< 2 4) (> 4 6);
211032213210321003322113210032110332233hear
or (= 3 3) (= 3 1);
211032210321132113322103211321332233hear
or (> 1 5) (< 3 6);
2110322113213210133221321132110332233hear
or (< 6 2) (= 2 2);
2110322132110321033221032103210332233hear
or (> 2 5) (= 5 5);
2110322113210321013322103210132101332233hear
or (< 6 2) (= 3 3);
2110322132110321033221032113211332233hear
or (< 4 3) (> 5 2);
21103221321003211332211321013210332233hear
not | or (< 5 4) (= 1 2);
2100302321103221321013210033221032132...hear
not | or (< 6 4) (= 5 1);
2100302321103221321103210033221032101...hear
not | or (> 2 6) (= 1 5);
2100302321103221132103211033221032132...hear
not | or (< 6 3) (= 2 3);
2100302321103221321103211332210321032...hear
not | or (< 6 4) (> 0 1);
2100302321103221321103210033221132032...hear
not | or (= 3 5) (< 4 1);
2100302321103221032113210133221321003...hear
not | or (= 4 1) (< 4 2);
2100302321103221032100321332213210032...hear
not | or (< 6 3) (= 3 0);
2100302321103221321103211332210321132...hear
or (< 4 2) (< 4 6);
21103221321003210332213210032110332233hear
or (> 4 1) (< 5 2);
2110322113210032133221321013210332233hear
or (> 0 1) (> 7 5);
2110322113203213322113211132101332233hear
or (< 3 4) (> 3 6);
21103221321132100332211321132110332233hear
or (> 1 2) (> 6 4);
21103221132132103322113211032100332233hear
or (< 0 1) (= 4 5);
211032213203213322103210032101332233hear
or (< 4 6) (< 5 7);
211032213210032110332213210132111332233hear
# Now is an opportune moment for '<=' and '>='
define >= | ? x | ? y | or (> $x $y) (= $x $y);
2110132111011302321100321001103023211...hear
define <= | ? x | ? y | or (< $x $y) (= $x $y);
2110132111100302321100321001103023211...hear
>= 0 0;
211101132032032233hear
<= 0 0;
211110032032032233hear
not | >= 0 1;
21003023211101132032132233hear
<= 0 1;
211110032032132233hear
not | >= 0 2;
210030232111011320321032233hear
<= 0 2;
2111100320321032233hear
>= 1 0;
211101132132032233hear
not | <= 1 0;
21003023211110032132032233hear
>= 1 1;
211101132132132233hear
<= 1 1;
211110032132132233hear
not | >= 1 2;
210030232111011321321032233hear
<= 1 2;
2111100321321032233hear
>= 2 0;
2111011321032032233hear
not | <= 2 0;
210030232111100321032032233hear
>= 2 1;
2111011321032132233hear
not | <= 2 1;
210030232111100321032132233hear
>= 2 2;
21110113210321032233hear
<= 2 2;
21111003210321032233hear

15. illustrate pairs

define cons | ? x | ? y | ? z | z $x $y;
2110132101013023211003210011030232110...hear
define car | ? cons:z | cons:z | ? x | ? y $x;
2110132101103023211003211110130232111...hear
define cdr | ? cons:z | cons:z | ? x | ? y $y;
2110132101113023211003211110130232111...hear
assign x (cons 0 4) | = 0 | car $x;
2111032100110322101013203210033023210...hear
assign x (cons 0 4) | = 4 | cdr $x;
2111032100110322101013203210033023210...hear
assign x (cons 6 2) | = 6 | car $x;
2111032100110322101013211032103302321...hear
assign x (cons 6 2) | = 2 | cdr $x;
2111032100110322101013211032103302321...hear
assign x (cons 3 9) | = 3 | car $x;
2111032100110322101013211321001330232...hear
assign x (cons 3 9) | = 9 | cdr $x;
2111032100110322101013211321001330232...hear
assign x (cons 7 | cons 10 2) | = 7 | car $x;
2111032100110322101013211130232101013...hear
assign x (cons 7 | cons 10 2) | = 10 | car | cdr $x;
2111032100110322101013211130232101013...hear
assign x (cons 7 | cons 10 2) | = 2 | cdr | cdr $x;
2111032100110322101013211130232101013...hear
assign x (cons 1 | cons 15 17) | = 1 | car $x;
2111032100110322101013213023210101321...hear
assign x (cons 1 | cons 15 17) | = 15 | car | cdr $x;
2111032100110322101013213023210101321...hear
assign x (cons 1 | cons 15 17) | = 17 | cdr | cdr $x;
2111032100110322101013213023210101321...hear
assign x (cons 8 | cons 14 9) | = 8 | car $x;
2111032100110322101013210003023210101...hear
assign x (cons 8 | cons 14 9) | = 14 | car | cdr $x;
2111032100110322101013210003023210101...hear
assign x (cons 8 | cons 14 9) | = 9 | cdr | cdr $x;
2111032100110322101013210003023210101...hear
assign x (cons 3 | cons 0 | cons 2 | cons 4 1) | = 3 | car $x;
2111032100110322101013211302321010132...hear
assign x (cons 3 | cons 0 | cons 2 | cons 4 1) | = 0 | car | cdr $x;
2111032100110322101013211302321010132...hear
assign x (cons 3 | cons 0 | cons 2 | cons 4 1) | = 2 | car | cdr | cdr $x;
2111032100110322101013211302321010132...hear
assign x (cons 3 | cons 0 | cons 2 | cons 4 1) | = 4 | car | cdr | cdr | cdr $x;
2111032100110322101013211302321010132...hear
assign x (cons 3 | cons 0 | cons 2 | cons 4 1) | = 1 | cdr | cdr | cdr | cdr $x;
2111032100110322101013211302321010132...hear

16. introduce mutable objects, and side-effects

intro make-cell;
20321101132233hear
intro set!;
20321110032233hear
intro get!;
20321110132233hear
define demo:make-cell:x | make-cell 14;
2110132111110302321101132111032233hear
= (get! $demo:make-cell:x) 14;
2103221110132210321111103332111032233hear
set! $demo:make-cell:x 15;
2111003221032111110332111132233hear
= (get! $demo:make-cell:x) 15;
2103221110132210321111103332111132233hear
set! $demo:make-cell:x 5;
211100322103211111033210132233hear
set! $demo:make-cell:x 7;
211100322103211111033211132233hear
= (get! $demo:make-cell:x) 7;
210322111013221032111110333211132233hear
define demo:make-cell:y | make-cell 11;
2110132111111302321101132101132233hear
= (get! $demo:make-cell:y) 11;
2103221110132210321111113332101132233hear
set! $demo:make-cell:y 22;
21110032210321111113321011032233hear
= (get! $demo:make-cell:y) 22;
21032211101322103211111133321011032233hear
= (get! $demo:make-cell:x) 7;
210322111013221032111110333211132233hear
= 29 (+ (get! $demo:make-cell:x) | get! $demo:make-cell:y);
2103211101322101032211101322103211111...hear
if (= (get! $demo:make-cell:x) 7) (set! $demo:make-cell:x 88) (set! $demo:make-cell:x 99);
2111132210322111013221032111110333211...hear
= (get! $demo:make-cell:x) 88;
2103221110132210321111103332101100032233hear
if (= (get! $demo:make-cell:x) 7) (set! $demo:make-cell:x 88) (set! $demo:make-cell:x 99);
2111132210322111013221032111110333211...hear
= (get! $demo:make-cell:x) 99;
2103221110132210321111103332110001132233hear

17. illustrate lists and some list operators

# to make list describable as a function, need to preceed lists
# ... with an argument count
# Lists keep an explicit record of their length
# this is to avoid the need for using a special 'nil' symbol
# ... which cannot itself be placed in the list.
# pending: should introduce number? check function
define list-helper | ? n | ? ret | if (> $n 1) (? x | list-helper (- $n 1) (? y | ? z | ret (+ 1 $y) (cons $x $z))) (? x | ret 1 $x);
2110132100000030232110032100000130232...hear
define list | ? n | if (= $n 0) (cons 0 0) (list-helper $n (? y | ? z | cons $y $z));
2110132100001130232110032100000130232...hear
define head | ? lst | if (= (car $lst) 0) $undefined (if (= (car $lst) 1) (cdr $lst) (car | cdr $lst));
2110132100010030232110032100010130232...hear
define tail | ? lst | if (= (car $lst) 0) $undefined (if (= (car $lst) 1) (cons 0 0) (cons (- (car $lst) 1) (cdr | cdr $lst)));
2110132100011030232110032100010130232...hear
define list-length | ? lst | car $lst;
2110132100011130232110032100010130232...hear
define list-ref | ? lst | ? n | if (= (list-ref $lst) 0) $undefined (if (= $n 0) (head $lst) (list-ref (tail $lst) (- $n 1)));
2110132100100030232110032100010130232...hear
define prepend | ? x | ? lst | if (= (list-length $lst) 0) (cons 1 $x) (cons (+ (list-length $lst) 1) (cons $x (cdr $lst)));
2110132100100130232110032100110302321...hear
define equal | ? x | ? y | if (= (number? $x) (number? $y)) (if (number? $x) (= $x $y) (list= $x $y)) $false;
2110132100030232110032100110302321100...hear
define list= | ? x | ? y | if (= (list-length $x) (list-length $y)) (if (> (list-length $x) 0) (and (equal (head $x) (head $y)) (list= (tail $x) (tail $y))) $true) $false;
2110132100101030232110032100110302321...hear
= (list-length | (list 0)) 0;
210322100011130232210000113203332032233hear
= (list-length | (list 4) 6 1 0 4) 4;
2103221000111302322100001132100332110...hear
= (list-length | (list 6) 6 2 7 0 9 4) 6;
2103221000111302322100001132110332110...hear
= (list-length | (list 2) 4 9) 2;
2103221000111302322100001132103321003...hear
= (list-length | (list 3) 6 1 7) 3;
2103221000111302322100001132113321103...hear
= (head | (list 6) 12 11 10 4 1 5) 12;
2103221000100302322100001132110332110...hear
list= (tail | (list 6) 12 11 10 4 1 5) ((list 5) 11 10 4 1 5);
2100101032210001103023221000011321103...hear
= (head | (list 8) 15 13 12 7 10 11 13 18) 15;
2103221000100302322100001132100033211...hear
list= (tail | (list 8) 15 13 12 7 10 11 13 18) ((list 7) 13 12 7 10 11 13 18);
2100101032210001103023221000011321000...hear
= (head | (list 2) 11 1) 11;
2103221000100302322100001132103321011...hear
list= (tail | (list 2) 11 1) ((list 1) 1);
2100101032210001103023221000011321033...hear
= (head | (list 6) 5 19 4 16 6 11) 5;
2103221000100302322100001132110332101...hear
list= (tail | (list 6) 5 19 4 16 6 11) ((list 5) 19 4 16 6 11);
2100101032210001103023221000011321103...hear
= (head | (list 10) 12 18 7 4 9 18 6 16 6 18) 12;
2103221000100302322100001132101033211...hear
list= (tail | (list 10) 12 18 7 4 9 18 6 16 6 18) ((list 9) 18 7 4 9 18 6 16 6 18);
2100101032210001103023221000011321010...hear
= (head | (list 6) 19 7 3 10 19 13) 19;
2103221000100302322100001132110332100...hear
list= (tail | (list 6) 19 7 3 10 19 13) ((list 5) 7 3 10 19 13);
2100101032210001103023221000011321103...hear
= (head | (list 6) 19 7 19 12 16 13) 19;
2103221000100302322100001132110332100...hear
list= (tail | (list 6) 19 7 19 12 16 13) ((list 5) 7 19 12 16 13);
2100101032210001103023221000011321103...hear
= (head | (list 1) 3) 3;
2103221000100302322100001132133211332...hear
list= (tail | (list 1) 3) ((list 0));
2100101032210001103023221000011321332...hear
= (head | (list 3) 2 19 17) 2;
2103221000100302322100001132113321032...hear
list= (tail | (list 3) 2 19 17) ((list 2) 19 17);
2100101032210001103023221000011321133...hear
= (head | (list 7) 1 16 5 14 6 19 2) 1;
2103221000100302322100001132111332132...hear
list= (tail | (list 7) 1 16 5 14 6 19 2) ((list 6) 16 5 14 6 19 2);
2100101032210001103023221000011321113...hear
= (list-ref ((list 3) 18 14 17) 1) 14;
2103221001000322210000113211332100103...hear
= (list-ref ((list 3) 8 11 10) 2) 10;
2103221001000322210000113211332100032...hear
= (list-ref ((list 8) 15 0 4 9 9 2 10 17) 3) 9;
2103221001000322210000113210003321111...hear
= (list-ref ((list 7) 4 8 8 5 14 5 13) 4) 14;
2103221001000322210000113211133210032...hear
= (list-ref ((list 4) 1 4 7 18) 2) 7;
2103221001000322210000113210033213210...hear
= (list-ref ((list 3) 12 2 3) 1) 2;
2103221001000322210000113211332110032...hear
= (list-ref ((list 6) 12 5 7 15 7 16) 2) 7;
2103221001000322210000113211033211003...hear
= (list-ref ((list 8) 5 15 7 14 7 1 11 19) 0) 5;
2103221001000322210000113210003321013...hear
= (list-ref ((list 3) 19 17 8) 2) 8;
2103221001000322210000113211332100113...hear
= (list-ref ((list 4) 10 10 4 11) 1) 10;
2103221001000322210000113210033210103...hear
list= ((list 0)) ((list 0));
2100101032221000011320333222100001132...hear
list= ((list 1) 4) ((list 1) 4);
2100101032221000011321332100332221000...hear
list= ((list 2) 7 5) ((list 2) 7 5);
2100101032221000011321033211132101332...hear
list= ((list 3) 15 13 11) ((list 3) 15 13 11);
2100101032221000011321133211113211013...hear
list= ((list 4) 2 8 0 6) ((list 4) 2 8 0 6);
2100101032221000011321003321032100032...hear
# this next batch of examples are a bit misleading, should streamline
not | list= ((list 0)) ((list 1) 9);
2100302321001010322210000113203332221...hear
not | list= ((list 0)) ((list 1) 5);
2100302321001010322210000113203332221...hear
not | list= ((list 1) 18) ((list 2) 8 18);
2100302321001010322210000113213321001...hear
not | list= ((list 1) 18) ((list 2) 18 5);
2100302321001010322210000113213321001...hear
not | list= ((list 2) 11 18) ((list 3) 7 11 18);
2100302321001010322210000113210332101...hear
not | list= ((list 2) 11 18) ((list 3) 11 18 6);
2100302321001010322210000113210332101...hear
not | list= ((list 3) 7 19 17) ((list 4) 6 7 19 17);
2100302321001010322210000113211332111...hear
not | list= ((list 3) 7 19 17) ((list 4) 7 19 17 0);
2100302321001010322210000113211332111...hear
not | list= ((list 4) 10 0 11 1) ((list 5) 0 10 0 11 1);
2100302321001010322210000113210033210...hear
not | list= ((list 4) 10 0 11 1) ((list 5) 10 0 11 1 8);
2100302321001010322210000113210033210...hear
# some helpful functions
list= (prepend 8 ((list 0))) ((list 1) 8);
2100101032210010013210003222100001132...hear
list= (prepend 11 ((list 1) 8)) ((list 2) 11 8);
2100101032210010013210113222100001132...hear
list= (prepend 13 ((list 2) 1 12)) ((list 3) 13 1 12);
2100101032210010013211013222100001132...hear
list= (prepend 0 ((list 3) 7 7 5)) ((list 4) 0 7 7 5);
2100101032210010013203222100001132113...hear
list= (prepend 16 ((list 4) 16 0 19 3)) ((list 5) 16 16 0 19 3);
2100101032210010013210000322210000113...hear
list= (prepend 10 ((list 5) 5 6 7 9 10)) ((list 6) 10 5 6 7 9 10);
2100101032210010013210103222100001132...hear
list= (prepend 19 ((list 6) 3 19 18 6 10 16)) ((list 7) 19 3 19 18 6 10 16);
2100101032210010013210011322210000113...hear
list= (prepend 19 ((list 7) 17 17 10 1 18 12 14)) ((list 8) 19 17 17 10 1 18 12 14);
2100101032210010013210011322210000113...hear
define pair | ? x | ? y | (list 2) $x $y;
2110132100101130232110032100110302321...hear
define first | ? lst | head $lst;
2110132100110030232110032100010130232...hear
define second | ? lst | head | tail $lst;
2110132100110130232110032100010130232...hear
list= (pair 3 6) ((list 2) 3 6);
2100101032210010113211321103322210000...hear
= (first | pair 3 6) 3;
2103221001100302321001011321132110332...hear
= (second | pair 3 6) 6;
2103221001101302321001011321132110332...hear
list= (pair 4 9) ((list 2) 4 9);
2100101032210010113210032100133222100...hear
= (first | pair 4 9) 4;
2103221001100302321001011321003210013...hear
= (second | pair 4 9) 9;
2103221001101302321001011321003210013...hear
list= (pair 8 3) ((list 2) 8 3);
2100101032210010113210003211332221000...hear
= (first | pair 8 3) 8;
2103221001100302321001011321000321133...hear
= (second | pair 8 3) 3;
2103221001101302321001011321000321133...hear
define list-find-helper | ? lst | ? key | ? fail | ? idx | if (= (list-length $lst) 0) (fail 0) (if (equal (head $lst) $key) $idx (list-find-helper (tail $lst) $key $fail (+ $idx 1)));
2110132100111030232110032100010130232...hear
define list-find | ? lst | ? key | ? fail | list-find-helper $lst $key $fail 0;
2110132101001030232110032100010130232...hear
define example-fail | ? x 100;
2110132101001130232110032100110321100...hear
= (list-find ((list 1) 13) 13 $example-fail) 0;
2103221010010322210000113213321101332...hear
= (list-find ((list 10) 0 9 8 16 15 14 17 5 9 2) 15 $example-fail) 4;
2103221010010322210000113210103320321...hear
= (list-find ((list 3) 7 4 10) 7 $example-fail) 0;
2103221010010322210000113211332111321...hear
= (list-find ((list 6) 0 17 10 13 11 5) 17 $example-fail) 1;
2103221010010322210000113211033203210...hear
= (list-find ((list 3) 12 9 6) 12 $example-fail) 0;
2103221010010322210000113211332110032...hear
= (list-find ((list 7) 17 1 4 17 14 13 13) 14 $example-fail) 4;
2103221010010322210000113211133210001...hear
= (list-find ((list 3) 2 15 2) 15 $example-fail) 1;
2103221010010322210000113211332103211...hear
= (list-find ((list 9) 6 13 10 8 10 9 6 15 18) 13 $example-fail) 1;
2103221010010322210000113210013321103...hear
= (list-find ((list 3) 12 16 0) 12 $example-fail) 0;
2103221010010322210000113211332110032...hear
= (list-find ((list 1) 15) 15 $example-fail) 0;
2103221010010322210000113213321111332...hear
= (list-find ((list 4) 2 17 11 5) 14 $example-fail) 100;
2103221010010322210000113210033210321...hear
= (list-find ((list 6) 12 1 19 6 17 9) 2 $example-fail) 100;
2103221010010322210000113211033211003...hear
= (list-find ((list 8) 11 6 17 8 13 10 9 16) 19 $example-fail) 100;
2103221010010322210000113210003321011...hear

18. describe changes to the implicit interpreter to allow new special forms

define base-translate $translate;
21101321010100322103211001332233hear
define translate | ? x | if (= $x 32) 64 (base-translate $x);
2110132110013023211003210011030232111...hear
= 32 64;
2103210000032100000032233hear
= (+ 32 64) 128;
2103221010321000003210000003321000000...hear
define translate $base-translate;
21101321100132210321010100332233hear
not | = 32 64;
210030232103210000032100000032233hear
= (+ 32 64) 96;
2103221010321000003210000003321100000...hear
# now can create a special form for lists
define translate | ? x | if (number? $x) (base-translate $x) (if (= (head $x) vector) (translate | prepend ((list 2) list (list-length | tail $x)) (tail $x)) (base-translate $x));
2110132110013023211003210011030232111...hear
list= (vector 1 2 3) ((list 3) 1 2 3);
2100101032210000321321032113322210000...hear
# now to desugar let expressions
define translate-with-vector $translate;
21101321010101322103211001332233hear
define translate-let-form | ? x | ? body | if (= (list-length $x) 0) (translate $body) (translate-let-form (tail $x) (vector (vector ? (head | head $x) $body) (head | tail | head $x)));
2110132101011030232110032100110302321...hear
define translate | ? x | if (number? $x) (translate-with-vector $x) (if (= (head $x) let) (translate-let-form (head | tail $x) (head | tail | tail $x)) (translate-with-vector $x));
2110132110013023211003210011030232111...hear
let ((x 20)) (= $x 20);
2101100032221001103210100333221032210...hear
let ((x 50) (y 20)) (= (- $x $y) 30);
2101100032221001103211001033221100013...hear
# the is-list function is now on dubious ground
# this stuff will be replaced with typing ASAP
define is-list | ? x | not | number? $x;
2110132101100130232110032100110302321...hear
is-list | (list 2) 1 3;
21011001302322100001132103321321132233hear
is-list | (list 0);
210110013023221000011320332233hear
not | is-list 23;
2100302321011001321011132233hear
is-list | (list 3) ((list 2) 2 3) 1 (? x | + $x 10);
2101100130232210000113211332221000011...hear

19. introduce sugar for let

# if would be good to introduce desugarings more rigorously, but for now...
# ... just a very vague sketch
intro let;
2032101100032233hear
= (let ((x 10)) (+ $x 5)) ((? x | + $x 5) 10);
2103221011000322210011032101033322101...hear
= (let ((x 10) (y 5)) (+ $x $y)) (((? x | ? y | + $x $y) 10) 5);
2103221011000322210011032101033221100...hear

20. build up functions of several variables

= ((? x | ? y | - $x $y) 4 0) 4;
2103222110032100110302321100321100013...hear
= ((? x | ? y | - $x $y) 11 8) 3;
2103222110032100110302321100321100013...hear
= ((? x | ? y | - $x $y) 5 5) 0;
2103222110032100110302321100321100013...hear
= ((? x | ? y | - $x $y) 10 1) 9;
2103222110032100110302321100321100013...hear
= ((? x | ? y | - $x $y) 10 7) 3;
2103222110032100110302321100321100013...hear
define last | ? x | list-ref $x (- (list-length $x) 1);
2110132101101030232110032100110302321...hear
define except-last | ? x | if (> (list-length $x) 1) (prepend (head $x) (except-last | tail $x)) (vector);
2110132101101130232110032100110302321...hear
# test last and except-last
= 15 (last | vector 4 5 15);
2103211113221011010302321000032100321...hear
list= (vector 4 5) (except-last | vector 4 5 15);
2100101032210000321003210133221011011...hear
intro lambda;
20321101032233hear
define prev-translate $translate;
21101321011100322103211001332233hear
define translate | let ((prev $prev-translate)) (? x | if (number? $x) (prev $x) (if (= (head $x) lambda) (let ((formals (head | tail $x)) (body (head | tail | tail $x))) (if (> (list-length $formals) 0) (translate (vector lambda (except-last $formals) (vector ? (last $formals) $body))) (translate $body))) (prev $x)));
2110132110013023210110003222101110132...hear
# test lambda
= ((lambda (x y) (- $x $y)) 8 3) 5;
2103222110103221001103211000133221011...hear
= ((lambda (x y) (- $x $y)) 1 1) 0;
2103222110103221001103211000133221011...hear
= ((lambda (x y) (- $x $y)) 10 9) 1;
2103222110103221001103211000133221011...hear
= ((lambda (x y) (- $x $y)) 7 5) 2;
2103222110103221001103211000133221011...hear
= ((lambda (x y) (- $x $y)) 9 8) 1;
2103222110103221001103211000133221011...hear
define apply | lambda (x y) (if (list= $y (vector)) $x (apply ($x (head $y)) (tail $y)));
2110132101111130232110103221001103211...hear
= (apply (lambda (x y) (- $x $y)) (vector 8 6)) 2;
2103221011111322110103221001103211000...hear
= (apply (lambda (x y) (- $x $y)) (vector 5 0)) 5;
2103221011111322110103221001103211000...hear
= (apply (lambda (x y) (- $x $y)) (vector 12 9)) 3;
2103221011111322110103221001103211000...hear
= (apply (lambda (x y) (- $x $y)) (vector 13 8)) 5;
2103221011111322110103221001103211000...hear
= (apply (lambda (x y) (- $x $y)) (vector 11 3)) 8;
2103221011111322110103221001103211000...hear

21. show map function for applying a function across the elements of a list

define map | lambda (p lst) (if (> (list-length $lst) 0) (prepend (p (head $lst)) (map $p (tail $lst))) (vector));
2110132110000030232110103221100001321...hear
list= (map (? x | * $x 2) (vector 0 8 15)) (vector 0 16 30);
2100101032211000003221100321001103023...hear
list= (map (? x | * $x 2) (vector 12 4 0 9)) (vector 24 8 0 18);
2100101032211000003221100321001103023...hear
list= (map (? x | * $x 2) (vector 8 9 5 7 10)) (vector 16 18 10 14 20);
2100101032211000003221100321001103023...hear
list= (map (? x | * $x 2) (vector 10 12 19 8 3 1)) (vector 20 24 38 16 6 2);
2100101032211000003221100321001103023...hear
list= (map (? x 42) (vector 5 18 4)) (vector 42 42 42);
2100101032211000003221100321001103210...hear
list= (map (? x 42) (vector 3 10 17 11)) (vector 42 42 42 42);
2100101032211000003221100321001103210...hear
list= (map (? x 42) (vector 5 13 6 16 2)) (vector 42 42 42 42 42);
2100101032211000003221100321001103210...hear
list= (map (? x 42) (vector 9 1 19 14 6 10)) (vector 42 42 42 42 42 42);
2100101032211000003221100321001103210...hear
define crunch | lambda (p lst) (if (>= (list-length $lst) 2) (p (head $lst) (crunch $p (tail $lst))) (if (= (list-length $lst) 1) (head $lst) $undefined));
2110132110001030232110103221100001321...hear
= (crunch $+ (vector 5 12 2)) 19;
2103221100010322103210103322100003210...hear
= (crunch $+ (vector 11 18 1 4)) 34;
2103221100010322103210103322100003210...hear
= (crunch $+ (vector 15 13 10 12 2)) 52;
2103221100010322103210103322100003211...hear
= (crunch $+ (vector 12 6 17 15 4 10)) 64;
2103221100010322103210103322100003211...hear

22. end of part 1, start of part 2

# The following parts of the message are experimental, and not
# carefully integrated with the main body
intro part2;
2032110001132233hear

23. show an example of recursive evaluation

# skipping over a lot of definitions and desugarings
define easy-factorial | ? f | ? x | if (> $x 0) (* $x | f $f (- $x 1)) 1;
2110132110010030232110032110010130232...hear
define factorial | ? x | if (> $x 0) (* $x | factorial | - $x 1) 1;
2110132111010302321100321001103023211...hear
= (easy-factorial $easy-factorial 0) 1;
2103221100100322103211001003320332132233hear
= (easy-factorial $easy-factorial 1) 1;
2103221100100322103211001003321332132233hear
= (easy-factorial $easy-factorial 2) 2;
2103221100100322103211001003321033210...hear
= (easy-factorial $easy-factorial 3) 6;
2103221100100322103211001003321133211...hear
= (easy-factorial $easy-factorial 4) 24;
2103221100100322103211001003321003321...hear
= (easy-factorial $easy-factorial 5) 120;
2103221100100322103211001003321013321...hear
= (factorial 0) 1;
210322111010320332132233hear
= (factorial 1) 1;
210322111010321332132233hear
= (factorial 2) 2;
21032211101032103321032233hear
= (factorial 3) 6;
210322111010321133211032233hear
= (factorial 4) 24;
210322111010321003321100032233hear
= (factorial 5) 120;
21032211101032101332111100032233hear

24. some pure lambda calculus definitions - optional

# these definitions are not quite what we want
# since thinking of everything as a function requires headscratching
# it would be better to use these as a parallel means of evaluation
# ... for expressions
define pure-if | ? x | ? y | ? z | x $y $z;
2110132110011030232110032100110302321...hear
define pure-true | ? y | ? z | y;
2110132110011130232110032110001302321...hear
define pure-false | ? y | ? z | z;
2110132110100030232110032110001302321...hear
define pure-cons | ? x | ? y | ? z | pure-if $z $x $y;
2110132110100130232110032100110302321...hear
define pure-car | ? x | x $pure-true;
2110132110101030232110032100110302321...hear
define pure-cdr | ? x | x $pure-false;
2110132110101130232110032100110302321...hear
define zero | ? f | ? x $x;
2110132110110030232110032110010130232...hear
define one | ? f | ? x | f $x;
2110132110110130232110032110010130232...hear
define two | ? f | ? x | f (f $x);
2110132110111030232110032110010130232...hear
define succ | ? n | ? f | ? x | f ((n $f) $x);
2110132110111130232110032100000130232...hear
define add | ? a | ? b | (a $succ) $b;
2110132111000030232110032111000130232...hear
define mult | ? a | ? b | (a (add $b)) $zero;
2110132111001130232110032111000130232...hear
define pred | ? n | pure-cdr | (n (? p | pure-cons (succ | pure-car $p) (pure-car $p))) (pure-cons $zero $zero);
2110132111010030232110032100000130232...hear
define is-zero | ? n | (n (? dummy $pure-false) $pure-true);
2110132111010130232110032100000130232...hear
define fixed-point | ? f | (? x | f (x $x)) (? x | f (x $x));
2110132111011130232110032110010130232...hear
# .. but for rest of message will assume that define does fixed-point for us
# now build a link between numbers and church number functions
define unchurch | ? c | c (? x | + $x 1) 0;
2110132111100030232110032111100130232...hear
= 0 (unchurch $zero);
2103203221111000322103211011003332233hear
= 1 (unchurch $one);
2103213221111000322103211011013332233hear
= 2 (unchurch $two);
21032103221111000322103211011103332233hear
define church | ? x | if (= 0 $x) $zero (succ | church | - $x 1);
2110132111101030232110032100110302321...hear

25. introduce universal quantifier

# really need to link with sets for true correctness
# and the examples here are REALLY sparse, need much more
intro forall;
20321001132233hear
< 5 (+ 5 1);
2132101322101032101321332233hear
< 4 (+ 4 1);
2132100322101032100321332233hear
< 3 (+ 3 1);
21321132210103211321332233hear
< 2 (+ 2 1);
21321032210103210321332233hear
< 1 (+ 1 1);
213213221010321321332233hear
< 0 (+ 0 1);
213203221010320321332233hear
forall (? x | < $x (+ $x 1));
2100113221100321001103023213221032100...hear
< 5 (* 5 2);
21321013221001321013210332233hear
< 4 (* 4 2);
21321003221001321003210332233hear
< 3 (* 3 2);
213211322100132113210332233hear
< 2 (* 2 2);
213210322100132103210332233hear
< 1 (* 1 2);
2132132210013213210332233hear
not | < 0 (* 0 2);
210030232132032210013203210332233hear
not | forall (? x | < $x (* $x 2));
2100302321001132211003210011030232132...hear

26. introduce existential quantifier

# really need to link with sets for true correctness
# and the examples here are REALLY sparse, need much more
not | = 5 (* 2 2);
2100302321032101322100132103210332233hear
= 4 (* 2 2);
21032100322100132103210332233hear
not | = 3 (* 2 2);
210030232103211322100132103210332233hear
not | = 2 (* 2 2);
210030232103210322100132103210332233hear
not | = 1 (* 2 2);
21003023210321322100132103210332233hear
not | = 0 (* 2 2);
21003023210320322100132103210332233hear
intro exists;
20321010032233hear
exists (? x | = $x (* 2 2));
2101003221100321001103023210322103210...hear
not | = 5 (+ 5 2);
21003023210321013221010321013210332233hear
not | = 4 (+ 4 2);
21003023210321003221010321003210332233hear
not | = 3 (+ 3 2);
210030232103211322101032113210332233hear
not | = 2 (+ 2 2);
210030232103210322101032103210332233hear
not | = 1 (+ 1 2);
2100302321032132210103213210332233hear
not | = 0 (+ 0 2);
2100302321032032210103203210332233hear
not (exists (? x | = $x (+ $x 2)));
2100322101003221100321001103023210322...hear

27. introduce logical implication

intro =>;
2032111101132233hear
define => | ? x | ? y | not | and $x (not $y);
2110132111101130232110032100110302321...hear
=> $true $true;
2111101132210321101103322103211011033...hear
not | => $true $false;
2100302321111011322103211011033221032...hear
=> $false $true;
2111101132210321101113322103211011033...hear
=> $false $false;
2111101132210321101113322103211011133...hear
forall (? x | forall (? y | => (=> $x $y) (=> (not $y) (not $x))));
2100113221100321001103023210011322110...hear

28. introduce sets and set membership

intro element;
2032111110032233hear
define element | ? x | ? lst | not | = (list-find-helper $lst $x (? y 0) 1) 0;
2110132111110030232110032100110302321...hear
element 0 (vector 0 4 8 3 5);
2111110032032210000320321003210003211...hear
element 5 (vector 0 4 8 3 5);
2111110032101322100003203210032100032...hear
element 3 (vector 0 4 8 3 5);
2111110032113221000032032100321000321...hear
element 3 (vector 3 5 1 0 9);
2111110032113221000032113210132132032...hear
element 1 (vector 3 5 1 0 9);
2111110032132210000321132101321320321...hear
element 5 (vector 3 5 1 0 9);
2111110032101322100003211321013213203...hear
element 5 (vector 8 1 6 2 0 5);
2111110032101322100003210003213211032...hear
element 6 (vector 8 1 6 2 0 5);
2111110032110322100003210003213211032...hear
element 5 (vector 8 1 6 2 0 5);
2111110032101322100003210003213211032...hear
element 5 (vector 5 3 8 6 2 9);
2111110032101322100003210132113210003...hear
element 5 (vector 5 3 8 6 2 9);
2111110032101322100003210132113210003...hear
element 9 (vector 5 3 8 6 2 9);
2111110032100132210000321013211321000...hear
element 7 (vector 1 7 2 6 4 5);
2111110032111322100003213211132103211...hear
element 2 (vector 1 7 2 6 4 5);
2111110032103221000032132111321032110...hear
element 6 (vector 1 7 2 6 4 5);
2111110032110322100003213211132103211...hear
not | element 7 (vector 8 3 9 6);
2100302321111100321113221000032100032...hear
not | element 1 (vector 8 6 3 5 4);
2100302321111100321322100003210003211...hear
not | element 2 (vector 9 5 6);
2100302321111100321032210000321001321...hear
not | element 5 (vector 2 0 7);
2100302321111100321013221000032103203...hear
not | element 6 (vector 3 5);
2100302321111100321103221000032113210...hear
# rules for set equality
define set-subset | ? x | ? y | if (> (list-length $x) 0) (and (element (head $x) $y) (set-subset (tail $x) $y)) (true);
2110132111110130232110032100110302321...hear
define set= | ? x | ? y | and (set-subset $x $y) (set-subset $y $x);
2110132111111030232110032100110302321...hear
set= (vector 1 5 9) (vector 5 1 9);
2111111032210000321321013210013322100...hear
set= (vector 1 5 9) (vector 9 1 5);
2111111032210000321321013210013322100...hear
not | set= (vector 1 5 9) (vector 1 5);
2100302321111110322100003213210132100...hear
# let's go leave ourselves wide open to Russell's paradox
# ... by using characteristic functions
# ... since it doesn't really matter for communication purposes
# ... and so far this is just used/tested with sets of integers really
element 5 (all (? x | = (+ $x 10) 15));
2111110032101322111103221100321001103...hear
element 3 (all (? x | = (* $x 3) (+ $x 6)));
2111110032113221111032211003210011030...hear
define empty-set | vector;
21101321111111302321000032233hear
element 0 $natural-set;
21111100320322103211111332233hear
forall (? x | => (element $x $natural-set) (element (+ $x 1) $natural-set));
2100113221100321001103023211110113221...hear
element 1 $natural-set;
21111100321322103211111332233hear
element 2 $natural-set;
211111003210322103211111332233hear
element 3 $natural-set;
211111003211322103211111332233hear
element 4 $natural-set;
2111110032100322103211111332233hear
element 5 $natural-set;
2111110032101322103211111332233hear
element 6 $natural-set;
2111110032110322103211111332233hear
element 7 $natural-set;
2111110032111322103211111332233hear
element 8 $natural-set;
21111100321000322103211111332233hear
element 9 $natural-set;
21111100321001322103211111332233hear
define boolean-set | vector $true $false;
2110132100000003023210000322103211011...hear
element $true $boolean-set;
2111110032210321101103322103210000000...hear
element $false $boolean-set;
2111110032210321101113322103210000000...hear
# actually, to simplify semantics elsewhere, true and false
# are now just 0 and 1 so they are not distinct from ints
define even-natural-set | all | ? x | exists | ? y | and (element $y $natural-set) (= (* 2 $y) $x);
2110132100000013023211110302321100321...hear
element 0 $natural-set;
21111100320322103211111332233hear
element 0 $even-natural-set;
21111100320322103210000001332233hear
element 1 $natural-set;
21111100321322103211111332233hear
not | element 1 $even-natural-set;
2100302321111100321322103210000001332233hear
element 2 $natural-set;
211111003210322103211111332233hear
element 2 $even-natural-set;
211111003210322103210000001332233hear
element 3 $natural-set;
211111003211322103211111332233hear
not | element 3 $even-natural-set;
2100302321111100321132210321000000133...hear
element 4 $natural-set;
2111110032100322103211111332233hear
element 4 $even-natural-set;
2111110032100322103210000001332233hear
element 5 $natural-set;
2111110032101322103211111332233hear
not | element 5 $even-natural-set;
2100302321111100321013221032100000013...hear
element 6 $natural-set;
2111110032110322103211111332233hear
element 6 $even-natural-set;
2111110032110322103210000001332233hear

29. introduce graph structures

define make-graph | lambda (nodes links) (pair $nodes $links);
2110132100000103023211010322100000113...hear
define test-graph | make-graph (vector 1 2 3 4) (vector (vector 1 2) (vector 2 3) (vector 1 4));
2110132100001013023210000010322100003...hear
define graph-linked | lambda (g n1 n2) (exists | ? idx | if (and (>= $idx 0) (< $idx (list-length | list-ref $g 1))) (list= (list-ref (list-ref $g 1) $idx) (vector $n1 $n2)) $false);
2110132100001103023211010322100001113...hear
= (graph-linked $test-graph 1 2) (true);
2103221000011032210321000010133213210...hear
= (graph-linked $test-graph 1 3) (false);
2103221000011032210321000010133213211...hear
= (graph-linked $test-graph 2 4) (false);
2103221000011032210321000010133210321...hear
# 'if' is used a lot in the next definition in place of and/or
# this is because I haven't established lazy evaluation forms for and/or
# so this very inefficient algorithm completely bogs down when combined
# ... during testing with a dumb implementation for 'exists'.
define graph-linked* | lambda (g n1 n2) (if (= $n1 $n2) $true (if (graph-linked $g $n1 $n2) $true (exists (? n3 | if (graph-linked $g $n1 $n3) (graph-linked* $g $n3 $n2) $false))));
2110132100010103023211010322100001113...hear
= (graph-linked* $test-graph 1 2) (true);
2103221000101032210321000010133213210...hear
= (graph-linked* $test-graph 1 3) (true);
2103221000101032210321000010133213211...hear
= (graph-linked* $test-graph 2 4) (false);
2103221000101032210321000010133210321...hear

30. show how to execute a sequence of instructions

intro begin;
20321000110032233hear
define prev-translate $translate;
21101321011100322103211001332233hear
define reverse | ? x | if (>= (list-length $x) 1) (prepend (last $x) (reverse | except-last $x)) $x;
2110132100011013023211003210011030232...hear
# test reverse
list= (vector 1 2 3) (reverse | vector 3 2 1);
2100101032210000321321032113322100011...hear
define translate | let ((prev $prev-translate)) (? x | if (number? $x) (prev $x) (if (= (head $x) begin) (translate (vector (vector ? x (vector last (vector x))) (prepend vector (tail $x)))) (prev $x)));
2110132110013023210110003222101110132...hear
= (begin 1 7 2 4) 4;
2103221000110032132111321032100332100...hear
= (begin (set! $demo:make-cell:x 88) (set! $demo:make-cell:x 6) (get! $demo:make-cell:x)) 6;
2103221000110032211100322103211111033...hear
= (begin (set! $demo:make-cell:y 88) (set! $demo:make-cell:x 6) (get! $demo:make-cell:y)) 88;
2103221000110032211100322103211111133...hear
= (begin (set! $demo:make-cell:x 88) (set! $demo:make-cell:x 6) (get! $demo:make-cell:x) 4) 4;
2103221000110032211100322103211111033...hear

31. introduce environment/hashmap structure

# this section needs a LOT more examples :-)
# note that at the time of writing (h 1 2) is same as ((h) 1 2)
define hash-add | lambda (h x y z) (if (equal $z $x) $y (h $z));
2110132100011103023211010322100011113...hear
define hash-ref | lambda (h x) (h $x);
2110132100100003023211010322100011113...hear
define hash-null | ? x $undefined;
2110132100100013023211003210011032210...hear
define hash-default | ? default | ? x $default;
2110132100100103023211003210010011302...hear
define test-hash | hash-add (hash-add $hash-null 3 2) 4 9;
2110132100101003023210001110322100011...hear
= (hash-ref $test-hash 4) 9;
2103221001000032210321001010033210033...hear
= (hash-ref $test-hash 3) 2;
2103221001000032210321001010033211332...hear
= (hash-ref $test-hash 8) $undefined;
2103221001000032210321001010033210003...hear
= (hash-ref $test-hash 15) $undefined;
2103221001000032210321001010033211113...hear
= (hash-ref (hash-add $test-hash 15 33) 15) 33;
2103221001000032210001110322103210010...hear
= (hash-ref $test-hash 15) $undefined;
2103221001000032210321001010033211113...hear
define make-hash | ? x | if (list= $x (vector)) $hash-null (hash-add (make-hash (tail $x)) (first | head $x) (second | head $x));
2110132100101013023211003210011030232...hear
= (hash-ref (make-hash | vector (pair 3 10) (pair 2 20) (pair 1 30)) 3) 10;
2103221001000032210010101302321000032...hear
= (hash-ref (make-hash | vector (pair 3 10) (pair 2 20) (pair 1 30)) 1) 30;
2103221001000032210010101302321000032...hear

32. introduce simple mutable structures

define mutable-struct | ? lst | let ((data (map (? x | make-cell 0) $lst))) (? key | list-ref $data (list-find $lst $key (? x 0)));
2110132100101103023211003210001013023...hear
define test-struct1 | mutable-struct | vector item1 item2 item3;
2110132100110003023210010110302321000...hear
set! (test-struct1 item1) 15;
211100322100110003210011001332111132233hear
= (get! | test-struct1 item1) 15;
2103221110130232100110003210011001332...hear

33. introduce method handler wrappers

define add-method | lambda (object name method) (hash-add $object $name (? dummy | method $object));
2110132100111003023211010322100111013...hear
define call | ? x | x 0;
2110132101000003023211003210011030232...hear
define test-struct2 | mutable-struct | vector x y;
2110132101000013023210010110302321000...hear
set! (test-struct2 x) 10;
2111003221010000132100110332101032233hear
set! (test-struct2 y) 20;
21110032210100001321100013321010032233hear
= (get! | test-struct2 x) 10;
2103221110130232101000013210011033210...hear
= (get! | test-struct2 y) 20;
2103221110130232101000013211000133210...hear
define test-struct3 | add-method $test-struct2 sum (? self | + (get! | self x) (get! | self y));
2110132101000103023210011100322103210...hear
= (get! | test-struct3 x) 10;
2103221110130232101000103210011033210...hear
= (get! | test-struct3 y) 20;
2103221110130232101000103211000133210...hear
= (call | test-struct3 sum) 30;
2103221010000030232101000103210100011...hear
set! (test-struct3 y) 10;
2111003221010001032110001332101032233hear
= (call | test-struct3 sum) 20;
2103221010000030232101000103210100011...hear
set! (test-struct2 y) 5;
211100322101000013211000133210132233hear
= (call | test-struct3 sum) 15;
2103221010000030232101000103210100011...hear

34. introduce turing machine model

# just for fun!
define safe-tail | ? x | if (> (list-length $x) 0) (if (> (list-length $x) 1) (tail $x) (vector | vector)) (vector | vector);
2110132101001013023211003210011030232...hear
define safe-head | ? x | if (> (list-length $x) 0) (head $x) (vector);
2110132101001103023211003210011030232...hear
define tape-read | ? tape | let ((x (second $tape))) (if (> (list-length $x) 0) (head $x) (vector));
2110132101001113023211003210101000302...hear
define tape-transition | lambda (tape shift value) (if (= $shift 1) (pair (prepend $value (first $tape)) (safe-tail | second $tape)) (if (= $shift 0) (pair (safe-tail | first $tape) (prepend (safe-head | first $tape) (prepend $value (safe-tail | second $tape)))) (pair (first $tape) (prepend $value (safe-tail | second $tape)))));
2110132101010013023211010322101010003...hear
define turing | lambda (machine current last tape) (if (= $current $last) $tape (let ((next (machine $current (tape-read $tape)))) (turing $machine (list-ref $next 0) $last (tape-transition $tape (list-ref $next 1) (list-ref $next 2)))));
2110132101011003023211010322101011013...hear
define make-tape | ? x | pair (vector) $x;
2110132101100003023211003210011030232...hear
define remove-trail | ? x | ? lst | if (> (list-length $lst) 0) (if (equal (last $lst) $x) (remove-trail $x (except-last $lst)) $lst) $lst;
2110132101100013023211003210011030232...hear
define extract-tape | ? x | remove-trail (vector) (second $x);
2110132101100103023211003210011030232...hear
define tm-binary-increment | make-hash | vector (pair right (make-hash | vector (pair 0 (vector right 1 0)) (pair 1 (vector right 1 1)) (pair (vector) (vector inc 0 (vector))))) (pair inc (make-hash | vector (pair 0 (vector noinc 0 1)) (pair 1 (vector inc 0 0)) (pair (vector) (vector halt 2 1)))) (pair noinc (make-hash | vector (pair 0 (vector noinc 0 0)) (pair 1 (vector noinc 0 1)) (pair (vector) (vector halt 1 (vector))))) (pair halt (make-hash | vector));
2110132101100113023210010101302321000...hear
list= (extract-tape | turing $tm-binary-increment right halt (make-tape | vector 1 0 0 1)) (vector 1 0 1 0);
2100101032210110010302321010110032210...hear
list= (extract-tape | turing $tm-binary-increment right halt (make-tape | vector 1 1 1)) (vector 1 0 0 0);
2100101032210110010302321010110032210...hear
list= (extract-tape | turing $tm-binary-increment right halt (make-tape | vector 1 1 1 0 0 0 1 1 1)) (vector 1 1 1 0 0 1 0 0 0);
2100101032210110010302321010110032210...hear

35. introduce simple form of typing, for ease of documentation.

# An object is simply a function that takes an argument.
# The argument is the method to call on the object.
# Types are here taken to be just the existence of a particular method,
# with that method returning an object of the appropriate type.
define make-integer
  (lambda (v)
    (lambda (x)
      (if (= (x) int)
      (v)
      0)));
2110132101110003221101032210100133221...hear
define objectify
  (? x 
     (if (number? (x))
     (make-integer (x))
     (x)));
2110132101110103221100321001103221111...hear
define instanceof
  (lambda (T t)
    (if (number? (t))
    (= (T) int)
    (not (number? ((objectify (t)) (T))))));
2110132101110113221101032210111100321...hear
# add version of lambda that allows types to be declared
define prev-translate (translate);
2110132101110032211001332233hear
define translate
  (let ((prev (prev-translate)))
    (? x
      (if (number? (x))
        (prev (x))
        (if (= (head (x)) lambda)
          (let ((formals (head (tail (x))))
                (body (head (tail (tail (x))))))
            (if (> (list-length (formals)) 0)
        (if (number? (last (formals)))
            (translate
             (vector
              lambda
              (except-last (formals))
              (vector ? (last (formals)) (body))))
            (let ((formal-name (first (last (formals))))
              (formal-type (second (last (formals)))))
              (translate
               (vector
            lambda
            (except-last (formals))
            (vector 
             ? 
             (formal-name) 
             (vector 
              let
              (vector (vector 
                   (formal-name) 
                   (vector
                    (vector objectify (vector (formal-name)))
                    (formal-type))))
              (body)))))))
        (translate (body))))
          (prev (x))))));
2110132110013221011000322210111013221...hear
# add conditional form
define prev-translate (translate);
2110132101110032211001332233hear
define translate
  (let ((prev (prev-translate)))
    (? x
      (if (number? (x))
        (prev (x))
        (if (= (head (x)) cond)
          (let ((cnd (head (tail (x))))
                (rem (tail (tail (x)))))
            (if (> (list-length (rem)) 0)
        (translate
         (vector
                  if
          (first (cnd))
          (second (cnd))
          (prepend cond (rem))))
        (translate (cnd))))
          (prev (x))))));
2110132110013221011000322210111013221...hear
= 99 (cond 99);
21032110001132211000000321100011332233hear
= 8 (cond ((true) 8) 11);
2103210003221100000032221101103321000...hear
= 11 (cond ((false) 8) 11);
2103210113221100000032221101113321000...hear
= 7 (cond ((false) 3) ((true) 7) 11);
2103211132211000000322211011133211332...hear
= 3 (cond ((true) 3) ((true) 7) 11);
2103211322110000003222110110332113322...hear
= 11 (cond ((false) 3) ((false) 7) 11);
2103210113221100000032221101113321133...hear
define remove-match 
  (lambda (test lst)
    (if (> (list-length (lst)) 0)
    (if (test (head (lst)))
        (remove-match (test) (tail (lst)))
        (prepend (head (lst)) (remove-match (test) (tail (lst)))))
    (lst)));
2110132110000113221101032211000100321...hear
define remove-element
  (lambda (x) 
    (remove-match (lambda (y) (= (y) (x)))));
2110132110001013221101032210011033221...hear
list= (vector 1 2 3 5) (remove-element 4 (vector 1 2 3 4 5));
2100101032210000321321032113210133221...hear
list= (vector 1 2 3 5) (remove-element 4 (vector 1 4 2 4 3 4 5));
2100101032210000321321032113210133221...hear
define return
  (lambda (T t)
    (let ((obj (objectify (t))))
      (obj (T))));
2110132110001103221101032210111100321...hear
define tester
  (lambda ((x int) (y int))
    (return int (+ (x) (y))));
2110132110010003221101032221001103210...hear
= 42 (tester (make-integer 10) (make-integer 32));
2103210101032211001000322101110003210...hear
= 42 (tester 10 32);
2103210101032211001000321010321000003...hear
define reflective
  (lambda (f)
    ((lambda (x)
       (f (lambda (y) ((x (x)) (y)))))
     (lambda (x)
       (f (lambda (y) ((x (x)) (y)))))));
2110132110010013221101032211001013322...hear

36. an example object -- a 2D point

define point
  (lambda (x y)
    (reflective
     (lambda (self msg)
       (cond ((= (msg) x) (x))
         ((= (msg) y) (y))
         ((= (msg) point) (self))
         ((= (msg) +) 
          (lambda ((p point))
        (point (+ (x) (p x))
               (+ (y) (p y)))))
         ((= (msg) =) 
          (lambda ((p point))
        (and (= (x) (p x))
             (= (y) (p y)))))
         0))));
2110132110010103221101032210011032110...hear
define point1 (point 1 11);
2110132110011003221100101032132101133...hear
define point2 (point 2 22);
2110132110011013221100101032103210110...hear
= 1 (point1 x);
2103213221100110032100110332233hear
= 22 (point2 y);
21032101103221100110132110001332233hear
= 11 ((point 11 12) x);
2103210113222110010103210113211003321...hear
= 11 (((point 11 12) point) x);
2103210113222211001010321011321100332...hear
= 16 (((point 16 17) point) x);
2103210000322221100101032100003210001...hear
= 33 (point1 + (point2) y);
2103210000132211001100321010322110011...hear
point1 + (point2) = (point 3 33);
2110011003210103221100110133210322110...hear
point2 + (point1) = (point 3 33);
2110011013210103221100110033210322110...hear
(point 100 200) + (point 200 100) = (point 300 300);
2211001010321100100321100100033210103...hear
instanceof point (point1);
210111011321100101032211001100332233hear
not (instanceof int (point1));
2100322101110113210111001322110011003...hear
instanceof int 5;
21011101132101110013210132233hear
not (instanceof point 5);
210032210111011321100101032101332233hear

37. an example object -- a container

define container
  (lambda (x)
    (let ((contents (make-cell (vector))))
      (reflective
       (lambda (self msg)
     (cond ((= (msg) container) (self))
           ((= (msg) inventory) (get! (contents)))
           ((= (msg) add)
        (lambda (x) 
          (if (not (element (x) (get! (contents))))
              (set! (contents) (prepend (x) (get! (contents))))
              (false))))
           ((= (msg) remove)
        (lambda (x)
          (set! (contents) (remove-element (x) (get! (contents))))))
           ((= (msg) =)
        (lambda ((c container))
          (set= (self inventory) (c inventory))))
           0)))));
2110132110011103221101032210011033221...hear
# Can pass anything to container function to create an object
# Should eventually use a consistent protocol for all objects,
# but all this stuff is still in flux
define pocket (container new);
2110132110100103221100111032110100113...hear
pocket add 77;
21101001032111000032100110132233hear
pocket add 88;
21101001032111000032101100032233hear
pocket add 99;
21101001032111000032110001132233hear
set= (pocket inventory) (vector 77 88 99);
2111111032211010010321101000033221000...hear
pocket remove 88;
211010010321101000132101100032233hear
set= (pocket inventory) (vector 77 99);
2111111032211010010321101000033221000...hear
define pocket2 (container new);
2110132110101003221100111032110100113...hear
pocket2 add 77;
21101010032111000032100110132233hear
pocket2 add 99;
21101010032111000032110001132233hear
pocket2 = (pocket);
211010100321032211010010332233hear

38. expressing inheritance

# counter-container adds one method to container: count
define counter-container
  (lambda (x)
    (let ((super (container new)))
      (reflective
       (lambda (self msg)
     (cond ((= (msg) counter-container) (self))
           ((= (msg) count) (list-length (super inventory)))
           (super (msg)))))));
2110132110101013221101032210011033221...hear
define cc1 (counter-container new);
2110132110110003221101010132110100113...hear
= 0 (cc1 count);
210320322110110003211010111332233hear
cc1 add 4;
2110110003211100003210032233hear
= 1 (cc1 count);
210321322110110003211010111332233hear
cc1 add 5;
2110110003211100003210132233hear
= 2 (cc1 count);
2103210322110110003211010111332233hear

39. adding a special form for classes

# need a bunch of extra machinery first, will push this
# back into previous sections eventually, and simplify
define list-append
  (lambda (lst1 lst2)
    (if (> (list-length (lst1)) 0)
    (list-append (except-last (lst1))
             (prepend (last (lst1)) (lst2)))
    (lst2)));
2110132110110013221101032211011010321...hear
list= (list-append (vector 1 2 3) (vector 4 5 6)) (vector 1 2 3 4 5 6);
2100101032211011001322100003213210321...hear
define append
  (? x
     (? lst
    (if (> (list-length (lst)) 0)
        (prepend (head (lst)) (append (x) (tail (lst))))
        (vector (x)))));
2110132110111003221100321001103221100...hear
list= (append 5 (vector 1 2)) (vector 1 2 5);
2100101032211011100321013221000032132...hear
define select-match 
  (lambda (test lst)
    (if (> (list-length (lst)) 0)
    (if (test (head (lst)))
        (prepend (head (lst)) (select-match (test) (tail (lst))))
        (select-match (test) (tail (lst))))
    (lst)));
2110132110111013221101032211000100321...hear
define unique
  (let ((store (make-cell 0)))
    (lambda (x)
      (let ((id (get! (store))))
    (begin
      (set! (store) (+ (id) 1))
      (id)))));
2110132110111103221011000322211011111...hear
= (unique new) 0;
210322110111103211010011332032233hear
= (unique new) 1;
210322110111103211010011332132233hear
= (unique new) 2;
2103221101111032110100113321032233hear
not (= (unique new) (unique new));
2100322103221101111032110100113322110...hear
define setup-this
  (lambda (this self)
    (if (number? | this)
    (self)
    (this)));
2110132111000013221101032211100010321...hear
# okay, here it comes.  don't panic!
# I need to split this up into helpers, and simplify.
# It basically just writes code for classes like we saw in
# a previous section.
define prev-translate (translate);
2110132101110032211001332233hear
define translate
  (let ((prev (prev-translate)))
    (? x
       (if (number? (x))
       (prev (x))
       (if (= (head (x)) class)
           (let ((name (list-ref (x) 1))
             (args (list-ref (x) 2))
             (fields (tail (tail (tail (x))))))
         (translate
          (vector
           define
           (name)
           (vector
            lambda
            (prepend ext-this (args))
            (vector
             let
             (append
              (vector unique-id (vector unique new))
              (map 
               (tail)
               (select-match (? x (= (first (x)) field)) (fields))))
             (vector
              let
              (vector
               (vector
            self
            (vector
             reflective
             (vector
              lambda
              (vector self)
              (vector
               let
               (vector 
                (vector
                 this
                 (vector setup-this 
                     (vector ext-this)
                     (vector self))))
               (vector 
                let
                (vector (vector ignore-this 1))
                (vector
                 lambda
                 (vector method)
                 (list-append
                  (prepend
                   cond
                   (list-append
                (map
                 (? x 
                    (vector
                     (vector = (vector method) (first (x)))
                     (second (x))))
                 (map (tail)
                      (select-match 
                       (? x (= (first (x)) method)) 
                       (fields))))
                (map
                 (? x 
                    (vector
                     (vector = (vector method) (x))
                     (vector (x))))
                 (map (second)
                      (select-match 
                       (? x (= (first (x)) field)) 
                       (fields))))))
                  (vector
                   (vector
                (vector = (vector method) self)
                (vector self))
                   (vector
                (vector = (vector method) (name))
                (vector self self))
                   (vector
                (vector = (vector method) classname)
                (name))
                   (vector
                (vector = (vector method) unknown)
                (vector lambda (vector x) 0))
                   (vector
                (vector = (vector method) new)
                0)
                   (vector
                (vector = (vector method) unique-id)
                (vector unique-id))
                   (vector
                (vector = (vector method) ==)
                (vector
                 lambda
                 (vector x)
                 (vector = 
                     (vector unique-id)
                     (vector x unique-id))))
                   (vector self unknown (vector method)))))))))))
              (vector 
               begin
               (vector self new)
               (vector self))))))))
           (prev (x))))));
2110132110013221011000322210111013221...hear
# revisit the point class example
class point (x y) 
       (method x (x))
       (method y (y))
       (method + (lambda ((p point))
           (point new 
              (+ (x) (p x))
              (+ (y) (p y)))))
       (method = (lambda ((p point))
           (and (= (x) (p x))
            (= (y) (p y)))));
2111000113211001010322100110321100013...hear
# note the appearance of new in the next line --
# this is the only difference to previous version
define point1 (point new 1 11);
2110132110011003221100101032110100113...hear
define point2 (point new 2 22);
2110132110011013221100101032110100113...hear
= 1 (point1 x);
2103213221100110032100110332233hear
= 22 (point2 y);
21032101103221100110132110001332233hear
= 11 ((point new 11 12) x);
2103210113222110010103211010011321011...hear
= 11 (((point new 11 12) point) x);
2103210113222211001010321101001132101...hear
= 16 (((point new 16 17) point) x);
2103210000322221100101032110100113210...hear
= 33 (point1 + (point2) y);
2103210000132211001100321010322110011...hear
point1 + (point2) = (point new 3 33);
2110011003210103221100110133210322110...hear
point2 + (point1) = (point new 3 33);
2110011013210103221100110033210322110...hear
(point new 100 200) + (point new 200 100) = (point new 300 300);
2211001010321101001132110010032110010...hear
instanceof point (point1);
210111011321100101032211001100332233hear
not (instanceof int (point1));
2100322101110113210111001322110011003...hear
# Check that virtual calls can be made to work.
# They are a little awkward right now.
# Should they be the default?
class c1 ()
       (method getid 100)
       (method altid (this getid));
2111000113211101101323221001111132111...hear
class c2 ()
       (field super-ref (make-cell 0))
       (method new (set! (super-ref) (c1 | this)))
       (method super (? x ((get! | super-ref) (x))))
       (method unknown (? x (self super | x)))
       (method getid 200);
2111000113211110000323221110100032111...hear
= 100 | c1 new altid;
2103211001003023211101101321101001132...hear
= 200 | c2 new altid;
2103211001000302321111000032110100113...hear

40. wrapper class for cells

class cell (initial-value)
       (field content (make-cell (initial-value)))
       (method get (get! (content)))
       (method set (lambda (new-value)
             (set! (content) (new-value))))
       (method reset (self set (initial-value)))
       (method unknown (lambda (x) ((objectify (self get)) (x))));
2111000113211110010322111100113322111...hear
define cell-test1 (cell new 15);
2110132111110013221111001032110100113...hear
= 15 (cell-test1 get);
210321111322111110013211110101332233hear
cell-test1 set 82;
211111001321111011032101001032233hear
= 82 (cell-test1 get);
210321010010322111110013211110101332233hear
define cell-test2 (cell new (point new 120 150));
2110132111110103221111001032110100113...hear
define cell-test3 (cell new (point new 300 300));
2110132111110113221111001032110100113...hear
cell-test2 + (cell-test3) = (point new 420 450);
2111110103210103221111101133210322110...hear
not (cell-test2 = (cell-test3));
2100322111110103210322111110113332233hear
cell-test3 set (cell-test2);
211111011321111011032211111010332233hear
cell-test2 = (cell-test3);
211111010321032211111011332233hear

41. playing around with doors and rooms

class door ((src room) (dest room))
       (method new (begin
             (src add (self))
             (dest add (self))))
       (method access-from (lambda ((current room))
                 (cond ((current == (src)) (dest))
                   ((current == (dest)) (src))
                   0)))
       (method is-present (lambda ((current room))
                (cond ((current == (src)) (true))
                  ((current == (dest)) (true))
                  (false))));
2111000113211111100322211111101321111...hear
class room (name)
       (field content (container new))
       (method name (name))
       (method unknown (lambda (x) (content (x))));
2111000113211111110322100111103322111...hear
# need to fix up containers to use object equality
define object-element
  (lambda (n lst)
    (> (list-length 
    (select-match (lambda (x) (x == (n))) (lst))) 
       0));
2110132100000010322110103221000001321...hear
class container ()
    (field contents (cell new (vector)))
    (method inventory (contents get))
    (method add (lambda (x) 
          (if (not (object-element (x) (contents get)))
              (contents set (prepend (x) (contents get)))
              (false))));
2111000113211001110323221110100032110...hear
define hall (room new 0);
2110132100000011322111111103211010011...hear
define kitchen (room new 1);
2110132100000100322111111103211010011...hear
define door1 (door new (hall) (kitchen));
2110132100000101322111111003211010011...hear
(first (hall inventory)) == (door1);
2210011003221000000113211010000333211...hear
(first (kitchen inventory)) == (door1);
2210011003221000001003211010000333211...hear
door1 access-from (hall) == (kitchen);
2100000101321000000003221000000113321...hear
not (door1 access-from (hall) == (hall));
2100322100000101321000000003221000000...hear
door1 access-from (kitchen) == (hall);
2100000101321000000003221000001003321...hear
define stairs (room new 2);
2110132100000110322111111103211010011...hear
define lawn (room new 3);
2110132100000111322111111103211010011...hear
define bedroom (room new 4);
2110132100001000322111111103211010011...hear
define nowhere (room new 0);
2110132100001001322111111103211010011...hear
define door2 (door new (hall) (lawn));
2110132100001010322111111003211010011...hear
define door3 (door new (hall) (stairs));
2110132100001011322111111003211010011...hear
define door4 (door new (stairs) (bedroom));
2110132100001100322111111003211010011...hear
class character ()
       (field location (cell new 0))
       (field name (cell new 0))
       (method set-room (lambda ((r room)) 
              (begin
                (if (not (number? | location get))
                (location get remove (self))
                0)
                (r add (self))
                (location set (r)))))
       (method get-room (location get))
       (method set-name (lambda (n) (name set | n)))
       (method get-name (name get))
       (method update 0);
2111000113210000110132322111010003210...hear
define find-max-helper
  (lambda (test max idx n lst)
    (if (> (list-length (lst)) 0)
    (if (> (test (head (lst))) (max))
        (find-max-helper (test) (test (head (lst))) (n) (+ (n) 1) (tail (lst)))
        (find-max-helper (test) (max) (idx) (+ (n) 1) (tail (lst))))
    (idx)));
2110132100010101322110103221100010032...hear
define find-max-idx
  (lambda (test lst)
    (find-max-helper (test) (test (head (lst))) 0 0 (lst)));
2110132100010110322110103221100010032...hear
define find-min-helper
  (lambda (test max idx n lst)
    (if (> (list-length (lst)) 0)
    (if (< (test (head (lst))) (max))
        (find-min-helper (test) (test (head (lst))) (n) (+ (n) 1) (tail (lst)))
        (find-min-helper (test) (max) (idx) (+ (n) 1) (tail (lst))))
    (idx)));
2110132100010111322110103221100010032...hear
define find-min-idx
  (lambda (test lst)
    (find-min-helper (test) (test (head (lst))) 0 0 (lst)));
2110132100011000322110103221100010032...hear
= 2 (find-max-idx (lambda (x) (x)) (vector 3 4 5 0));
2103210322100010110322110103221001103...hear
= 1 (find-max-idx (lambda (x) (x)) (vector 3 5 4 0));
2103213221000101103221101032210011033...hear
= 0 (find-max-idx (lambda (x) (x)) (vector 5 3 4 0));
2103203221000101103221101032210011033...hear
# the robo class makes a character that patrols from room to room
class robo ()
       (field super (character new))
       (field timestamp (cell new 1))
       (field timestamp-map (cell new (lambda (x) 0)))
       (method unknown (lambda (x) (super (x))))
       (method update 
           (let ((exits 
              (select-match (lambda (x) (instanceof door (x)))
                    (self location inventory))))
         (let ((timestamps
            (map (lambda (x) (timestamp-map get (x)))
                 (exits))))
           (let ((chosen-exit (list-ref 
                       (exits)
                       (find-min-idx (lambda (x) (x))
                             (timestamps))))
             (current-tmap (timestamp-map get))
             (current-t (timestamp get)))
             (begin
               (self location set (chosen-exit 
                       access-from 
                       (self location get)))
               (timestamp-map set 
                      (lambda ((d door))
                    (if (d == (chosen-exit))
                        (current-t)
                        (current-tmap (d)))))
               (timestamp set (+ (timestamp get) 1)))))));
2111000113210001100132322111010003211...hear
define myrobo (robo new);
2110132100100010322100011001321101001...hear
myrobo set-room (stairs);
210010001032100001111322100000110332233hear
define which-room
  (lambda ((rr robo))
    (find-max-idx 
     (lambda ((r room)) (if (r == (rr get-room)) 1 0))
     (vector (hall) (kitchen) (stairs) (lawn) (bedroom))));
2110132100100011322110103222100100100...hear
define sequencer
  (lambda (n current lst)
    (if (< (current) (n))
    (begin
      (myrobo update)
      (sequencer
       (n)
       (+ (current) 1)
       (append
        (which-room (myrobo))
        (lst))))
    (lst)));
2110132100100101322110103221000001321...hear
# here is a list of the first 30 rooms the robot character visits
# 0=hall, 1=kitchen, 2=stairs, 3=lawn, 4=bedroom
list= (sequencer 30 0 (vector)) (vector 4 2 0 3 0 1 0 2 4 2 0 3 0 1 0 2 4 2 0 3 0 1 0 2 4 2 0 3 0 1);
2100101032210010010132111103203221000...hear
# Now should start to introduce a language to talk about what is
# going on in the simulated world, and start to move away from
# detailed mechanism

42. end of part 2, start of part 3

# The following parts of the message are the beginnings
# of embedding an alternate visual primer
intro part3;
203210010011032233hear

43. simulating unless gates

# for embedded image-and-logic-based primer
# practice with pure logic gate
# X unless Y = (X if Y=0, otherwise 0)
define unless |
  ? x | ? y |
  and (x) (not (y));
2110132100100111302321100321001103023...hear
# if second input is true, output is blocked (false)
# if second input is false, output copies first input
= (false) (unless (false) (false));
2103221101113322100100111322110111332...hear
= (true) (unless (true) (false));
2103221101103322100100111322110110332...hear
= (false) (unless (false) (true));
2103221101113322100100111322110111332...hear
= (false) (unless (true) (true));
2103221101113322100100111322110110332...hear
# To do: add a simple simulator for non-grid-based
# logic -- much simpler to understand than
# grid-based
# On to a grid-based logic simulation
# first, need unbounded, mutable matrices
define make-matrix |
  ? default |
  (make-cell (hash-default (default)));
2110132100101000302321100321001001130...hear
define matrix-set |
  ? m |
  ? x |
  ? addr |
  set! (m) | hash-add (get! (m)) (addr) (x);
2110132100101001302321100321001010103...hear
define matrix-get |
  ? m |
  ? addr |
  hash-ref (get! (m)) (addr);
2110132100101100302321100321001010103...hear
define test-matrix
  (make-matrix 0);
2110132100101101322100101000320332233hear
= 0 | matrix-get (test-matrix) | vector 1 2 3;
2103203023210010110032210010110133023...hear
matrix-set (test-matrix) 10 | vector 1 2 3;
2100101001322100101101332101030232100...hear
= 10 | matrix-get (test-matrix) | vector 1 2 3;
2103210103023210010110032210010110133...hear
# go through a circuit of unless gates and analyze data flow
define unless-phase-1 |
  ? circuit |
  assign state (make-matrix (false))
  (begin
    (map 
     (? gate |
    assign x1 (list-ref (gate) 0) |
    assign y1 (list-ref (gate) 1) |
    assign x2 (list-ref (gate) 2) |
    assign y2 (list-ref (gate) 3) |
    assign v (list-ref (gate) 4) |
    (if (= (x1) (x2))
        (begin
          (matrix-set (state) (v) | vector (x2) (y2) vert-value)
          (matrix-set (state) (true) | vector (x2) (y2) vert-have)
          (matrix-set (state) (true) | vector (x1) (y1) vert-want)
          (gate))
        (begin
          (matrix-set (state) (v) | vector (x2) (y2) horiz-value)
          (matrix-set (state) (true) | vector (x2) (y2) horiz-have)
          (matrix-set (state) (true) | vector (x1) (y1) horiz-want)
          (gate))))
     (circuit))
    (state));
2110132100101110302321100321001011113...hear
# move forward one simulation step
define unless-phase-2 |
  ? circuit |
  ? state
  (map 
   (? gate |
      assign x1 (list-ref (gate) 0) |
      assign y1 (list-ref (gate) 1) |
      assign x2 (list-ref (gate) 2) |
      assign y2 (list-ref (gate) 3) |
      assign v (list-ref (gate) 4) |
      assign nv (if (= (x1) (x2))
            (if (matrix-get (state) | vector (x1) (y1) vert-have)
            (and (matrix-get (state) |
                     vector (x1) (y1) vert-value)
                 (not (and (matrix-get (state) |
                           vector (x1) (y1) horiz-value)
                       (not (matrix-get (state) |
                            vector (x1) (y1) horiz-want)))))
            (if (matrix-get (state) | vector (x1) (y1) horiz-have)
                (matrix-get (state) | vector (x1) (y1) horiz-value)
                (true)))
            (if (matrix-get (state) | vector (x1) (y1) horiz-have)
            (and (matrix-get (state) | vector (x1) (y1) horiz-value)
                 (not (and (matrix-get (state) |
                           vector (x1) (y1) vert-value)
                       (not (matrix-get (state) |
                            vector (x1) (y1) vert-want)))))
            (if (matrix-get (state) | vector (x1) (y1) vert-have)
                (matrix-get (state) | vector (x1) (y1) vert-value)
                (true)))) |
                vector (x1) (y1) (x2) (y2) (nv))
   (circuit));
2110132100111100302321100321001011113...hear
# wrap up both phases of simulation
define simulate-unless |
  ? circuit |
  assign state (unless-phase-1 (circuit)) |
  unless-phase-2 (circuit) (state);
2110132100111110302321100321001011113...hear
# A circuit is a list of gates
# Each gate is a list (x1 y1 x2 y2 v)
# where the coordinates (x1,y1) and (x2,y2) represent
# start and end points of a wire on a plane, carrying a 
# logic value v.
# Wires copy values from their start point.
#   |  
#   | (A)
#   V        
# -->-->
# (B)(C)
#
# Wire C here copies from wire B.
# If wire A is on, it blocks (sets to 0) C.
assign circuit1
    (vector
     (vector 2 2 4 2 (true))
     (vector 4 2 6 2 (true))
     (vector 6 2 8 2 (true))
     (vector 6 4 6 2 (true))) |
     assign circuit2
     (vector
      (vector 2 2 4 2 (true))
      (vector 4 2 6 2 (true))
      (vector 6 2 8 2 (false))
      (vector 6 4 6 2 (true))) |
      equal (simulate-unless (circuit1)) (circuit2);
2111032100111111322100003221000032103...hear
# okay, now let us make a simple image class
# we are going to encode each row as a single binary number,
# rather than a vector, so that images will be pretty
# obvious in the raw, uninterpreted message
define bit-get |
  lambda (n offset) |
  assign div2 (div (n) 2) 
  (if (= 0 | offset)
      (not | = (n) | * 2 | div2)
      (bit-get (div2) | - (offset) 1));
2110132101000001302321101032210000013...hear
= 0 | bit-get (::.) 0;
210320302321010000013211032032233hear
= 1 | bit-get (::.) 1;
210321302321010000013211032132233hear
= 1 | bit-get (::.) 2;
2103213023210100000132110321032233hear
= 0 | bit-get (::.) 3;
2103203023210100000132110321132233hear
= 0 | bit-get (::.) 4;
21032030232101000001321103210032233hear
= 0 | bit-get 8 0;
2103203023210100000132100032032233hear
= 0 | bit-get 8 1;
2103203023210100000132100032132233hear
= 0 | bit-get 8 2;
21032030232101000001321000321032233hear
= 1 | bit-get 8 3;
21032130232101000001321000321132233hear
define make-image |
  lambda (h w lst) |
  vector (h) (w) (lst);
2110132101000100302321101032210001111...hear
define image-get |
  lambda (image row col) |
  assign h (list-ref (image) 0) |
  assign w (list-ref (image) 1) |
  assign lst (list-ref (image) 2) |
  assign bits (list-ref (lst) (row)) |
  bit-get (bits) (- (- (w) (col)) 1);
2110132101000110302321101032210100011...hear
define image-height |
  ? image |
  list-ref (image) 0;
2110132101001011302321100321010001113...hear
define image-width |
  ? image |
  list-ref (image) 1;
2110132101001100302321100321010001113...hear
define test-image |
  make-image 3 5 |
  vector (:....) (:...:) (:....);
2110132101001101302321010001003211321...hear
= 3 (image-height | test-image);
210321132210100101130232101001101332233hear
= 5 (image-width | test-image);
2103210132210100110030232101001101332233hear
= (true) (image-get (test-image) 0 0);
2103221101103322101000110322101001101...hear
= (false) (image-get (test-image) 0 1);
2103221101113322101000110322101001101...hear
= (false) (image-get (test-image) 0 4);
2103221101113322101000110322101001101...hear
= (true) (image-get (test-image) 1 0);
2103221101103322101000110322101001101...hear
= (true) (image-get (test-image) 2 0);
2103221101103322101000110322101001101...hear
= (true) (image-get (test-image) 1 4);
2103221101103322101000110322101001101...hear
# need a way to join two lists
define merge-list |
  ? lst1 |
  ? lst2 |
  (if (> (list-length | lst1) 0)
      (prepend (head | lst1) (merge-list (tail | lst1) (lst2)))
      (lst2));
2110132101001110302321100321101101030...hear
define merge-lists |
  ? lst |
  (if (> (list-length | lst) 2)
      (merge-list (head | lst) (merge-lists | tail | lst))
      (if (= (list-length | lst) 2)
      (merge-list (head | lst) | (head | tail | lst))
      (if (= (list-length | lst) 1)
          (head | lst)
          (vector))));
2110132101001111302321100321000101302...hear
equal (vector 1 2 3 4) (merge-list (vector 1 2) (vector 3 4));
2100032210000321321032113210033221010...hear
equal (vector 1 2 3 4) (merge-lists (vector (vector 1 2) (vector 3) (vector 4)));
2100032210000321321032113210033221010...hear
# helper for pairing
define prefix |
  ? x | 
  ? lst |
  map (? y (vector (x) (y))) (lst);
2110132101010000302321100321001103023...hear
equal (vector (vector 1 10) (vector 1 11))
       (prefix 1 (vector 10 11));
2100032210000322100003213210103322100...hear
# need a way to take product of domains
define pairing |
  ? lst1 | 
  ? lst2
  (if (> (list-length | lst1) 0)
      (merge-list (prefix (head | lst1) (lst2))
          (pairing (tail | lst1) (lst2)))
      (vector));
2110132101010001302321100321101101030...hear
equal (vector (vector 1 10) (vector 1 11) (vector 2 10) (vector 2 11))
       (pairing (vector 1 2) (vector 10 11));
2100032210000322100003213210103322100...hear
# need a way to make counting sets
define count |
  ? lo | ? hi
  (if (<= (lo) (hi))
      (prepend (lo) (count (+ (lo) 1) (hi)))
      (vector));
2110132110101113023211003210101001030...hear
equal (vector 0 1 2 3 4) (count 0 4);
2100032210000320321321032113210033221...hear
# given an image of a circuit, extract a model.
# wire elements are centered on multiples of 8
# individual element...
define distill-element |
  ? image | ? xlogic | ? ylogic | ? xmid | ? ymid 
  (if (image-get (image) (ymid) (xmid))
      (assign vert (image-get (image) (+ (ymid) 4) (xmid)) |
          assign dx (if (vert) 0 1) |
          assign dy (if (vert) 1 0) |
          assign pos (image-get (image) 
                    (+ (ymid) | + (* 4 | dy) (* 2 | dx))
                    (+ (xmid) | - (* 4 | dx) (* 2 | dy))) |
          assign sgn (if (pos) 1 (- 0 1)) |
          assign dx (* (sgn) (dx)) |
          assign dy (* (sgn) (dy)) |
          assign active (image-get (image) (+ (ymid) (dx)) (- (xmid) (dy))) |
          (vector 
           (vector (- (xlogic) (dx)) 
               (- (ylogic) (dy))
               (+ (xlogic) (dx))
               (+ (ylogic) (dy))
               (active))))
      (vector));
2110132101010100302321100321010001113...hear
# full circuit...
define distill-circuit |
  ? image |
  assign h (div (image-height | image) 8) |
  assign w (div (image-width | image) 8) 
  (merge-lists
   (map (? v |
       assign xlogic (list-ref (v) 0) |
       assign ylogic (list-ref (v) 1) |
       assign xmid (* 8 | xlogic) |
       assign ymid (* 8 | ylogic) |
       distill-element (image) (xlogic) (ylogic) (xmid) (ymid))
    (pairing (count 1 (- (w) 1))
         (count 1 (- (h) 1)))));
2110132101011111302321100321010001113...hear

44. testing alternate primer based on gates: cos_not circuit

# This section contains one or more representations of a circuit
# constructed using UNLESS gates.
define cos_not_gate | vector 
  (vector 0 6 2 6 (true))
  (vector 2 6 4 6 (true))
  (vector 4 6 6 6 (true))
  (vector 6 6 8 6 (true))
  (vector 8 4 8 6 (true))
  (vector 8 6 8 8 (false))
  (vector 8 8 10 8 (false))
  (vector 10 8 12 8 (false))
  (vector 12 8 12 6 (false))
  (vector 12 6 14 6 (false))
  (vector 14 6 16 6 (false))
  (vector 16 6 18 6 (false))
  (vector 18 6 20 6 (false));
2110132101100000302321000032210000320...hear
define cos_not_image | make-image 109 169 | vector 
  (:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:..............................................................:::......................................................................................................:)
  (:..............................................................:::......................................................................................................:)
  (:..............................................................:::......................................................................................................:)
  (:..............................................................:::......................................................................................................:)
  (:..............................................................:::......................................................................................................:)
  (:..............................................................:::......................................................................................................:)
  (:..............................................................:::......................................................................................................:)
  (:..............................................................:::......................................................................................................:)
  (:..............................................................:::......................................................................................................:)
  (:.............................................................:::::.....................................................................................................:)
  (:..............................................................:::......................................................................................................:)
  (:...........:...............:...............:...............:...:...........................................:...............:...............:...............:...........:)
  (:..:::::::::::.....:::::::::::.....:::::::::::.....:::::::::::..............................................::..............::..............::..............::..........:)
  (:..::::::::::::....::::::::::::....::::::::::::....::::::::::::....................................::::::::::::....::::::::::::....::::::::::::....::::::::::::.........:)
  (:..:::::::::::.....:::::::::::.....:::::::::::.....:::::::::::..............................................::..............::..............::..............::..........:)
  (:...........:...............:...............:...............:...................................:...........:...............:...............:...............:...........:)
  (:...............................................................:..............................:::......................................................................:)
  (:...............................................................:.............................:::::.....................................................................:)
  (:...............................................................:...............................:.......................................................................:)
  (:...............................................................:...............................:.......................................................................:)
  (:...............................................................:...............................:.......................................................................:)
  (:...............................................................:...............................:.......................................................................:)
  (:...............................................................:...............................:.......................................................................:)
  (:...............................................................:...............................:.......................................................................:)
  (:...............................................................:...............................:.......................................................................:)
  (:.............................................................:::::.............................:.......................................................................:)
  (:..............................................................:::..............................:.......................................................................:)
  (:...............................................................:...........:...............:...........................................................................:)
  (:...........................................................................::..............::..........................................................................:)
  (:..................................................................::::::::::::....::::::::::::.........................................................................:)
  (:...........................................................................::..............::..........................................................................:)
  (:...........................................................................:...............:...........................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::);
2110132101100001302321010001003211011...hear
equal (cos_not_gate) (distill-circuit (cos_not_image));
2100032210110000033221010111113221011...hear

Run simulator

45. testing alternate primer based on gates: cos_and circuit

# This section contains one or more representations of a circuit
# constructed using UNLESS gates.
define cos_and_gate | vector 
  (vector 0 2 2 2 (true))
  (vector 0 8 2 8 (true))
  (vector 2 2 4 2 (true))
  (vector 2 4 4 4 (true))
  (vector 2 6 4 6 (true))
  (vector 2 8 4 8 (true))
  (vector 4 2 4 4 (true))
  (vector 4 8 4 6 (true))
  (vector 4 4 6 4 (false))
  (vector 4 6 6 6 (false))
  (vector 6 4 8 4 (false))
  (vector 6 6 8 6 (false))
  (vector 8 4 10 4 (false))
  (vector 8 6 10 6 (false))
  (vector 10 2 10 4 (true))
  (vector 10 4 10 6 (true))
  (vector 10 6 10 8 (true))
  (vector 10 8 12 8 (true))
  (vector 12 8 14 8 (true))
  (vector 14 8 16 8 (true))
  (vector 16 8 18 8 (true));
2110132101100010302321000032210000320...hear
define cos_and_image | make-image 88 153 | vector 
  (:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::)
  (:.......................................................................................................................................................:)
  (:.......................................................................................................................................................:)
  (:.......................................................................................................................................................:)
  (:.......................................................................................................................................................:)
  (:.......................................................................................................................................................:)
  (:.......................................................................................................................................................:)
  (:.......................................................................................................................................................:)
  (:.......................................................................................................................................................:)
  (:.......................................................................................................................................................:)
  (:.......................................................................................................................................................:)
  (:.......................................................................................................................................................:)
  (:.......................................................................................................................................................:)
  (:.......................................................................................................................................................:)
  (:...........:...............:...........................................................................................................................:)
  (:..:::::::::::.....:::::::::::..........................................................................................................................:)
  (:..::::::::::::....::::::::::::.........................................................................................................................:)
  (:..:::::::::::.....:::::::::::..........................................................................................................................:)
  (:...........:...............:...........................................................................................................................:)
  (:..............................:::.............................................:::......................................................................:)
  (:..............................:::.............................................:::......................................................................:)
  (:..............................:::.............................................:::......................................................................:)
  (:..............................:::.............................................:::......................................................................:)
  (:..............................:::.............................................:::......................................................................:)
  (:..............................:::.............................................:::......................................................................:)
  (:..............................:::.............................................:::......................................................................:)
  (:..............................:::.............................................:::......................................................................:)
  (:..............................:::.............................................:::......................................................................:)
  (:.............................:::::...........................................:::::.....................................................................:)
  (:..............................:::.............................................:::......................................................................:)
  (:...........................:...:...........:...............:...............:...:.......................................................................:)
  (:..................:::::::::::..............::..............::..............::..........................................................................:)
  (:..................::::::::::::....::::::::::::....::::::::::::....::::::::::::.........................................................................:)
  (:..................:::::::::::..............::..............::..............::..........................................................................:)
  (:...........................:...............:...............:...............:...........................................................................:)
  (:..............................................................................:::......................................................................:)
  (:..............................................................................:::......................................................................:)
  (:..............................................................................:::......................................................................:)
  (:..............................................................................:::......................................................................:)
  (:..............................................................................:::......................................................................:)
  (:..............................................................................:::......................................................................:)
  (:..............................................................................:::......................................................................:)
  (:..............................................................................:::......................................................................:)
  (:..............................................................................:::......................................................................:)
  (:.............................................................................:::::.....................................................................:)
  (:..............................................................................:::......................................................................:)
  (:...........................:...............:...............:...............:...:.......................................................................:)
  (:..................:::::::::::..............::..............::..............::..........................................................................:)
  (:..................::::::::::::....::::::::::::....::::::::::::....::::::::::::.........................................................................:)
  (:..................:::::::::::..............::..............::..............::..........................................................................:)
  (:...........................:...:...........:...............:...............:...........................................................................:)
  (:..............................:::.............................................:::......................................................................:)
  (:.............................:::::............................................:::......................................................................:)
  (:..............................:::.............................................:::......................................................................:)
  (:..............................:::.............................................:::......................................................................:)
  (:..............................:::.............................................:::......................................................................:)
  (:..............................:::.............................................:::......................................................................:)
  (:..............................:::.............................................:::......................................................................:)
  (:..............................:::.............................................:::......................................................................:)
  (:..............................:::.............................................:::......................................................................:)
  (:..............................:::............................................:::::.....................................................................:)
  (:..............................:::.............................................:::......................................................................:)
  (:...........:...............:...................................................:...........:...............:...............:...............:...........:)
  (:..:::::::::::.....:::::::::::.....................................................:::::::::::.....:::::::::::.....:::::::::::.....:::::::::::..........:)
  (:..::::::::::::....::::::::::::....................................................::::::::::::....::::::::::::....::::::::::::....::::::::::::.........:)
  (:..:::::::::::.....:::::::::::.....................................................:::::::::::.....:::::::::::.....:::::::::::.....:::::::::::..........:)
  (:...........:...............:...............................................................:...............:...............:...............:...........:)
  (:.......................................................................................................................................................:)
  (:.......................................................................................................................................................:)
  (:.......................................................................................................................................................:)
  (:.......................................................................................................................................................:)
  (:.......................................................................................................................................................:)
  (:.......................................................................................................................................................:)
  (:.......................................................................................................................................................:)
  (:.......................................................................................................................................................:)
  (:.......................................................................................................................................................:)
  (:.......................................................................................................................................................:)
  (:.......................................................................................................................................................:)
  (:.......................................................................................................................................................:)
  (:.......................................................................................................................................................:)
  (:.......................................................................................................................................................:)
  (:.......................................................................................................................................................:)
  (:.......................................................................................................................................................:)
  (:.......................................................................................................................................................:)
  (:.......................................................................................................................................................:)
  (:.......................................................................................................................................................:)
  (:.......................................................................................................................................................:)
  (:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::);
2110132101100011302321010001003210110...hear
equal (cos_and_gate) (distill-circuit (cos_and_image));
2100032210110001033221010111113221011...hear

Run simulator

46. testing alternate primer based on gates: cos_or circuit

# This section contains one or more representations of a circuit
# constructed using UNLESS gates.
define cos_or_gate | vector 
  (vector 2 4 4 4 (true))
  (vector 2 6 4 6 (true))
  (vector 4 4 6 4 (true))
  (vector 4 6 6 6 (true))
  (vector 6 4 8 4 (true))
  (vector 6 6 8 6 (true))
  (vector 8 4 10 4 (true))
  (vector 8 6 10 6 (true))
  (vector 8 8 10 8 (true))
  (vector 10 2 10 4 (true))
  (vector 10 4 10 6 (false))
  (vector 10 6 10 8 (false))
  (vector 10 8 12 8 (true))
  (vector 12 8 14 8 (true))
  (vector 14 8 16 8 (true))
  (vector 16 8 18 8 (true));
2110132101100100302321000032210000321...hear
define cos_or_image | make-image 93 169 | vector 
  (:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:..............................................................................:::......................................................................................:)
  (:..............................................................................:::......................................................................................:)
  (:..............................................................................:::......................................................................................:)
  (:..............................................................................:::......................................................................................:)
  (:..............................................................................:::......................................................................................:)
  (:..............................................................................:::......................................................................................:)
  (:..............................................................................:::......................................................................................:)
  (:..............................................................................:::......................................................................................:)
  (:..............................................................................:::......................................................................................:)
  (:.............................................................................:::::.....................................................................................:)
  (:..............................................................................:::......................................................................................:)
  (:...........................:...............:...............:...............:...:.......................................................................................:)
  (:..................:::::::::::.....:::::::::::.....:::::::::::.....:::::::::::..........................................................................................:)
  (:..................::::::::::::....::::::::::::....::::::::::::....::::::::::::.........................................................................................:)
  (:..................:::::::::::.....:::::::::::.....:::::::::::.....:::::::::::..........................................................................................:)
  (:...........................:...............:...............:...............:...........................................................................................:)
  (:...............................................................................:.......................................................................................:)
  (:...............................................................................:.......................................................................................:)
  (:...............................................................................:.......................................................................................:)
  (:...............................................................................:.......................................................................................:)
  (:...............................................................................:.......................................................................................:)
  (:...............................................................................:.......................................................................................:)
  (:...............................................................................:.......................................................................................:)
  (:...............................................................................:.......................................................................................:)
  (:...............................................................................:.......................................................................................:)
  (:.............................................................................:::::.....................................................................................:)
  (:..............................................................................:::......................................................................................:)
  (:...........................:...............:...............:...............:...:.......................................................................................:)
  (:..................:::::::::::.....:::::::::::.....:::::::::::.....:::::::::::..........................................................................................:)
  (:..................::::::::::::....::::::::::::....::::::::::::....::::::::::::.........................................................................................:)
  (:..................:::::::::::.....:::::::::::.....:::::::::::.....:::::::::::..........................................................................................:)
  (:...........................:...............:...............:...............:...........................................................................................:)
  (:...............................................................................:.......................................................................................:)
  (:...............................................................................:.......................................................................................:)
  (:...............................................................................:.......................................................................................:)
  (:...............................................................................:.......................................................................................:)
  (:...............................................................................:.......................................................................................:)
  (:...............................................................................:.......................................................................................:)
  (:...............................................................................:.......................................................................................:)
  (:...............................................................................:.......................................................................................:)
  (:...............................................................................:.......................................................................................:)
  (:.............................................................................:::::.....................................................................................:)
  (:..............................................................................:::......................................................................................:)
  (:...........................................................................:...:...........:...............:...............:...............:...........................:)
  (:..................................................................:::::::::::.....:::::::::::.....:::::::::::.....:::::::::::.....:::::::::::..........................:)
  (:..................................................................::::::::::::....::::::::::::....::::::::::::....::::::::::::....::::::::::::.........................:)
  (:..................................................................:::::::::::.....:::::::::::.....:::::::::::.....:::::::::::.....:::::::::::..........................:)
  (:...........................................................................:...............:...............:...............:...............:...........................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::);
2110132101100101302321010001003210111...hear
equal (cos_or_gate) (distill-circuit (cos_or_image));
2100032210110010033221010111113221011...hear

Run simulator

47. testing alternate primer based on gates: cos_nor circuit

# This section contains one or more representations of a circuit
# constructed using UNLESS gates.
define cos_nor_gate | vector 
  (vector 0 6 2 6 (true))
  (vector 0 8 2 8 (true))
  (vector 2 6 4 6 (true))
  (vector 2 8 4 8 (true))
  (vector 4 6 6 6 (true))
  (vector 4 8 6 8 (true))
  (vector 6 6 8 6 (true))
  (vector 6 8 8 8 (true))
  (vector 8 4 8 6 (true))
  (vector 8 6 8 8 (false))
  (vector 8 8 8 10 (false))
  (vector 8 10 10 10 (false))
  (vector 10 10 12 10 (false))
  (vector 12 10 14 10 (false))
  (vector 14 10 16 10 (false))
  (vector 16 10 18 10 (false))
  (vector 18 10 20 10 (false));
2110132101100110302321000032210000320...hear
define cos_nor_image | make-image 125 169 | vector 
  (:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:..............................................................:::......................................................................................................:)
  (:..............................................................:::......................................................................................................:)
  (:..............................................................:::......................................................................................................:)
  (:..............................................................:::......................................................................................................:)
  (:..............................................................:::......................................................................................................:)
  (:..............................................................:::......................................................................................................:)
  (:..............................................................:::......................................................................................................:)
  (:..............................................................:::......................................................................................................:)
  (:..............................................................:::......................................................................................................:)
  (:.............................................................:::::.....................................................................................................:)
  (:..............................................................:::......................................................................................................:)
  (:...........:...............:...............:...............:...:.......................................................................................................:)
  (:..:::::::::::.....:::::::::::.....:::::::::::.....:::::::::::..........................................................................................................:)
  (:..::::::::::::....::::::::::::....::::::::::::....::::::::::::.........................................................................................................:)
  (:..:::::::::::.....:::::::::::.....:::::::::::.....:::::::::::..........................................................................................................:)
  (:...........:...............:...............:...............:...........................................................................................................:)
  (:...............................................................:.......................................................................................................:)
  (:...............................................................:.......................................................................................................:)
  (:...............................................................:.......................................................................................................:)
  (:...............................................................:.......................................................................................................:)
  (:...............................................................:.......................................................................................................:)
  (:...............................................................:.......................................................................................................:)
  (:...............................................................:.......................................................................................................:)
  (:...............................................................:.......................................................................................................:)
  (:...............................................................:.......................................................................................................:)
  (:.............................................................:::::.....................................................................................................:)
  (:..............................................................:::......................................................................................................:)
  (:...........:...............:...............:...............:...:.......................................................................................................:)
  (:..:::::::::::.....:::::::::::.....:::::::::::.....:::::::::::..........................................................................................................:)
  (:..::::::::::::....::::::::::::....::::::::::::....::::::::::::.........................................................................................................:)
  (:..:::::::::::.....:::::::::::.....:::::::::::.....:::::::::::..........................................................................................................:)
  (:...........:...............:...............:...............:...........................................................................................................:)
  (:...............................................................:.......................................................................................................:)
  (:...............................................................:.......................................................................................................:)
  (:...............................................................:.......................................................................................................:)
  (:...............................................................:.......................................................................................................:)
  (:...............................................................:.......................................................................................................:)
  (:...............................................................:.......................................................................................................:)
  (:...............................................................:.......................................................................................................:)
  (:...............................................................:.......................................................................................................:)
  (:...............................................................:.......................................................................................................:)
  (:.............................................................:::::.....................................................................................................:)
  (:..............................................................:::......................................................................................................:)
  (:...............................................................:...........:...............:...............:...............:...............:...............:...........:)
  (:...........................................................................::..............::..............::..............::..............::..............::..........:)
  (:..................................................................::::::::::::....::::::::::::....::::::::::::....::::::::::::....::::::::::::....::::::::::::.........:)
  (:...........................................................................::..............::..............::..............::..............::..............::..........:)
  (:...........................................................................:...............:...............:...............:...............:...............:...........:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::);
2110132101100111302321010001003211111...hear
equal (cos_nor_gate) (distill-circuit (cos_nor_image));
2100032210110011033221010111113221011...hear

Run simulator

48. testing alternate primer based on gates: cos_osc circuit

# This section contains one or more representations of a circuit
# constructed using UNLESS gates.
define cos_osc_gate | vector 
  (vector 4 8 6 8 (true))
  (vector 6 8 8 8 (true))
  (vector 8 6 8 8 (true))
  (vector 10 6 8 6 (true))
  (vector 8 8 10 8 (false))
  (vector 12 6 10 6 (false))
  (vector 10 8 12 8 (false))
  (vector 12 8 12 6 (false))
  (vector 12 8 14 8 (false))
  (vector 14 8 16 8 (false));
2110132101101000302321000032210000321...hear
define cos_osc_image | make-image 120 169 | vector 
  (:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:...................................................................:...............:...................................................................................:)
  (:..................................................................:::::::::::.....::...................................................................................:)
  (:.................................................................::::::::::::....::::::::::::..........................................................................:)
  (:..................................................................:::::::::::.....::...................................................................................:)
  (:...................................................................:...............:...........:.......................................................................:)
  (:..............................................................:::.............................:::......................................................................:)
  (:..............................................................:::............................:::::.....................................................................:)
  (:..............................................................:::..............................:.......................................................................:)
  (:..............................................................:::..............................:.......................................................................:)
  (:..............................................................:::..............................:.......................................................................:)
  (:..............................................................:::..............................:.......................................................................:)
  (:..............................................................:::..............................:.......................................................................:)
  (:..............................................................:::..............................:.......................................................................:)
  (:..............................................................:::..............................:.......................................................................:)
  (:.............................................................:::::.............................:.......................................................................:)
  (:..............................................................:::..............................:.......................................................................:)
  (:...........................................:...............:...:...........:...............:...............:...............:...........................................:)
  (:..................................:::::::::::.....:::::::::::..............::..............::..............::..............::..........................................:)
  (:..................................::::::::::::....::::::::::::....::::::::::::....::::::::::::....::::::::::::....::::::::::::.........................................:)
  (:..................................:::::::::::.....:::::::::::..............::..............::..............::..............::..........................................:)
  (:...........................................:...............:...............:...............:...............:...............:...........................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::);
2110132101101001302321010001003211110...hear
equal (cos_osc_gate) (distill-circuit (cos_osc_image));
2100032210110100033221010111113221011...hear

Run simulator

49. testing alternate primer based on gates: cos_sr circuit

# This section contains one or more representations of a circuit
# constructed using UNLESS gates.
define cos_sr_gate | vector 
  (vector 0 2 2 2 (true))
  (vector 0 8 2 8 (true))
  (vector 2 2 4 2 (true))
  (vector 2 8 4 8 (true))
  (vector 4 2 6 2 (true))
  (vector 4 6 6 6 (true))
  (vector 4 8 6 8 (true))
  (vector 6 8 6 6 (true))
  (vector 6 2 8 2 (true))
  (vector 6 6 8 6 (false))
  (vector 8 4 8 6 (false))
  (vector 8 2 10 2 (true))
  (vector 10 4 8 4 (false))
  (vector 8 6 10 6 (false))
  (vector 10 6 10 8 (false))
  (vector 10 2 12 2 (true))
  (vector 12 4 10 4 (false))
  (vector 10 6 12 6 (false))
  (vector 10 8 12 8 (false))
  (vector 12 6 12 4 (false))
  (vector 12 2 14 2 (true))
  (vector 14 4 12 4 (false))
  (vector 12 8 14 8 (false))
  (vector 14 2 14 4 (true))
  (vector 16 4 14 4 (true))
  (vector 14 8 16 8 (false))
  (vector 16 8 18 8 (false))
  (vector 18 8 20 8 (false));
2110132101101010302321000032210000320...hear
define cos_sr_image | make-image 88 169 | vector 
  (:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:...........:...............:...............:...............:...............:...............:...............:...........................................................:)
  (:..:::::::::::.....:::::::::::.....:::::::::::.....:::::::::::.....:::::::::::.....:::::::::::.....:::::::::::..........................................................:)
  (:..::::::::::::....::::::::::::....::::::::::::....::::::::::::....::::::::::::....::::::::::::....::::::::::::.........................................................:)
  (:..:::::::::::.....:::::::::::.....:::::::::::.....:::::::::::.....:::::::::::.....:::::::::::.....:::::::::::..........................................................:)
  (:...........:...............:...............:...............:...............:...............:...............:...........................................................:)
  (:..............................................................................................................:::......................................................:)
  (:..............................................................................................................:::......................................................:)
  (:..............................................................................................................:::......................................................:)
  (:..............................................................................................................:::......................................................:)
  (:..............................................................................................................:::......................................................:)
  (:..............................................................................................................:::......................................................:)
  (:..............................................................................................................:::......................................................:)
  (:..............................................................................................................:::......................................................:)
  (:..............................................................................................................:::......................................................:)
  (:.............................................................................................................:::::.....................................................:)
  (:..............................................................................................................:::......................................................:)
  (:...................................................................:...............:...............:...........:...:...................................................:)
  (:..................................................................::..............::..............::..............:::::::::::..........................................:)
  (:.................................................................::::::::::::....::::::::::::....::::::::::::....::::::::::::..........................................:)
  (:..................................................................::..............::..............::..............:::::::::::..........................................:)
  (:...................................................................:...............:...........:...:...............:...................................................:)
  (:...............................................................:..............................:::......................................................................:)
  (:...............................................................:.............................:::::.....................................................................:)
  (:...............................................................:...............................:.......................................................................:)
  (:...............................................................:...............................:.......................................................................:)
  (:...............................................................:...............................:.......................................................................:)
  (:...............................................................:...............................:.......................................................................:)
  (:...............................................................:...............................:.......................................................................:)
  (:...............................................................:...............................:.......................................................................:)
  (:...............................................................:...............................:.......................................................................:)
  (:.............................................................:::::.............................:.......................................................................:)
  (:..............................................................:::..............................:.......................................................................:)
  (:...........................................:...............:...:...........:...............:...........................................................................:)
  (:..................................:::::::::::..............::..............::..............::..........................................................................:)
  (:..................................::::::::::::....::::::::::::....::::::::::::....::::::::::::.........................................................................:)
  (:..................................:::::::::::..............::..............::..............::..........................................................................:)
  (:...........................................:...:...........:...............:...............:...........................................................................:)
  (:..............................................:::..............................:.......................................................................................:)
  (:.............................................:::::.............................:.......................................................................................:)
  (:..............................................:::..............................:.......................................................................................:)
  (:..............................................:::..............................:.......................................................................................:)
  (:..............................................:::..............................:.......................................................................................:)
  (:..............................................:::..............................:.......................................................................................:)
  (:..............................................:::..............................:.......................................................................................:)
  (:..............................................:::..............................:.......................................................................................:)
  (:..............................................:::..............................:.......................................................................................:)
  (:..............................................:::............................:::::.....................................................................................:)
  (:..............................................:::.............................:::......................................................................................:)
  (:...........:...............:...............:...................................:...........:...............:...............:...............:...............:...........:)
  (:..:::::::::::.....:::::::::::.....:::::::::::..............................................::..............::..............::..............::..............::..........:)
  (:..::::::::::::....::::::::::::....::::::::::::....................................::::::::::::....::::::::::::....::::::::::::....::::::::::::....::::::::::::.........:)
  (:..:::::::::::.....:::::::::::.....:::::::::::..............................................::..............::..............::..............::..............::..........:)
  (:...........:...............:...............:...............................................:...............:...............:...............:...............:...........:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::);
2110132101101011302321010001003210110...hear
equal (cos_sr_gate) (distill-circuit (cos_sr_image));
2100032210110101033221010111113221011...hear

Run simulator

50. testing alternate primer based on gates: cos_d circuit

# This section contains one or more representations of a circuit
# constructed using UNLESS gates.
define cos_d_gate | vector 
  (vector 0 2 2 2 (true))
  (vector 0 6 2 6 (true))
  (vector 2 2 4 2 (true))
  (vector 2 6 4 6 (true))
  (vector 4 2 6 2 (true))
  (vector 4 6 6 6 (true))
  (vector 6 2 8 2 (true))
  (vector 6 6 8 6 (true))
  (vector 8 2 10 2 (true))
  (vector 8 6 10 6 (true))
  (vector 10 6 10 4 (true))
  (vector 10 10 10 8 (true))
  (vector 10 2 12 2 (true))
  (vector 10 4 12 4 (true))
  (vector 10 6 12 6 (true))
  (vector 10 8 12 8 (true))
  (vector 12 10 10 10 (true))
  (vector 12 0 12 2 (true))
  (vector 12 2 12 4 (false))
  (vector 12 6 12 8 (true))
  (vector 12 10 12 12 (true))
  (vector 12 4 14 4 (true))
  (vector 12 8 14 8 (false))
  (vector 14 10 12 10 (true))
  (vector 12 12 14 12 (true))
  (vector 14 0 14 2 (true))
  (vector 14 2 14 4 (true))
  (vector 14 4 14 6 (false))
  (vector 14 6 14 8 (false))
  (vector 14 8 14 10 (false))
  (vector 16 10 14 10 (true))
  (vector 14 12 16 12 (true))
  (vector 16 12 18 12 (true))
  (vector 18 12 20 12 (true));
2110132101101100302321000032210000320...hear
define cos_d_image | make-image 109 169 | vector 
  (:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:..............................................................................................:::.............:::......................................................:)
  (:..............................................................................................:::.............:::......................................................:)
  (:..............................................................................................:::.............:::......................................................:)
  (:..............................................................................................:::.............:::......................................................:)
  (:..............................................................................................:::.............:::......................................................:)
  (:..............................................................................................:::.............:::......................................................:)
  (:..............................................................................................:::.............:::......................................................:)
  (:..............................................................................................:::.............:::......................................................:)
  (:..............................................................................................:::.............:::......................................................:)
  (:.............................................................................................:::::...........:::::.....................................................:)
  (:..............................................................................................:::.............:::......................................................:)
  (:...........:...............:...............:...............:...............:...............:...:...............:.......................................................:)
  (:..:::::::::::.....:::::::::::.....:::::::::::.....:::::::::::.....:::::::::::.....:::::::::::..........................................................................:)
  (:..::::::::::::....::::::::::::....::::::::::::....::::::::::::....::::::::::::....::::::::::::.........................................................................:)
  (:..:::::::::::.....:::::::::::.....:::::::::::.....:::::::::::.....:::::::::::.....:::::::::::..........................................................................:)
  (:...........:...............:...............:...............:...............:...............:...........................................................................:)
  (:...............................................................................................:..............:::......................................................:)
  (:...............................................................................................:..............:::......................................................:)
  (:...............................................................................................:..............:::......................................................:)
  (:...............................................................................................:..............:::......................................................:)
  (:...............................................................................................:..............:::......................................................:)
  (:...............................................................................................:..............:::......................................................:)
  (:...............................................................................................:..............:::......................................................:)
  (:...............................................................................................:..............:::......................................................:)
  (:...............................................................................................:..............:::......................................................:)
  (:.............................................................................................:::::...........:::::.....................................................:)
  (:..............................................................................................:::.............:::......................................................:)
  (:...........................................................................................:...:...........:...:.......................................................:)
  (:..................................................................................:::::::::::.....:::::::::::..........................................................:)
  (:..................................................................................::::::::::::....::::::::::::.........................................................:)
  (:..................................................................................:::::::::::.....:::::::::::..........................................................:)
  (:...............................................................................:...........:...............:...........................................................:)
  (:..............................................................................:::..............................:.......................................................:)
  (:.............................................................................:::::.............................:.......................................................:)
  (:..............................................................................:::..............................:.......................................................:)
  (:..............................................................................:::..............................:.......................................................:)
  (:..............................................................................:::..............................:.......................................................:)
  (:..............................................................................:::..............................:.......................................................:)
  (:..............................................................................:::..............................:.......................................................:)
  (:..............................................................................:::..............................:.......................................................:)
  (:..............................................................................:::..............................:.......................................................:)
  (:..............................................................................:::............................:::::.....................................................:)
  (:..............................................................................:::.............................:::......................................................:)
  (:...........:...............:...............:...............:...............:...............:...................:.......................................................:)
  (:..:::::::::::.....:::::::::::.....:::::::::::.....:::::::::::.....:::::::::::.....:::::::::::..........................................................................:)
  (:..::::::::::::....::::::::::::....::::::::::::....::::::::::::....::::::::::::....::::::::::::.........................................................................:)
  (:..:::::::::::.....:::::::::::.....:::::::::::.....:::::::::::.....:::::::::::.....:::::::::::..........................................................................:)
  (:...........:...............:...............:...............:...............:...............:...........................................................................:)
  (:..............................................................................................:::..............:.......................................................:)
  (:..............................................................................................:::..............:.......................................................:)
  (:..............................................................................................:::..............:.......................................................:)
  (:..............................................................................................:::..............:.......................................................:)
  (:..............................................................................................:::..............:.......................................................:)
  (:..............................................................................................:::..............:.......................................................:)
  (:..............................................................................................:::..............:.......................................................:)
  (:..............................................................................................:::..............:.......................................................:)
  (:..............................................................................................:::..............:.......................................................:)
  (:.............................................................................................:::::...........:::::.....................................................:)
  (:..............................................................................................:::.............:::......................................................:)
  (:...........................................................................................:...:...........:...:.......................................................:)
  (:..................................................................................:::::::::::..............::..........................................................:)
  (:..................................................................................::::::::::::....::::::::::::.........................................................:)
  (:..................................................................................:::::::::::..............::..........................................................:)
  (:...............................................................................:...........:...............:...........................................................:)
  (:..............................................................................:::..............................:.......................................................:)
  (:.............................................................................:::::.............................:.......................................................:)
  (:..............................................................................:::..............................:.......................................................:)
  (:..............................................................................:::..............................:.......................................................:)
  (:..............................................................................:::..............................:.......................................................:)
  (:..............................................................................:::..............................:.......................................................:)
  (:..............................................................................:::..............................:.......................................................:)
  (:..............................................................................:::..............................:.......................................................:)
  (:..............................................................................:::..............................:.......................................................:)
  (:..............................................................................:::............................:::::.....................................................:)
  (:..............................................................................:::.............................:::......................................................:)
  (:...................................................................................:...............:...........:...:...................................................:)
  (:..................................................................................:::::::::::.....:::::::::::.....:::::::::::..........................................:)
  (:.................................................................................::::::::::::....::::::::::::....::::::::::::..........................................:)
  (:..................................................................................:::::::::::.....:::::::::::.....:::::::::::..........................................:)
  (:...................................................................................:...............:...............:...................................................:)
  (:..............................................................................................:::......................................................................:)
  (:..............................................................................................:::......................................................................:)
  (:..............................................................................................:::......................................................................:)
  (:..............................................................................................:::......................................................................:)
  (:..............................................................................................:::......................................................................:)
  (:..............................................................................................:::......................................................................:)
  (:..............................................................................................:::......................................................................:)
  (:..............................................................................................:::......................................................................:)
  (:..............................................................................................:::......................................................................:)
  (:.............................................................................................:::::.....................................................................:)
  (:..............................................................................................:::......................................................................:)
  (:...............................................................................................:...........:...............:...............:...............:...........:)
  (:..................................................................................................:::::::::::.....:::::::::::.....:::::::::::.....:::::::::::..........:)
  (:..................................................................................................::::::::::::....::::::::::::....::::::::::::....::::::::::::.........:)
  (:..................................................................................................:::::::::::.....:::::::::::.....:::::::::::.....:::::::::::..........:)
  (:...........................................................................................................:...............:...............:...............:...........:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:.......................................................................................................................................................................:)
  (:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::);
2110132101101101302321010001003211011...hear
equal (cos_d_gate) (distill-circuit (cos_d_image));
2100032210110110033221010111113221011...hear

Run simulator

51. probing networks of unless gates

define set-input |
  ? circuit |
  ? index |
  ? value |
  assign wire (list-ref (circuit) (index)) 
  (map (? w (if (equal (w) (wire))
        (vector (list-ref (w) 0)
            (list-ref (w) 1)
            (list-ref (w) 2)            
            (list-ref (w) 3)
            (value))
        (w)))
       (circuit));
2110132101101110302321100321001011113...hear
define read-output |
  ? circuit |
  ? index |
  assign len (list-length | circuit) |
  assign wire (list-ref (circuit) | - (- (len) 1) (index)) |
  list-ref (wire) 4;
2110132101110001302321100321001011113...hear
define sim |
  ? circuit | ? steps | ? setter
  (if (> (steps) 0)
      (sim (simulate-unless (setter | circuit)) (- (steps) 1) (setter))
      (circuit));
2110132101110011302321100321001011113...hear
define smart-sim |
  ? circuit |
  ? setter |
  sim (circuit) (list-length | circuit) (setter);
2110132101110110302321100321001011113...hear
# test cos_not gate
define cos_not_harness |
  ? x |
  assign c (cos_not_gate) | 
  assign c (smart-sim (c) (? c (set-input (c) 0 (x)))) |
  read-output (c) 0;
2110132101110111302321100321001103023...hear
= (false) | cos_not_harness | true;
2103221101113302321011101113023211011...hear
= (true) | cos_not_harness | false;
2103221101103302321011101113023211011...hear
# test cos_and gate
define cos_and_harness |
  ? x | ? y |
  assign c (cos_and_gate) | 
  assign c (smart-sim (c) (? c (set-input (set-input (c) 0 (x)) 1 (y)))) |
  read-output (c) 0;
2110132101111000302321100321001103023...hear
= (false) | cos_and_harness (false) (false);
2103221101113302321011110003221101113...hear
= (false) | cos_and_harness (false) (true);
2103221101113302321011110003221101113...hear
= (false) | cos_and_harness (true) (false);
2103221101113302321011110003221101103...hear
= (true) | cos_and_harness (true) (true);
2103221101103302321011110003221101103...hear
# this code is more awkward than it needs to be -
# should make circuits mutable

52. end of part 3, start of part 4

# The following parts of the message start
# to introduce some self-reference into the message
intro part4;
203210111100132233hear

53. a mechanism for referring to parts of the message

# Many choices for how to do this.
# Could do it without special machinery by using the
# standard A-B trick for giving e.g. a Turing machine
# access to its own description.
# Instead, will simply introduce a "primer" function
# that gives access to every statement made so far 
# (question: should future statements be included? 
# tentatively assume YES: will simplify
# discussion of creating modified copies of the
# complete message).
# For now, assume primer is a list of statements,
# with each statement being a list in the same
# form as "translate" functions expect.
# This means that there is, for now, no
# distinction between unary or binary,
# and the "/" structure is expanded.
intro primer;
203210001132233hear
# this line is referred to later - change/move carefully
equal (list-ref (primer) 0) (vector intro is:int);
2100032210010003221000113320332210000...hear
equal (list-ref (primer) 1) (vector is:int (vector unary 0));
2100032210010003221000113321332210000...hear
equal (list-ref (primer) 2) (vector is:int (vector unary 1 0));
2100032210010003221000113321033221000...hear
assign idx (list-find (primer) (vector intro primer) (? x 0)) 
    (equal (list-ref (primer) (+ (idx) 1))
           (vector equal 
               (vector list-ref (vector primer) 0)
               (vector vector intro is:int)));
2111032101000132210100103221000113322...hear
# Now, we could return to the MUD, simulate an agent A
# transferring a copy of the primer to another agent B,
# and then show B making a modified copy of that primer
# and passing it back to A.
# We could also show agents experimenting with the
# primer in various ways.
# Message is pretty solid up to this point.
# For testing purposes, useful to save state here to disk,
# command: DISK-SAVE base

54. some preparatory work for integrating with Java code

class Object ()
       (method add-one (lambda (x) (+ (x) 1)))
       (method unknown (lambda (x) (x)))
       (method <init>-V (self))
       (method <init> (self))
       (method classname Object)
       (method equals-Object-Z (this ==))
       (method equals (self equals-Object-Z))
       (method act (true))
       (method isobj (true));
2111000113210111101032322100111113210...hear
define java-object | Object;
21101321100000103023210111101032233hear
define act | ? x | true;
2110132110000000302321100321001103023...hear
#(class java-string ()
#       (field super (java-object new))
#       (method classname String)
#       (method unknown (lambda (x) (super (x)))));
# inconsistency of various kinds of equality throughout message
# needs to be cleaned up
class Integer ()
       (field super (java-object new))
       (field value (cell new 0))
       (method <init> (self))
       (method <init>-V (self))
       (method <init>-I-V (lambda (v) 
                (begin 
                  (value set (v))
                  (self))))
       (method intValue-V (value get))
       (method intValue (self intValue-V))
       (method equals-Object-Z (lambda (o) (if (= (o classname) Integer)
                           (= (value get) (o value get))
                           (false))))
       (method equals (self equals-Object-Z))
       (method get (value get))
       (method set (lambda(x)
             (value set
                (if (number? | x)
                (x)
                (x intValue)))))
       (method classname Integer)
       (method unknown (lambda (x) (super (x))));
2111000113211000001132322111010003211...hear
# string is basically the same as an integer
class String ()
       (field super (java-object new))
       (field value (cell new 0))
       (method <init> (self))
       (method <init>-V (self))
       (method <init>-String-V (lambda (v) 
                 (begin 
                   (value set (v value get))
                   (self))))
       (method int-init (lambda (x) 
              (begin 
                (value set (x))
                (self))))
       (method intValue-V (value get))
       (method intValue (self intValue-V))
       (method get (value get))
       (method set (lambda(x)
             (value set
                (if (number? | x)
                (x)
                (x intValue)))))
       (method equals-Object-Z (lambda (o) (if (= (o classname) String)
                           (= (value get) (o value get))
                           (false))))
       (method equals (self equals-Object-Z))
       (method classname String)
       (method unknown (lambda (x) (super (x))));
2111000113211000100132322111010003211...hear
# will need to install class hierarchy, just hardcode a few things for now
define java
  (? x | ? y 
     (cond ((= (y) String) (String))
       ((= (y) Object) (java-object))
       ((= (y) Integer) (Integer))
       (java-object)));
2110132110001100322110032100110302321...hear
(java util String) new isobj;
2211000110032110001101321100010013321...hear
= ((java util String) new add-one 15) 16;
2103222110001100321100011013211000100...hear
class java-numeric ()
       (field super (java-object new))
       (method unknown (lambda (x) (super (x))))
       (field java-content (cell new 0))
       (method get (java-content get))
       (method init (lambda (v)
              (begin
            (self set (v))
            (self))))
       (method set (lambda (v) (java-content set (v))));
2111000113211000111032322111010003211...hear
define byte (java-numeric);
2110132110010001322110001110332233hear
define char (java-numeric);
2110132110010010322110001110332233hear
define double (java-numeric);
2110132110010011322110001110332233hear
define float (java-numeric);
2110132110010100322110001110332233hear
define int (java-numeric);
211013210111001322110001110332233hear
define long (java-numeric);
2110132110010101322110001110332233hear
define short (java-numeric);
2110132110010110322110001110332233hear
define boolean (java-numeric);
2110132110010111322110001110332233hear
define void (java-numeric);
2110132110011000322110001110332233hear
define java-test1 (int new);
2110132110011001322101110013211010011...hear
java-test1 set 15;
2110011001321111011032111132233hear
= 15 (java-test1 get);
2103211113221100110013211110101332233hear
define java-test2 (int new init 17);
2110132110011010322101110013211010011...hear
= 17 (java-test2 get);
21032100013221100110103211110101332233hear
define state-machine-test1
  (? x
     (cond ((= (x) 1) 20)
       ((= (x) 2) 40)
       ((= (x) 3) 60)
       0));
2110132110011011322110032100110322110...hear
= (state-machine-test1 3) 60;
210322110011011321133211110032233hear
# really ought to go back and be clear about eager/laziness issues
define state-machine-test2
  (? x
     (cond ((= (x) 1) (java-test1 set 20))
       ((= (x) 2) (java-test1 set 40))
       ((= (x) 3) (java-test1 set 60))
       0));
2110132110011100322110032100110322110...hear
state-machine-test2 2;
2110011100321032233hear
= (java-test1 get) 40;
210322110011001321111010133210100032233hear
define compare-object-reference
  (lambda (o1 o2)
    (if (number? | o1)
    (number? | o2)
    (= (o1 unique-id) (o2 unique-id))));
2110132110011101322110103221100111103...hear
define jvm-maker
  (lambda (vars stack pc ret)
    (? op
     (begin
       (pc set (+ (pc get) 1)) |
     cond ((= (op) new)
        (lambda (type)
          (stack-push (stack) ((type) new))))
       ((= (op) dup)
        (stack-push (stack) (stack-peek (stack))))
       ((= (op) checkcast)
        (lambda (t)
          1))
       ((or (= (op) astore) (= (op) istore))
        (lambda (index)
          (vars set (hash-add (vars get) (index) (stack-pop (stack))))))
       ((or (= (op) aload) (= (op) iload))
        (lambda (index)
          (stack-push (stack) (hash-ref (vars get) (index)))))
       ((or (= (op) iconst) (= (op) ldc))
        (lambda (val)
          (stack-push (stack) (val))))
       ((= (op) aconst_null)
        (stack-push (stack) 0))
       ((= (op) instanceof)
        (lambda (t)
          (stack-push 
           (stack)
           (not | number? | (stack-pop | stack) (t new classname)))))
       ((= (op) getfield)
        (lambda (key ignore)
          (stack-push (stack) ((stack-pop (stack)) (key) get))))
       ((= (op) putfield)
        (lambda (key ignore)
          (let ((val (stack-pop (stack))))
        ((stack-pop (stack)) (key) set (val)))))
       ((= (op) imul)
        (let ((v2 (stack-pop (stack))))
          (let ((v1 (stack-pop (stack))))
        (stack-push (stack)
                (* (v1) (v2))))))
       ((= (op) iadd)
        (let ((v2 (stack-pop (stack))))
          (let ((v1 (stack-pop (stack))))
        (stack-push (stack)
                (+ (v1) (v2))))))
       ((= (op) isub)
        (let ((v2 (stack-pop (stack))))
          (let ((v1 (stack-pop (stack))))
        (stack-push (stack)
                (- (v1) (v2))))))
       ((= (op) goto)
        (lambda (x)
          (pc set (x))))
       ((= (op) iflt)
        (lambda (x)
          (if (< (stack-pop (stack)) 0)
          (pc set (x))
          0)))
       ((= (op) ifle)
        (lambda (x)
          (if (< (stack-pop (stack)) 1)
          (pc set (x))
          0)))
       ((= (op) ifgt)
        (lambda (x)
          (if (> (stack-pop (stack)) 0)
          (pc set (x))
          0)))
       ((= (op) ifge)
        (lambda (x)
          (if (>= (stack-pop (stack)) 0)
          (pc set (x))
          0)))
       ((= (op) ifne)
        (lambda (x)
          (if (not (= (stack-pop (stack)) 0))
          (pc set (x))
          0)))
       ((= (op) ifeq)
        (lambda (x)
          (if (= (stack-pop (stack)) 0)
          (pc set (x))
          0)))
       ((= (op) if_icmpne)
        (let ((v2 (stack-pop (stack))))
          (let ((v1 (stack-pop (stack))))
        (lambda (x)
          (if (not (= (v1) (v2)))
              (pc set (x))
              0)))))
       ((= (op) if_icmpeq)
        (let ((v2 (stack-pop (stack))))
          (let ((v1 (stack-pop (stack))))
        (lambda (x)
          (if (= (v1) (v2))
              (pc set (x))
              0)))))
       ((= (op) if_acmpne)
        (let ((v2 (stack-pop (stack))))
          (let ((v1 (stack-pop (stack))))
        (lambda (x)
          (if (not (compare-object-reference (v1) (v2)))
              (pc set (x))
              0)))))
       ((= (op) if_acmpeq)
        (let ((v2 (stack-pop (stack))))
          (let ((v1 (stack-pop (stack))))
        (lambda (x)
          (if (compare-object-reference (v1) (v2))
              (pc set (x))
              0)))))
       ((= (op) if_icmpge)
        (let ((v2 (stack-pop (stack))))
          (let ((v1 (stack-pop (stack))))
        (lambda (x)
          (if (>= (v1) (v2))
              (pc set (x))
              0)))))
       ((= (op) if_icmpgt)
        (let ((v2 (stack-pop (stack))))
          (let ((v1 (stack-pop (stack))))
        (lambda (x)
          (if (> (v1) (v2))
              (pc set (x))
              0)))))
       ((= (op) if_icmple)
        (let ((v2 (stack-pop (stack))))
          (let ((v1 (stack-pop (stack))))
        (lambda (x)
          (if (<= (v1) (v2))
              (pc set (x))
              0)))))
       ((= (op) if_icmplt)
        (let ((v2 (stack-pop (stack))))
          (let ((v1 (stack-pop (stack))))
        (lambda (x)
          (if (< (v1) (v2))
              (pc set (x))
              0)))))
       ((= (op) ifnull)
        (lambda (x)
          (if (number? | stack-pop (stack))
          (pc set (x))
          0)))
       ((= (op) ifnonnull)
        (lambda (x)
          (if (not (number? | stack-pop (stack)))
          (pc set (x))
          0)))
       ((= (op) return)
        (begin (ret set (hash-ref (vars get) 0))
           (pc set -1)))
       ((= (op) ireturn)
        (begin (ret set (stack-pop (stack)))
           (pc set -1)))
       ((= (op) areturn)
        (begin (ret set (stack-pop (stack)))
           (pc set -1)))
       ((= (op) goto)
        (lambda (target)
          (pc set (target))))
       ((= (op) invokevirtual)
        (lambda (target m n)
          (let ((result (stack-call (stack) (target) (m))))
        (if (= (n) 1)
            (stack-push (stack) (result))
            0))))
       ((= (op) invokeinterface)
        (lambda (target m n ignore)
          (let ((result (stack-call (stack) (target) (m))))
        (if (= (n) 1)
            (stack-push (stack) (result))
            0))))
       ((= (op) invokespecial)
        (lambda (target m n)
          (let ((result (stack-call-special (stack) 
                        (hash-ref (vars get) 0)
                        (target) 
                        (m))))
        (if (= (n) 1)
            (stack-push (stack) (result))
            0))))
       0)));
2110132110100000322110103221101000013...hear
define stack-call
  (lambda (stack target ct)
    (if (= (ct) 0)
    ((stack-pop (stack)) (target))
    (let ((arg (stack-pop (stack))))
      ((stack-call (stack) (target) (- (ct) 1)) (arg)))));
2110132111010001322110103221101000103...hear
define stack-call-special
  (lambda (stack self target ct)
    (if (= (ct) 0)
    (let ((act (stack-pop | stack)))
      (if (act == (self))
          (act super (target))
          (act (target))))
    (let ((arg (stack-pop (stack))))
      ((stack-call-special (stack) (self) (target) (- (ct) 1)) (arg)))));
2110132111010100322110103221101000103...hear
define stack-push
  (lambda (stack x)
    (stack set (prepend (x) (stack get))));
2110132110100110322110103221101000103...hear
define stack-pop
  (lambda (stack)
    (let ((v (head (stack get))))
      (begin
    (stack set (tail (stack get)))
    (v))));
2110132110101100322110103221101000103...hear
define stack-peek
  (lambda (stack)
    (head (stack get)));
2110132110101000322110103221101000103...hear
define stack-test1 (cell new (vector 5 3 1));
2110132111010111322111100103211010011...hear
= (stack-pop (stack-test1)) 5;
210322110101100322111010111333210132233hear
= (stack-peek (stack-test1)) 3;
21032211010100032211101011133321132233hear
= (stack-pop (stack-test1)) 3;
21032211010110032211101011133321132233hear
stack-push (stack-test1) 7;
211010011032211101011133211132233hear
= (stack-pop (stack-test1)) 7;
210322110101100322111010111333211132233hear
define vars-test1 (cell new (hash-null));
2110132111011000322111100103211010011...hear
define pc-test1 (cell new 0);
2110132111011001322111100103211010011...hear
define ret-test1 (cell new 0);
2110132111011010322111100103211010011...hear
define test-jvm (jvm-maker (vars-test1) (stack-test1) (pc-test1) (ret-test1));
2110132111011011322110100000322111011...hear
stack-push (stack-test1) 4;
211010011032211101011133210032233hear
test-jvm dup;
21110110113211010011132233hear
= (stack-pop (stack-test1)) 4;
210322110101100322111010111333210032233hear
= (stack-pop (stack-test1)) 4;
210322110101100322111010111333210032233hear
stack-push (stack-test1) 66;
2110100110322111010111332100001032233hear
stack-push (stack-test1) 77;
2110100110322111010111332100110132233hear
test-jvm astore 3;
211101101132110101010321132233hear
= (stack-pop (stack-test1)) 66;
2103221101011003221110101113332100001...hear
test-jvm aload 3;
211101101132110101101321132233hear
= (stack-pop (stack-test1)) 77;
2103221101011003221110101113332100110...hear
class test-class ()
       (field x ((int) new))
       (field y ((int) new));
2111000113211101110032322111010003210...hear
define test-this (test-class new);
2110132111011101322111011100321101001...hear
test-this x set 5;
21110111013210011032111101103210132233hear
= (test-this x get) 5;
2103221110111013210011032111101013321...hear
stack-push (stack-test1) (test-this);
2110100110322111010111332211101110133...hear
= ((stack-pop (stack-test1)) x get) 5;
2103222110101100322111010111333210011...hear
stack-push (stack-test1) (test-this);
2110100110322111010111332211101110133...hear
test-jvm astore 0;
21110110113211010101032032233hear
test-jvm aload 0;
21110110113211010110132032233hear
test-jvm getfield x (int);
2111011011321101100113210011032210111...hear
= (stack-pop (stack-test1)) 5;
210322110101100322111010111333210132233hear
test-jvm aload 0;
21110110113211010110132032233hear
test-jvm iconst 15;
21110110113211010111132111132233hear
test-jvm putfield y (int);
2111011011321101101013211000132210111...hear
= (test-this y get) 15;
2103221110111013211000132111101013321...hear
stack-push (stack-test1) 7;
211010011032211101011133211132233hear
stack-push (stack-test1) 10;
2110100110322111010111332101032233hear
test-jvm imul;
21110110113211011011032233hear
test-jvm ireturn;
21110110113211100110032233hear
= (ret-test1 get) 70;
2103221110110103211110101332100011032233hear
define state-machine-helper |
  ? at |
  lambda (vars stack machine) |
  let ((pc (cell new (at)))
       (ret (cell new (true)))) |
  let ((jvm (jvm-maker (vars) (stack) (pc) (ret))))
  (begin
    (machine (jvm) (pc get))
    (if (= (pc get) -1)
    (ret get)
    (state-machine-helper (pc get) (vars) (stack) (machine))));
2110132111011110302321100321110111113...hear
define state-machine
  (state-machine-helper 0);
2110132111100001322111011110320332233hear
stack-push (stack-test1) 10;
2110100110322111010111332101032233hear
stack-push (stack-test1) 33;
211010011032211101011133210000132233hear
= (state-machine (vars-test1) (stack-test1) | ? jvm | ? x
          (cond ((= (x) 0) (jvm istore 4))
            ((= (x) 1) (jvm iload 4))
            (jvm ireturn)))
   33;
2103221111000013221110110003322111010...hear
stack-push (stack-test1) 10;
2110100110322111010111332101032233hear
define bytecode-test-mul
  (lambda (arg0 arg1) |
      let ((vars | cell new | make-hash | vector (pair 0 0) (pair 1 (arg0)) (pair 2 (arg1)))
           (stack | cell new | vector)) |
           state-machine (vars) (stack) | ? jvm | ? x | cond
           ((= (x) 0) (jvm iload 1))
           ((= (x) 1) (jvm iload 2))
           ((= (x) 2) (jvm imul))
           ((= (x) 3) (jvm ireturn))
           (jvm return));
2110132111100010322110103221111000113...hear
= (bytecode-test-mul 5 9) 45;
2103221111000103210132100133210110132233hear

55. class translation 'COS_JavaTest'

# Produced by Fritzifier, based on JasminVisitor
# Using BCEL library to read Java bytecode
# Here is the original code:
# public class COS_JavaTest {
#     private int q = 0;
#     public int add(int x, int y) {
#     return x+y;
#     }
#     public int sub(int x, int y) {
#     return x-y;
#     }
#     public int mult(int x, int y) {
#     return x*y;
#     }
#     public int addmult(int x, int y, int z) {
#     return add(x,mult(y,z));
#     }
#     public void set(int x) {
#     q = x;
#     }
#     public int get() {
#     return q;
#     }
#     public int fact(int x) {
#     return (x>0)?(x*fact(sub(x,1))):1;
#     }
# }
# 
class COS_JavaTest ()
   (field super-ref (make-cell 0))
   (method new (set! (super-ref) ((java lang Object) | this)))
   (method super (? x | (get! | super-ref) | x))
   (method unknown (? x | self super | x))
   (field q ((int) new))
   (method <init>-V
     (lambda () |
      let ((vars | cell new | make-hash | vector
                    (pair 0 (self)))
           (stack | cell new | vector)) |
      state-machine (vars) (stack) | ? jvm | ? x | cond
         ((= (x) 0) (jvm aload 0))
         ((= (x) 1) (jvm invokespecial <init>-V 0 0))
         ((= (x) 2) (jvm aload 0))
         ((= (x) 3) (jvm iconst 0))
         ((= (x) 4) (jvm putfield q (int)))
         ((= (x) 5) (jvm return))
         (jvm return))
   )

   (method <init> (self <init>-V))

   (method add-I-I-I
     (lambda (arg0 arg1) |
      let ((vars | cell new | make-hash | vector
                    (pair 0 (self)) (pair 1 (arg0)) (pair 2 (arg1)))
           (stack | cell new | vector)) |
      state-machine (vars) (stack) | ? jvm | ? x | cond
         ((= (x) 0) (jvm iload 1))
         ((= (x) 1) (jvm iload 2))
         ((= (x) 2) (jvm iadd))
         ((= (x) 3) (jvm ireturn))
         (jvm return))
   )

   (method add (self add-I-I-I))

   (method sub-I-I-I
     (lambda (arg0 arg1) |
      let ((vars | cell new | make-hash | vector
                    (pair 0 (self)) (pair 1 (arg0)) (pair 2 (arg1)))
           (stack | cell new | vector)) |
      state-machine (vars) (stack) | ? jvm | ? x | cond
         ((= (x) 0) (jvm iload 1))
         ((= (x) 1) (jvm iload 2))
         ((= (x) 2) (jvm isub))
         ((= (x) 3) (jvm ireturn))
         (jvm return))
   )

   (method sub (self sub-I-I-I))

   (method mult-I-I-I
     (lambda (arg0 arg1) |
      let ((vars | cell new | make-hash | vector
                    (pair 0 (self)) (pair 1 (arg0)) (pair 2 (arg1)))
           (stack | cell new | vector)) |
      state-machine (vars) (stack) | ? jvm | ? x | cond
         ((= (x) 0) (jvm iload 1))
         ((= (x) 1) (jvm iload 2))
         ((= (x) 2) (jvm imul))
         ((= (x) 3) (jvm ireturn))
         (jvm return))
   )

   (method mult (self mult-I-I-I))

   (method addmult-I-I-I-I
     (lambda (arg0 arg1 arg2) |
      let ((vars | cell new | make-hash | vector
                    (pair 0 (self)) (pair 1 (arg0)) (pair 2 (arg1)) (pair 3 (arg2)))
           (stack | cell new | vector)) |
      state-machine (vars) (stack) | ? jvm | ? x | cond
         ((= (x) 0) (jvm aload 0))
         ((= (x) 1) (jvm iload 1))
         ((= (x) 2) (jvm aload 0))
         ((= (x) 3) (jvm iload 2))
         ((= (x) 4) (jvm iload 3))
         ((= (x) 5) (jvm invokevirtual mult-I-I-I 2 1))
         ((= (x) 6) (jvm invokevirtual add-I-I-I 2 1))
         ((= (x) 7) (jvm ireturn))
         (jvm return))
   )

   (method addmult (self addmult-I-I-I-I))

   (method set-I-V
     (lambda (arg0) |
      let ((vars | cell new | make-hash | vector
                    (pair 0 (self)) (pair 1 (arg0)))
           (stack | cell new | vector)) |
      state-machine (vars) (stack) | ? jvm | ? x | cond
         ((= (x) 0) (jvm aload 0))
         ((= (x) 1) (jvm iload 1))
         ((= (x) 2) (jvm putfield q (int)))
         ((= (x) 3) (jvm return))
         (jvm return))
   )

   (method set (self set-I-V))

   (method get-I
     (lambda () |
      let ((vars | cell new | make-hash | vector
                    (pair 0 (self)))
           (stack | cell new | vector)) |
      state-machine (vars) (stack) | ? jvm | ? x | cond
         ((= (x) 0) (jvm aload 0))
         ((= (x) 1) (jvm getfield q (int)))
         ((= (x) 2) (jvm ireturn))
         (jvm return))
   )

   (method get (self get-I))

   (method fact-I-I
     (lambda (arg0) |
      let ((vars | cell new | make-hash | vector
                    (pair 0 (self)) (pair 1 (arg0)))
           (stack | cell new | vector)) |
      state-machine (vars) (stack) | ? jvm | ? x | cond
         ((= (x) 0) (jvm iload 1))
         ((= (x) 1) (jvm ifle 11))
         ((= (x) 2) (jvm iload 1))
         ((= (x) 3) (jvm aload 0))
         ((= (x) 4) (jvm aload 0))
         ((= (x) 5) (jvm iload 1))
         ((= (x) 6) (jvm iconst 1))
         ((= (x) 7) (jvm invokevirtual sub-I-I-I 2 1))
         ((= (x) 8) (jvm invokevirtual fact-I-I 1 1))
         ((= (x) 9) (jvm imul))
         ((= (x) 10) (jvm goto 12))
         ((= (x) 11) (jvm iconst 1))
         ((= (x) 12) (jvm ireturn))
         (jvm return))
   )

   (method fact (self fact-I-I))

 ;
2111000113211110010132322111010003211...hear

56. check that automatic conversion is workable

define test1 (COS_JavaTest new);
2110132111110011322111100101321101001...hear
# Note that the names of methods include type information.
# This could easily be removed, but is retained so that overloading
# is possible in the Java code.
# I is integer, V is void.  The last type in the name is the return type.
= (test1 mult-I-I-I 15 10) 150;
2103221111100113211110101132111132101...hear
# The type information can be safely omitted if there is no ambiguity
= (test1 mult 15 10) 150;
2103221111100113211100113211113210103...hear
= (test1 addmult-I-I-I-I 4 15 10) 154;
2103221111100113211110110032100321111...hear
begin
  (test1 set-I-V 87)
  (= (test1 get-I) 87);
2100011003221111100113211110111132101...hear
= (test1 fact-I-I 0) 1;
21032211111001132111110001320332132233hear
= (test1 fact-I-I 1) 1;
21032211111001132111110001321332132233hear
= (test1 fact-I-I 5) 120;
2103221111100113211111000132101332111...hear
# Yay! testing says this works.
# So structure for bytecode interpretation is in place.
# Very few opcodes actually implemented yet though.

57. another simple little text-adventure space

# let us try to make a slightly more interesting world
define make-table
  (lambda (lst)
    (crunch (? x | ? h | 
           assign name (car | x) |
           assign obj (cdr | x) |
           hash-add (h) (name) (obj))
        (append (hash-null) (lst))));
2110132111110100322110103221000101332...hear
# note, the quoted strings below are just represented as a big number,
# nothing special
define geo-map 
  (make-table
   (map
    (? name (cons (name) (room new (name))))
    (vector "boston" "dublin" "paris" "genoa")));
2110132111110101322111110100322110000...hear
define my-links
  (map 
   (? entry (assign src (car | entry) |
            assign dest (cdr | entry) |
            door new (geo-map | src) (geo-map | dest)))
   (vector
    (cons "boston" "dublin")
    (cons "dublin" "paris")
    (cons "boston" "paris")
    (cons "paris" "genoa")));
2110132111110110322110000032211003211...hear
define myrobo (robo new);
2110132100100010322100011001321101001...hear
myrobo set-room (geo-map "dublin");
2100100010321000011113221111101013210...hear
(equal "dublin" | myrobo get-room name);
2100032100111011001001110010110100100...hear
myrobo update;
21001000103210001010032233hear
(equal "paris" | myrobo get-room name);
2100032110000101110010011010010111001...hear
myrobo update;
21001000103210001010032233hear
(equal "genoa" | myrobo get-room name);
2100032100110101001000110010000101000...hear
myrobo update;
21001000103210001010032233hear
(equal "paris" | myrobo get-room name);
2100032110000101110010011010010111001...hear
myrobo update;
21001000103210001010032233hear
(equal "boston" | myrobo get-room name);
2100032100011001000101110010000100100...hear
myrobo update;
21001000103210001010032233hear
(equal "dublin" | myrobo get-room name);
2100032100111011001001110010110100100...hear
myrobo update;
21001000103210001010032233hear
(equal "paris" | myrobo get-room name);
2100032110000101110010011010010111001...hear
# all characters should update together
class world (the-places the-links)
       (field things (container new))
       (field names (cell new (hash-null)))
       (field places (cell new 0))
       (field links (cell new 0))
       (method new 
           (begin
         (places set
            (make-table
             (map
              (? name (cons (name) (room new (name))))
              (the-places))))
         (links set
            (map 
             (? entry (assign src (car | entry) |
                      assign dest (cdr | entry) |
                      door new 
                      (places get | src) 
                      (places get | dest)))
             (the-links)))))
       (method add (lambda (place name val) 
             (begin
               (val set-room (places get | place))
               (val set-name | name)
               (names set (hash-add (names get)
                        (name)
                        (val)))
               (things add (val)))))
       (method find (lambda (n) (names get (n) get-room name)))
       (method reachable (lambda (place)
               (let ((exits
                  (select-match (lambda (x) 
                          (instanceof door (x)))
                        (places get (place) inventory))))
                 (map (? door (door access-from 
                        (places get | place)
                        name))
                  (exits)))))
       (method update (begin 
            (map (? x (x update)) 
                 (things inventory))
            (true)));
2111000113211111100032211111100132111...hear
define geo-world
  (world new 
     (vector "boston" "dublin" "paris" "genoa")
     (vector
      (cons "boston" "dublin")
      (cons "dublin" "paris")
      (cons "boston" "paris")
      (cons "paris" "genoa")));
2110132100000000132211111100032110100...hear
geo-world add "dublin" "robo1" (robo new);
2100000000132111000032100111011001001...hear
geo-world add "genoa" "robo2" (robo new);
2100000000132111000032100110101001000...hear
(equal "dublin" | geo-world find "robo1");
2100032100111011001001110010110100100...hear
(equal "genoa" | geo-world find "robo2");
2100032100110101001000110010000101000...hear
geo-world update;
210000000013210001010032233hear
(equal "paris" | geo-world find "robo1");
2100032110000101110010011010010111001...hear
(equal "paris" | geo-world find "robo2");
2100032110000101110010011010010111001...hear
(equal (vector "paris" "dublin") | geo-world reachable "boston");
2100032210000321100001011100100110100...hear
(equal (vector "paris") | geo-world reachable "genoa");
2100032210000321100001011100100110100...hear

58. native implementation of a Java list, hash classes

define flex-equals
  (lambda (x y) 
    (if (number? | x)
    (if (number? | y)
        (= (x) (y))
        (false))
    (if (number? | y)
        (false)
        (x equals (y)))));
2110132100000001032211010322100110321...hear
define remove-object
  (lambda (x) 
    (remove-match (lambda (y) 
            (flex-equals (x) (y)))));
2110132100000001132211010322100110332...hear
define contains-object
  (lambda (x lst)
    (if (> (list-length | lst) 0)
    (if (flex-equals (head | lst) (x))
        (true)
        (contains-object (x) (tail | lst)))
    (false)));
2110132100000010032211010322100110321...hear
class COS_JList ()
       (field super ((java lang Object) new))
       (method unknown (lambda (x) (super (x))))
       (field contents (cell new (vector)))
       (method <init>-V (self))
       (method <init> (self <init>-V))
       (method add-Object-V (lambda (x)
             (contents set (prepend (x) (contents get)))))
       (method add (self add-Object-V))
       (method remove-Object-Z (lambda (x)
            (contents set 
                  (remove-object (x) (contents get)))))
       (method remove (self remove-Object-Z))
       (method contains-Object-Z (lambda (x)
                   (contains-object (x) (contents get))))
       (method contains (self contains-Object-Z))
       (method get-I-Object (lambda (x)
             (list-ref (contents get) (x))))
       (method get (self get-I-Object))
       (method iterator-Iterator (COS_JListIterator new (self)))
       (method iterator (self iterator-Iterator))
       (method size-V-I (list-length (contents get)))
       (method size (self size-V-I));
2111000113210000001013232211101000321...hear
define test1 (COS_JList new);
2110132111110011322100000010132110100...hear
begin (test1 add-Object-V (test1))
       (= 1 | test1 size-V-I);
2100011003221111100113210000001103221...hear
test1 == (test1 get-I-Object 0);
2111110011321110110032211111001132100...hear
class COS_JHashMap ()
       (field super ((java lang Object) new))
       (method unknown (lambda (x) (super (x))))
       (field contents (cell new (? x 0)))
       (method <init>-V (self))
       (method <init> (self <init>-V))
       (method put-Object-Object-V (lambda (x y)
                     (let ((prev | contents get))
                       (contents set 
                         (? z 
                            (if (flex-equals (z) (x))
                            (y)
                            (prev (z))))))))
       (method put (self put-Object-Object-V))
       (method get-Object-Object (lambda (x)
                   (contents get (x))))
       (method get (self get-Object-Object));
2111000113210000100003232211101000321...hear
define test2 (COS_JHashMap new);
2110132100001010032210000100003211010...hear
begin (test2 put-Object-Object-V 5 10)
       (= 10 | test2 get 5);
2100011003221000010100321000010001321...hear
# There is Java code for COS_JList available
# There is Java code for COS_JHashMap available

59. testing the JList class

define test1 (COS_JList new);
2110132111110011322100000010132110100...hear
begin (test1 add-Object-V (test1))
       (= 1 (test1 size-V-I));
2100011003221111100113210000001103221...hear
(test1 get-I-Object 0) == (test1);
2211111001132100000101032033211101100...hear

60. basic iterator implementation

class COS_JListIterator (ref)
       (field pipe (cell new (ref contents get)))
       (method <init>-V (self))
       (method <init> (self <init>-V))
       (method hasNext-Z (> (list-length | pipe get) 0))
       (method hasNext (self hasNext-Z))
       (method next (self next-Object))
       (method next-Object 
           (let ((result (head | pipe get)))
         (begin 
           (pipe set | tail | pipe get)
           (result))));
2111000113210000011003221000010101332...hear
define test1 (COS_JList new);
2110132111110011322100000010132110100...hear
begin
  (test1 add 15)
  (test1 add 72)
  (test1 add 99)
  (true);
2100011003221111100113211100003211113...hear
define iter1 (test1 iterator);
2110132100001101032211111001132100000...hear
iter1 hasNext;
2100001101032100001100032233hear
(equal 99 | iter1 next);
2100032110001130232100001101032101011...hear
iter1 hasNext;
2100001101032100001100032233hear
(equal 72 | iter1 next);
2100032100100030232100001101032101011...hear
iter1 hasNext;
2100001101032100001100032233hear
(equal 15 | iter1 next);
2100032111130232100001101032101011113...hear
not | iter1 hasNext;
210030232100001101032100001100032233hear
# There is Java code for COS_JListIterator available

61. class translation 'COS_JDoor'

# Produced by Fritzifier, based on JasminVisitor
# Using BCEL library to read Java bytecode
# Here is the original code:
# 
# public class COS_JDoor {
#     private COS_JRoom src, dest;
#     private String src_cmd, dest_cmd;
# 
#     public COS_JDoor(COS_JRoom src, String src_cmd,
#              COS_JRoom dest, String dest_cmd) {
#     this.src = src;
#     this.dest = dest;
#     this.src_cmd = src_cmd;
#     this.dest_cmd = dest_cmd;
#     src.addDoor(this);
#     dest.addDoor(this);
#     }
# 
#     public COS_JRoom apply(COS_JRoom src, String cmd) {
#     if (src == this.src) {
#         if (src_cmd.equals(cmd)) {
#         return this.dest;
#         }
#     }
#     if (src == this.dest) {
#         if (dest_cmd.equals(cmd)) {
#         return this.src;
#         }
#     }
#     return null;
#     }
# 
#     public COS_JRoom apply(COS_JRoom src) {
#     if (src==this.src) {
#         return this.dest;
#     }
#     if (src==this.dest) {
#         return this.src;
#     }
#     return null;
#     }
# }
class COS_JDoor ()
   (field super-ref (make-cell 0))
   (method new (set! (super-ref) ((java lang Object) | this)))
   (method super (? x | (get! | super-ref) | x))
   (method unknown (? x | self super | x))
   (field src (cell new 0))
   (field dest (cell new 0))
   (field src_cmd (cell new 0))
   (field dest_cmd (cell new 0))
   (method <init>-COS_JRoom-String-COS_JRoom-String-V
     (lambda (arg0 arg1 arg2 arg3) |
      let ((vars | cell new | make-hash | vector
                    (pair 0 (self)) (pair 1 (arg0)) (pair 2 (arg1)) (pair 3 (arg2)) (pair 4 (arg3)))
           (stack | cell new | vector)) |
      state-machine (vars) (stack) | ? jvm | ? x | cond
         ((= (x) 0) (jvm aload 0))
         ((= (x) 1) (jvm invokespecial <init>-V 0 0))
         ((= (x) 2) (jvm aload 0))
         ((= (x) 3) (jvm aload 1))
         ((= (x) 4) (jvm putfield src (COS_JRoom)))
         ((= (x) 5) (jvm aload 0))
         ((= (x) 6) (jvm aload 3))
         ((= (x) 7) (jvm putfield dest (COS_JRoom)))
         ((= (x) 8) (jvm aload 0))
         ((= (x) 9) (jvm aload 2))
         ((= (x) 10) (jvm putfield src_cmd (java lang String)))
         ((= (x) 11) (jvm aload 0))
         ((= (x) 12) (jvm aload 4))
         ((= (x) 13) (jvm putfield dest_cmd (java lang String)))
         ((= (x) 14) (jvm aload 1))
         ((= (x) 15) (jvm aload 0))
         ((= (x) 16) (jvm invokevirtual addDoor-COS_JDoor-V 1 0))
         ((= (x) 17) (jvm aload 3))
         ((= (x) 18) (jvm aload 0))
         ((= (x) 19) (jvm invokevirtual addDoor-COS_JDoor-V 1 0))
         ((= (x) 20) (jvm return))
         (jvm return))
   )

   (method <init> (self <init>-COS_JRoom-String-COS_JRoom-String-V))

   (method apply-COS_JRoom-String-COS_JRoom
     (lambda (arg0 arg1) |
      let ((vars | cell new | make-hash | vector
                    (pair 0 (self)) (pair 1 (arg0)) (pair 2 (arg1)))
           (stack | cell new | vector)) |
      state-machine (vars) (stack) | ? jvm | ? x | cond
         ((= (x) 0) (jvm aload 1))
         ((= (x) 1) (jvm aload 0))
         ((= (x) 2) (jvm getfield src (COS_JRoom)))
         ((= (x) 3) (jvm if_acmpne 12))
         ((= (x) 4) (jvm aload 0))
         ((= (x) 5) (jvm getfield src_cmd (java lang String)))
         ((= (x) 6) (jvm aload 2))
         ((= (x) 7) (jvm invokevirtual equals-Object-Z 1 1))
         ((= (x) 8) (jvm ifeq 12))
         ((= (x) 9) (jvm aload 0))
         ((= (x) 10) (jvm getfield dest (COS_JRoom)))
         ((= (x) 11) (jvm areturn))
         ((= (x) 12) (jvm aload 1))
         ((= (x) 13) (jvm aload 0))
         ((= (x) 14) (jvm getfield dest (COS_JRoom)))
         ((= (x) 15) (jvm if_acmpne 24))
         ((= (x) 16) (jvm aload 0))
         ((= (x) 17) (jvm getfield dest_cmd (java lang String)))
         ((= (x) 18) (jvm aload 2))
         ((= (x) 19) (jvm invokevirtual equals-Object-Z 1 1))
         ((= (x) 20) (jvm ifeq 24))
         ((= (x) 21) (jvm aload 0))
         ((= (x) 22) (jvm getfield src (COS_JRoom)))
         ((= (x) 23) (jvm areturn))
         ((= (x) 24) (jvm aconst_null))
         ((= (x) 25) (jvm areturn))
         (jvm return))
   )

   (method apply (self apply-COS_JRoom-String-COS_JRoom))

   (method apply-COS_JRoom-COS_JRoom
     (lambda (arg0) |
      let ((vars | cell new | make-hash | vector
                    (pair 0 (self)) (pair 1 (arg0)))
           (stack | cell new | vector)) |
      state-machine (vars) (stack) | ? jvm | ? x | cond
         ((= (x) 0) (jvm aload 1))
         ((= (x) 1) (jvm aload 0))
         ((= (x) 2) (jvm getfield src (COS_JRoom)))
         ((= (x) 3) (jvm if_acmpne 7))
         ((= (x) 4) (jvm aload 0))
         ((= (x) 5) (jvm getfield dest (COS_JRoom)))
         ((= (x) 6) (jvm areturn))
         ((= (x) 7) (jvm aload 1))
         ((= (x) 8) (jvm aload 0))
         ((= (x) 9) (jvm getfield dest (COS_JRoom)))
         ((= (x) 10) (jvm if_acmpne 14))
         ((= (x) 11) (jvm aload 0))
         ((= (x) 12) (jvm getfield src (COS_JRoom)))
         ((= (x) 13) (jvm areturn))
         ((= (x) 14) (jvm aconst_null))
         ((= (x) 15) (jvm areturn))
         (jvm return))
   )

 ;
2111000113210000110113232211101000321...hear

62. class translation 'COS_JThing'

# Produced by Fritzifier, based on JasminVisitor
# Using BCEL library to read Java bytecode
# Here is the original code:
# 
# public class COS_JThing extends COS_JNamed {
#     private COS_JRoom location;
#     private COS_JRoom nextLocation;
# 
#     public void setRoom(COS_JRoom location) {
#     if (this.location!=null) {
#         this.location.removeThing(this);
#     }
#     this.location = location;
#     location.addThing(this);
#     this.nextLocation = location;
#     }
#     
#     public COS_JRoom getRoom() {
#     return location;
#     }
# 
#     public void setNextRoom(COS_JRoom location) {
#     nextLocation = location;
#     }
# 
#     public void postUpdate() {
#     if (nextLocation!=location) {
#         setRoom(nextLocation);
#     }
#     }
# }
# 
class COS_JThing ()
   (field super-ref (make-cell 0))
   (method new (set! (super-ref) ((COS_JNamed) | this)))
   (method super (? x | (get! | super-ref) | x))
   (method unknown (? x | self super | x))
   (field location (cell new 0))
   (field nextLocation (cell new 0))
   (method <init>-V
     (lambda () |
      let ((vars | cell new | make-hash | vector
                    (pair 0 (self)))
           (stack | cell new | vector)) |
      state-machine (vars) (stack) | ? jvm | ? x | cond
         ((= (x) 0) (jvm aload 0))
         ((= (x) 1) (jvm invokespecial <init>-V 0 0))
         ((= (x) 2) (jvm return))
         (jvm return))
   )

   (method <init> (self <init>-V))

   (method setRoom-COS_JRoom-V
     (lambda (arg0) |
      let ((vars | cell new | make-hash | vector
                    (pair 0 (self)) (pair 1 (arg0)))
           (stack | cell new | vector)) |
      state-machine (vars) (stack) | ? jvm | ? x | cond
         ((= (x) 0) (jvm aload 0))
         ((= (x) 1) (jvm getfield location (COS_JRoom)))
         ((= (x) 2) (jvm ifnull 7))
         ((= (x) 3) (jvm aload 0))
         ((= (x) 4) (jvm getfield location (COS_JRoom)))
         ((= (x) 5) (jvm aload 0))
         ((= (x) 6) (jvm invokevirtual removeThing-COS_JThing-V 1 0))
         ((= (x) 7) (jvm aload 0))
         ((= (x) 8) (jvm aload 1))
         ((= (x) 9) (jvm putfield location (COS_JRoom)))
         ((= (x) 10) (jvm aload 1))
         ((= (x) 11) (jvm aload 0))
         ((= (x) 12) (jvm invokevirtual addThing-COS_JThing-V 1 0))
         ((= (x) 13) (jvm aload 0))
         ((= (x) 14) (jvm aload 1))
         ((= (x) 15) (jvm putfield nextLocation (COS_JRoom)))
         ((= (x) 16) (jvm return))
         (jvm return))
   )

   (method setRoom (self setRoom-COS_JRoom-V))

   (method getRoom-COS_JRoom
     (lambda () |
      let ((vars | cell new | make-hash | vector
                    (pair 0 (self)))
           (stack | cell new | vector)) |
      state-machine (vars) (stack) | ? jvm | ? x | cond
         ((= (x) 0) (jvm aload 0))
         ((= (x) 1) (jvm getfield location (COS_JRoom)))
         ((= (x) 2) (jvm areturn))
         (jvm return))
   )

   (method getRoom (self getRoom-COS_JRoom))

   (method setNextRoom-COS_JRoom-V
     (lambda (arg0) |
      let ((vars | cell new | make-hash | vector
                    (pair 0 (self)) (pair 1 (arg0)))
           (stack | cell new | vector)) |
      state-machine (vars) (stack) | ? jvm | ? x | cond
         ((= (x) 0) (jvm aload 0))
         ((= (x) 1) (jvm aload 1))
         ((= (x) 2) (jvm putfield nextLocation (COS_JRoom)))
         ((= (x) 3) (jvm return))
         (jvm return))
   )

   (method setNextRoom (self setNextRoom-COS_JRoom-V))

   (method postUpdate-V
     (lambda () |
      let ((vars | cell new | make-hash | vector
                    (pair 0 (self)))
           (stack | cell new | vector)) |
      state-machine (vars) (stack) | ? jvm | ? x | cond
         ((= (x) 0) (jvm aload 0))
         ((= (x) 1) (jvm getfield nextLocation (COS_JRoom)))
         ((= (x) 2) (jvm aload 0))
         ((= (x) 3) (jvm getfield location (COS_JRoom)))
         ((= (x) 4) (jvm if_acmpeq 9))
         ((= (x) 5) (jvm aload 0))
         ((= (x) 6) (jvm aload 0))
         ((= (x) 7) (jvm getfield nextLocation (COS_JRoom)))
         ((= (x) 8) (jvm invokevirtual setRoom-COS_JRoom-V 1 0))
         ((= (x) 9) (jvm return))
         (jvm return))
   )

   (method postUpdate (self postUpdate-V))

 ;
2111000113210001001003232211101000321...hear

63. class translation 'COS_JRoom'

# Produced by Fritzifier, based on JasminVisitor
# Using BCEL library to read Java bytecode
# Here is the original code:
# 
# import java.util.Iterator;
# 
# public class COS_JRoom extends COS_JNamed {
#     //private COS_JList content = new COS_JList();
#     //private COS_JList doors = new COS_JList();
# 
#     private COS_JList content;
#     private COS_JList doors;
# 
#     public COS_JRoom() {
#     content = new COS_JList();
#     doors = new COS_JList();
#     }
# 
#     public COS_JList get() {
#     return content;
#     }
# 
#     public Iterator getDoors() {
#     return doors.iterator();
#     }
# 
#     public void addDoor(COS_JDoor door) {
#     //System.out.println("add door -> " + getName());
#     doors.add(door);
#     }
# 
#     public void addThing(COS_JThing thing) {
#     content.add(thing);
#     }
# 
#     public void removeThing(COS_JThing thing) {
#     content.remove(thing);
#     }
# }
class COS_JRoom ()
   (field super-ref (make-cell 0))
   (method new (set! (super-ref) ((COS_JNamed) | this)))
   (method super (? x | (get! | super-ref) | x))
   (method unknown (? x | self super | x))
   (field content (cell new 0))
   (field doors (cell new 0))
   (method <init>-V
     (lambda () |
      let ((vars | cell new | make-hash | vector
                    (pair 0 (self)))
           (stack | cell new | vector)) |
      state-machine (vars) (stack) | ? jvm | ? x | cond
         ((= (x) 0) (jvm aload 0))
         ((= (x) 1) (jvm invokespecial <init>-V 0 0))
         ((= (x) 2) (jvm aload 0))
         ((= (x) 3) (jvm new (COS_JList)))
         ((= (x) 4) (jvm dup))
         ((= (x) 5) (jvm invokespecial <init>-V 0 0))
         ((= (x) 6) (jvm putfield content (COS_JList)))
         ((= (x) 7) (jvm aload 0))
         ((= (x) 8) (jvm new (COS_JList)))
         ((= (x) 9) (jvm dup))
         ((= (x) 10) (jvm invokespecial <init>-V 0 0))
         ((= (x) 11) (jvm putfield doors (COS_JList)))
         ((= (x) 12) (jvm return))
         (jvm return))
   )

   (method <init> (self <init>-V))

   (method get-COS_JList
     (lambda () |
      let ((vars | cell new | make-hash | vector
                    (pair 0 (self)))
           (stack | cell new | vector)) |
      state-machine (vars) (stack) | ? jvm | ? x | cond
         ((= (x) 0) (jvm aload 0))
         ((= (x) 1) (jvm getfield content (COS_JList)))
         ((= (x) 2) (jvm areturn))
         (jvm return))
   )

   (method get (self get-COS_JList))

   (method getDoors-Iterator
     (lambda () |
      let ((vars | cell new | make-hash | vector
                    (pair 0 (self)))
           (stack | cell new | vector)) |
      state-machine (vars) (stack) | ? jvm | ? x | cond
         ((= (x) 0) (jvm aload 0))
         ((= (x) 1) (jvm getfield doors (COS_JList)))
         ((= (x) 2) (jvm invokevirtual iterator-Iterator 0 1))
         ((= (x) 3) (jvm areturn))
         (jvm return))
   )

   (method getDoors (self getDoors-Iterator))

   (method addDoor-COS_JDoor-V
     (lambda (arg0) |
      let ((vars | cell new | make-hash | vector
                    (pair 0 (self)) (pair 1 (arg0)))
           (stack | cell new | vector)) |
      state-machine (vars) (stack) | ? jvm | ? x | cond
         ((= (x) 0) (jvm aload 0))
         ((= (x) 1) (jvm getfield doors (COS_JList)))
         ((= (x) 2) (jvm aload 1))
         ((= (x) 3) (jvm invokevirtual add-Object-V 1 0))
         ((= (x) 4) (jvm return))
         (jvm return))
   )

   (method addDoor (self addDoor-COS_JDoor-V))

   (method addThing-COS_JThing-V
     (lambda (arg0) |
      let ((vars | cell new | make-hash | vector
                    (pair 0 (self)) (pair 1 (arg0)))
           (stack | cell new | vector)) |
      state-machine (vars) (stack) | ? jvm | ? x | cond
         ((= (x) 0) (jvm aload 0))
         ((= (x) 1) (jvm getfield content (COS_JList)))
         ((= (x) 2) (jvm aload 1))
         ((= (x) 3) (jvm invokevirtual add-Object-V 1 0))
         ((= (x) 4) (jvm return))
         (jvm return))
   )

   (method addThing (self addThing-COS_JThing-V))

   (method removeThing-COS_JThing-V
     (lambda (arg0) |
      let ((vars | cell new | make-hash | vector
                    (pair 0 (self)) (pair 1 (arg0)))
           (stack | cell new | vector)) |
      state-machine (vars) (stack) | ? jvm | ? x | cond
         ((= (x) 0) (jvm aload 0))
         ((= (x) 1) (jvm getfield content (COS_JList)))
         ((= (x) 2) (jvm aload 1))
         ((= (x) 3) (jvm invokevirtual remove-Object-Z 1 1))
         ((= (x) 4) (jvm pop))
         ((= (x) 5) (jvm return))
         (jvm return))
   )

   (method removeThing (self removeThing-COS_JThing-V))

 ;
2111000113210001000003232211101000321...hear

64. class translation 'COS_JNamed'

# Produced by Fritzifier, based on JasminVisitor
# Using BCEL library to read Java bytecode
# Here is the original code:
# 
# public class COS_JNamed {
#     private String name = "-";
#     private COS_JWorld world = null;
# 
#     void setName(String name) {
#     this.name = name;
#     }
# 
#     String getName() {
#     return name;
#     }
# 
#     void setWorld(COS_JWorld world) {
#     this.world = world;
#     }
# 
#     COS_JWorld getWorld() {
#     return world;
#     }
# 
#     void update() {
#     }
# 
#     void postUpdate() {
#     }
# }
class COS_JNamed ()
   (field super-ref (make-cell 0))
   (method new (set! (super-ref) ((java lang Object) | this)))
   (method super (? x | (get! | super-ref) | x))
   (method unknown (? x | self super | x))
   (field name (cell new 0))
   (field world (cell new 0))
   (method <init>-V
     (lambda () |
      let ((vars | cell new | make-hash | vector
                    (pair 0 (self)))
           (stack | cell new | vector)) |
      state-machine (vars) (stack) | ? jvm | ? x | cond
         ((= (x) 0) (jvm aload 0))
         ((= (x) 1) (jvm invokespecial <init>-V 0 0))
         ((= (x) 2) (jvm aload 0))
         ((= (x) 3) (jvm ldc (String new int-init "-")))
         ((= (x) 4) (jvm putfield name (java lang String)))
         ((= (x) 5) (jvm aload 0))
         ((= (x) 6) (jvm aconst_null))
         ((= (x) 7) (jvm putfield world (COS_JWorld)))
         ((= (x) 8) (jvm return))
         (jvm return))
   )

   (method <init> (self <init>-V))

   (method setName-String-V
     (lambda (arg0) |
      let ((vars | cell new | make-hash | vector
                    (pair 0 (self)) (pair 1 (arg0)))
           (stack | cell new | vector)) |
      state-machine (vars) (stack) | ? jvm | ? x | cond
         ((= (x) 0) (jvm aload 0))
         ((= (x) 1) (jvm aload 1))
         ((= (x) 2) (jvm putfield name (java lang String)))
         ((= (x) 3) (jvm return))
         (jvm return))
   )

   (method setName (self setName-String-V))

   (method getName-String
     (lambda () |
      let ((vars | cell new | make-hash | vector
                    (pair 0 (self)))
           (stack | cell new | vector)) |
      state-machine (vars) (stack) | ? jvm | ? x | cond
         ((= (x) 0) (jvm aload 0))
         ((= (x) 1) (jvm getfield name (java lang String)))
         ((= (x) 2) (jvm areturn))
         (jvm return))
   )

   (method getName (self getName-String))

   (method setWorld-COS_JWorld-V
     (lambda (arg0) |
      let ((vars | cell new | make-hash | vector
                    (pair 0 (self)) (pair 1 (arg0)))
           (stack | cell new | vector)) |
      state-machine (vars) (stack) | ? jvm | ? x | cond
         ((= (x) 0) (jvm aload 0))
         ((= (x) 1) (jvm aload 1))
         ((= (x) 2) (jvm putfield world (COS_JWorld)))
         ((= (x) 3) (jvm return))
         (jvm return))
   )

   (method setWorld (self setWorld-COS_JWorld-V))

   (method getWorld-COS_JWorld
     (lambda () |
      let ((vars | cell new | make-hash | vector
                    (pair 0 (self)))
           (stack | cell new | vector)) |
      state-machine (vars) (stack) | ? jvm | ? x | cond
         ((= (x) 0) (jvm aload 0))
         ((= (x) 1) (jvm getfield world (COS_JWorld)))
         ((= (x) 2) (jvm areturn))
         (jvm return))
   )

   (method getWorld (self getWorld-COS_JWorld))

   (method update-V
     (lambda () |
      let ((vars | cell new | make-hash | vector
                    (pair 0 (self)))
           (stack | cell new | vector)) |
      state-machine (vars) (stack) | ? jvm | ? x | cond
         ((= (x) 0) (jvm return))
         (jvm return))
   )

   (method update (self update-V))

   (method postUpdate-V
     (lambda () |
      let ((vars | cell new | make-hash | vector
                    (pair 0 (self)))
           (stack | cell new | vector)) |
      state-machine (vars) (stack) | ? jvm | ? x | cond
         ((= (x) 0) (jvm return))
         (jvm return))
   )

   (method postUpdate (self postUpdate-V))

 ;
2111000113210001001013232211101000321...hear

65. class translation 'COS_JWorld'

# Produced by Fritzifier, based on JasminVisitor
# Using BCEL library to read Java bytecode
# Here is the original code:
# 
# import java.util.Iterator;
# 
# public class COS_JWorld {
#     private COS_JHashMap content;
#     private COS_JList inventory;
# 
#     public COS_JWorld() {
#     content = new COS_JHashMap();
#     inventory = new COS_JList();
#     }
# 
#     public void add(COS_JNamed named, String name) {
#     named.setName(name);
#     content.put(named.getName(),named);
#     inventory.add(named);
#     }
# 
#     public COS_JNamed get(String name) {
#     return (COS_JNamed)content.get(new String(name));
#     }
# 
#     public void update() {
#     for (Iterator i = inventory.iterator(); i.hasNext(); ) {
#         COS_JNamed o = (COS_JNamed) i.next();
#         o.update();
#     }
#     for (Iterator i = inventory.iterator(); i.hasNext(); ) {
#         COS_JNamed o = (COS_JNamed) i.next();
#         o.postUpdate();
#     }
#     }
# }
class COS_JWorld ()
   (field super-ref (make-cell 0))
   (method new (set! (super-ref) ((java lang Object) | this)))
   (method super (? x | (get! | super-ref) | x))
   (method unknown (? x | self super | x))
   (field content (cell new 0))
   (field inventory (cell new 0))
   (method <init>-V
     (lambda () |
      let ((vars | cell new | make-hash | vector
                    (pair 0 (self)))
           (stack | cell new | vector)) |
      state-machine (vars) (stack) | ? jvm | ? x | cond
         ((= (x) 0) (jvm aload 0))
         ((= (x) 1) (jvm invokespecial <init>-V 0 0))
         ((= (x) 2) (jvm aload 0))
         ((= (x) 3) (jvm new (COS_JHashMap)))
         ((= (x) 4) (jvm dup))
         ((= (x) 5) (jvm invokespecial <init>-V 0 0))
         ((= (x) 6) (jvm putfield content (COS_JHashMap)))
         ((= (x) 7) (jvm aload 0))
         ((= (x) 8) (jvm new (COS_JList)))
         ((= (x) 9) (jvm dup))
         ((= (x) 10) (jvm invokespecial <init>-V 0 0))
         ((= (x) 11) (jvm putfield inventory (COS_JList)))
         ((= (x) 12) (jvm return))
         (jvm return))
   )

   (method <init> (self <init>-V))

   (method add-COS_JNamed-String-V
     (lambda (arg0 arg1) |
      let ((vars | cell new | make-hash | vector
                    (pair 0 (self)) (pair 1 (arg0)) (pair 2 (arg1)))
           (stack | cell new | vector)) |
      state-machine (vars) (stack) | ? jvm | ? x | cond
         ((= (x) 0) (jvm aload 1))
         ((= (x) 1) (jvm aload 2))
         ((= (x) 2) (jvm invokevirtual setName-String-V 1 0))
         ((= (x) 3) (jvm aload 0))
         ((= (x) 4) (jvm getfield content (COS_JHashMap)))
         ((= (x) 5) (jvm aload 1))
         ((= (x) 6) (jvm invokevirtual getName-String 0 1))
         ((= (x) 7) (jvm aload 1))
         ((= (x) 8) (jvm invokevirtual put-Object-Object-V 2 0))
         ((= (x) 9) (jvm aload 0))
         ((= (x) 10) (jvm getfield inventory (COS_JList)))
         ((= (x) 11) (jvm aload 1))
         ((= (x) 12) (jvm invokevirtual add-Object-V 1 0))
         ((= (x) 13) (jvm return))
         (jvm return))
   )

   (method add (self add-COS_JNamed-String-V))

   (method get-String-COS_JNamed
     (lambda (arg0) |
      let ((vars | cell new | make-hash | vector
                    (pair 0 (self)) (pair 1 (arg0)))
           (stack | cell new | vector)) |
      state-machine (vars) (stack) | ? jvm | ? x | cond
         ((= (x) 0) (jvm aload 0))
         ((= (x) 1) (jvm getfield content (COS_JHashMap)))
         ((= (x) 2) (jvm new (java lang String)))
         ((= (x) 3) (jvm dup))
         ((= (x) 4) (jvm aload 1))
         ((= (x) 5) (jvm invokespecial <init>-String-V 1 0))
         ((= (x) 6) (jvm invokevirtual get-Object-Object 1 1))
         ((= (x) 7) (jvm checkcast (COS_JNamed)))
         ((= (x) 8) (jvm areturn))
         (jvm return))
   )

   (method get (self get-String-COS_JNamed))

   (method update-V
     (lambda () |
      let ((vars | cell new | make-hash | vector
                    (pair 0 (self)))
           (stack | cell new | vector)) |
      state-machine (vars) (stack) | ? jvm | ? x | cond
         ((= (x) 0) (jvm aload 0))
         ((= (x) 1) (jvm getfield inventory (COS_JList)))
         ((= (x) 2) (jvm invokevirtual iterator-Iterator 0 1))
         ((= (x) 3) (jvm astore 1))
         ((= (x) 4) (jvm aload 1))
         ((= (x) 5) (jvm invokeinterface hasNext-Z 0 1 1))
         ((= (x) 6) (jvm ifeq 14))
         ((= (x) 7) (jvm aload 1))
         ((= (x) 8) (jvm invokeinterface next-Object 0 1 1))
         ((= (x) 9) (jvm checkcast (COS_JNamed)))
         ((= (x) 10) (jvm astore 2))
         ((= (x) 11) (jvm aload 2))
         ((= (x) 12) (jvm invokevirtual update-V 0 0))
         ((= (x) 13) (jvm goto 4))
         ((= (x) 14) (jvm aload 0))
         ((= (x) 15) (jvm getfield inventory (COS_JList)))
         ((= (x) 16) (jvm invokevirtual iterator-Iterator 0 1))
         ((= (x) 17) (jvm astore 1))
         ((= (x) 18) (jvm aload 1))
         ((= (x) 19) (jvm invokeinterface hasNext-Z 0 1 1))
         ((= (x) 20) (jvm ifeq 28))
         ((= (x) 21) (jvm aload 1))
         ((= (x) 22) (jvm invokeinterface next-Object 0 1 1))
         ((= (x) 23) (jvm checkcast (COS_JNamed)))
         ((= (x) 24) (jvm astore 2))
         ((= (x) 25) (jvm aload 2))
         ((= (x) 26) (jvm invokevirtual postUpdate-V 0 0))
         ((= (x) 27) (jvm goto 18))
         ((= (x) 28) (jvm return))
         (jvm return))
   )

   (method update (self update-V))

 ;
2111000113210001110013232211101000321...hear

66. class translation 'COS_JRobo'

# Produced by Fritzifier, based on JasminVisitor
# Using BCEL library to read Java bytecode
# Here is the original code:
# 
# import java.util.Iterator;
# 
# public class COS_JRobo extends COS_JThing {
#     private COS_JHashMap times;
#     private int now;
# 
#     public COS_JRobo() {
#     times = new COS_JHashMap();
#     now = 1;
#     }
# 
#     public void update() {
#     COS_JRoom location = getRoom();
#     //System.out.println("Updating robo...");
#     if (location!=null) {
#         int oldestTime = now;
#         COS_JDoor oldestDoor = null;
#         for (Iterator i = location.getDoors(); i.hasNext(); ) {
#         COS_JDoor door = (COS_JDoor) i.next();
#         //System.out.println(" scanning door ");
#         Integer t = (Integer)times.get(door);
#         int v = 0;
#         if (t!=null) {
#             v = t.intValue();
#         }
#         if (v<oldestTime) {
#             oldestTime = v;
#             oldestDoor = door;
#         }
#         }
#         if (oldestDoor!=null) {
#         times.put(oldestDoor,new Integer(now));
#         setNextRoom(oldestDoor.apply(location));
#         }
#     }
#     now++;
#     }
# }
# 
class COS_JRobo ()
   (field super-ref (make-cell 0))
   (method new (set! (super-ref) ((COS_JThing) | this)))
   (method super (? x | (get! | super-ref) | x))
   (method unknown (? x | self super | x))
   (field times (cell new 0))
   (field now ((int) new))
   (method <init>-V
     (lambda () |
      let ((vars | cell new | make-hash | vector
                    (pair 0 (self)))
           (stack | cell new | vector)) |
      state-machine (vars) (stack) | ? jvm | ? x | cond
         ((= (x) 0) (jvm aload 0))
         ((= (x) 1) (jvm invokespecial <init>-V 0 0))
         ((= (x) 2) (jvm aload 0))
         ((= (x) 3) (jvm new (COS_JHashMap)))
         ((= (x) 4) (jvm dup))
         ((= (x) 5) (jvm invokespecial <init>-V 0 0))
         ((= (x) 6) (jvm putfield times (COS_JHashMap)))
         ((= (x) 7) (jvm aload 0))
         ((= (x) 8) (jvm iconst 1))
         ((= (x) 9) (jvm putfield now (int)))
         ((= (x) 10) (jvm return))
         (jvm return))
   )

   (method <init> (self <init>-V))

   (method update-V
     (lambda () |
      let ((vars | cell new | make-hash | vector
                    (pair 0 (self)))
           (stack | cell new | vector)) |
      state-machine (vars) (stack) | ? jvm | ? x | cond
         ((= (x) 0) (jvm aload 0))
         ((= (x) 1) (jvm invokevirtual getRoom-COS_JRoom 0 1))
         ((= (x) 2) (jvm astore 1))
         ((= (x) 3) (jvm aload 1))
         ((= (x) 4) (jvm ifnull 57))
         ((= (x) 5) (jvm aload 0))
         ((= (x) 6) (jvm getfield now (int)))
         ((= (x) 7) (jvm istore 2))
         ((= (x) 8) (jvm aconst_null))
         ((= (x) 9) (jvm astore 3))
         ((= (x) 10) (jvm aload 1))
         ((= (x) 11) (jvm invokevirtual getDoors-Iterator 0 1))
         ((= (x) 12) (jvm astore 4))
         ((= (x) 13) (jvm aload 4))
         ((= (x) 14) (jvm invokeinterface hasNext-Z 0 1 1))
         ((= (x) 15) (jvm ifeq 41))
         ((= (x) 16) (jvm aload 4))
         ((= (x) 17) (jvm invokeinterface next-Object 0 1 1))
         ((= (x) 18) (jvm checkcast (COS_JDoor)))
         ((= (x) 19) (jvm astore 5))
         ((= (x) 20) (jvm aload 0))
         ((= (x) 21) (jvm getfield times (COS_JHashMap)))
         ((= (x) 22) (jvm aload 5))
         ((= (x) 23) (jvm invokevirtual get-Object-Object 1 1))
         ((= (x) 24) (jvm checkcast (java lang Integer)))
         ((= (x) 25) (jvm astore 6))
         ((= (x) 26) (jvm iconst 0))
         ((= (x) 27) (jvm istore 7))
         ((= (x) 28) (jvm aload 6))
         ((= (x) 29) (jvm ifnull 33))
         ((= (x) 30) (jvm aload 6))
         ((= (x) 31) (jvm invokevirtual intValue-I 0 1))
         ((= (x) 32) (jvm istore 7))
         ((= (x) 33) (jvm iload 7))
         ((= (x) 34) (jvm iload 2))
         ((= (x) 35) (jvm if_icmpge 40))
         ((= (x) 36) (jvm iload 7))
         ((= (x) 37) (jvm istore 2))
         ((= (x) 38) (jvm aload 5))
         ((= (x) 39) (jvm astore 3))
         ((= (x) 40) (jvm goto 13))
         ((= (x) 41) (jvm aload 3))
         ((= (x) 42) (jvm ifnull 57))
         ((= (x) 43) (jvm aload 0))
         ((= (x) 44) (jvm getfield times (COS_JHashMap)))
         ((= (x) 45) (jvm aload 3))
         ((= (x) 46) (jvm new (java lang Integer)))
         ((= (x) 47) (jvm dup))
         ((= (x) 48) (jvm aload 0))
         ((= (x) 49) (jvm getfield now (int)))
         ((= (x) 50) (jvm invokespecial <init>-I-V 1 0))
         ((= (x) 51) (jvm invokevirtual put-Object-Object-V 2 0))
         ((= (x) 52) (jvm aload 0))
         ((= (x) 53) (jvm aload 3))
         ((= (x) 54) (jvm aload 1))
         ((= (x) 55) (jvm invokevirtual apply-COS_JRoom-COS_JRoom 1 1))
         ((= (x) 56) (jvm invokevirtual setNextRoom-COS_JRoom-V 1 0))
         ((= (x) 57) (jvm aload 0))
         ((= (x) 58) (jvm dup))
         ((= (x) 59) (jvm getfield now (int)))
         ((= (x) 60) (jvm iconst 1))
         ((= (x) 61) (jvm iadd))
         ((= (x) 62) (jvm putfield now (int)))
         ((= (x) 63) (jvm return))
         (jvm return))
   )

   (method update (self update-V))

 ;
2111000113210010001013232211101000321...hear

67. test JRoom, JDoor, JThing, etc

define s (? x | String new int-init | x);
2110132100100100132211003210011030232...hear
define room1 (COS_JRoom new <init>);
2110132100100101032210001000003211010...hear
define room2 (COS_JRoom new <init>);
2110132100100101132210001000003211010...hear
define door12 (COS_JDoor new <init> 
              (room1) (s "south") (room2) (s "north"));
2110132100100110032210000110113211010...hear
define jworld (COS_JWorld new <init>);
2110132100100110132210001110013211010...hear
define thing1 (COS_JThing new <init>);
2110132100100111032210001001003211010...hear
define robo1 (COS_JRobo new <init>);
2110132100100111132210010001013211010...hear
act | jworld add (thing1) | s "bus";
2110000000302321001001101321110000322...hear
act | jworld add (robo1) | s "autobus";
2110000000302321001001101321110000322...hear
act | jworld add (room1) | s "boston";
2110000000302321001001101321110000322...hear
act | jworld add (room2) | s "newyork";
2110000000302321001001101321110000322...hear
begin (room1 get add (room1))
       (= 1 | room1 get size);
2100011003221001001010321111010132111...hear
= 1 | room1 get size;
2103213023210010010103211110101321000...hear
= 0 | room2 get size;
2103203023210010010113211110101321000...hear
act | thing1 setRoom (room1);
2110000000302321001001110321000101010...hear
= 2 | room1 get size;
2103210302321001001010321111010132100...hear
= 0 | room2 get size;
2103203023210010010113211110101321000...hear
act | thing1 setRoom (room2);
2110000000302321001001110321000101010...hear
room1 get size;
21001001010321111010132100000111132233hear
room2 get size;
21001001011321111010132100000111132233hear
thing1 equals (thing1);
2100100111032101111111322100100111033...hear
room1 equals (room1);
2100100101032101111111322100100101033...hear
not | thing1 equals (room1);
2100302321001001110321011111113221001...hear
(equal "newyork" | door12 apply (room1) (s "south") getName intValue);
2100032100001101001000010001101100101...hear
(equal "boston" | door12 apply (room2) (s "north") getName intValue);
2100032100011001000101110010000100100...hear
define o
  (? x | jworld get | s | x);
2110132110000111322110032100110302321...hear
= "newyork" | (o "bus") getRoom getName intValue;
2103210000110100100001000110110010100...hear
act | robo1 setRoom (room1);
2110000000302321001001111321000101010...hear
(equal "boston" | (o "autobus") getRoom getName intValue);
2100032100011001000101110010000100100...hear
act | jworld update;
2110000000302321001001101321000101003...hear
(equal "newyork" | (o "autobus") getRoom getName intValue);
2100032100001101001000010001101100101...hear
Fork me on GitHub