# Author: Paul Fitzpatrick, paulfitz@ai.mit.edu
# Copyright (c) 2003 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
#

# introduce counting
00,0,,0,,,0,,,,0,,,,,.
0,,,,,0,,,,0,,,0,,0,0.
# now show equality
00=.
0,,0,,=.
0,,,,,0,,,,,=.
0,,0,,=.
0,,,0,,,=.
00=.
# now show other comparisons
0,,0>.
0,,,,,0,>.
0,,,0,>.
0,0>.
0,,,,,,0>.
0,,,,0>.
0,,,,,0>.
0,,,,0>.
0,0>.
0,,,,,,0,>.
0,,,,,,0,,>.
0,0,,,<.
00,,,,,<.
00,,,,,,<.
00,<.
00,<.
00,,<.
0,0,,,<.
00,,<.
0,,0,,,,<.
0,,,0,,,,,<.
00,,<.
0,,,,0>.
0,,,,,0,,,,>.
0,,0,,,<.
0,,0,>.
0,,,,,0,>.
0,,,0,,,=.
0,,,0,,,=.
0,0>.
0,0,,,,<.
0,,,,0,,,,=.
0,,,0,,>.
# introduce the NOT logical operator
0,,,0,,,=.
0,,,0,,,< not.
0,,,0,,,> not.
0,,,0,,,=.
0,,,0,,,< not.
0,,,0,,,> not.
0,,,0,,,=.
0,,,0,,,< not.
0,,,0,,,> not.
0,,,,,0,,,,,=.
0,,,,,0,,,,,< not.
0,,,,,0,,,,,> not.
0,0,=.
0,0,< not.
0,0,> not.
0,,,0,,,=.
0,,,0,,,< not.
0,,,0,,,> not.
00,,= not.
00,,<.
00,,> not.
0,0,,,,= not.
0,0,,,,<.
0,0,,,,> not.
0,0,,,,= not.
0,0,,,,<.
0,0,,,,> not.
0,,0,,,,= not.
0,,0,,,,<.
0,,0,,,,> not.
0,,,,,0,,,,,,,= not.
0,,,,,0,,,,,,,<.
0,,,,,0,,,,,,,> not.
0,,,,,0,,,,,,,= not.
0,,,,,0,,,,,,,<.
0,,,,,0,,,,,,,> not.
0,,,0,= not.
0,,,0,< not.
0,,,0,>.
0,,,,,,0,,,,,= not.
0,,,,,,0,,,,,< not.
0,,,,,,0,,,,,>.
0,,,,,0,,,,= not.
0,,,,,0,,,,< not.
0,,,,,0,,,,>.
0,,,,,,,0,,,,,= not.
0,,,,,,,0,,,,,< not.
0,,,,,,,0,,,,,>.
0,,,,,,,0,,,,,= not.
0,,,,,,,0,,,,,< not.
0,,,,,,,0,,,,,>.
0,,,0,= not.
0,,,0,< not.
0,,,0,>.
# introduce the AND logical operator
0,,,,,0,,,> 0,,,,,0,,> and.
0,,,,0,,,,,,< 0,0,= and.
00= 0,,,,,,,0,,,,,> and.
0,,,,,0,,,,,= 0,,,,0,,,,= and.
0,,,,,0,,,,,,< 0,,,,,0,,,,,= and.
0,,,,,,,0,,,,,> 0,,0,,= and.
0,,,0,,,,,,< 0,,,,,0,,,,> and.
0,,0,,= 00,,< and.
0,,,,,0,,> 0,,0,,= and.
0,0,,,,< 0,,,,0,,,,= and.
0,0,,< 0,,0,,,,,= and not.
0,0,,,< 0,0,,,= and not.
0,,,0,,,,< 0,,,,,0,,< and not.
0,,,,,0,,> 0,,,,0,,= and not.
0,,,0,,> 0,,,,,,0< and not.
0,,,,,0,,,,,,= 0,,,,0,,> and not.
0,0,,,> 0,,,,,0,,,,,,< and not.
0,,0,< 0,,,,0,,,,= and not.
0,,,,0,,,,,> 0,,0,,= and not.
0,0= 0,,,,,,,0,,,,,> and not.
0,,,0,,,,,> 0,,,0,,,,,,> and not.
0,,,,,0,,,,< 0,,,,,,0,,,,,,> and not.
0,,,,0= 00,,,> and not.
0,,,,,0= 0,,,0,,,> and not.
00,,,,> 0,,0,,> and not.
00,,,,,,> 0,,,,0,= and not.
0,,,0,,,> 0,,,,,0,,,,,,= and not.
0,,,,,,,,0,,,,,> 00,,,< and.
0,,,,0,,> 00,,,< and.
0,,,0,,< 0,,,,,0,,< and not.
0,0,> 0,,0= and not.
0,,0> 0,,,,,0,,,,,> and not.
0,,0,,= 0,,0,,= and.
0,,,0,= 00,,,,,,> and not.
0,0,,< 0,,,0,,,= and.
# introduce the OR logical operator
0,,0,,,< 0,,,,,,0< or.
0,,,,,0,,,,,= 0,,,,0,,,,> or.
0,0,,< 00,,,> or.
0,,,,0,> 0,,,0,,,> or.
0,0,,,,< 00,,> or.
0,,,,,0< 00= or.
0,,0,,,,,> 0,,,,,0,,,,,= or.
0,,0,,,,,> 0,,,,,,0,,,,,> or.
0,,,,,,0,,,,,,> 0,,,,,0,,,,,,,,< or.
00,= 00,,,< or.
00= 00,,< or.
0,,,,0,,,,= 0,,,,,0,,,,,,< or.
00,< 00,,,< or.
0,0,= 0,,,,,0,,,> or.
0,,,0,,,,,,< 0,,,,,,0,,,,> or.
0,,,,,0,,< 0,,,,,,0< or not.
0,0< 0,,0= or not.
00,,,> 0,,,,,,0,,< or not.
0,,,,,,0,,,< 0,,0= or not.
00,,= 0,,,,,,0,,,< or not.
0,0,,,,,,> 0,,,,0,,,,> or not.
0,,,,,0,,,> 0,,,0,,,> or.
00= 0,,,,,0,,,< or.
0,,,,0,,,> 0,,,,,0,,< or.
0,,0,,,,,= 00,,= or not.
00,,,< 0,,,,,0,,,= or.
0,,,,,,0,,,< 0,,,0,,,,,= or not.
0,,,,,0,,,,,= 0,,,,0< or.
0,,,,,,,,0,,,,,> 0,,,0,,,= or.
0,0,,,,= 0,,,0,,,> or not.
# use equality for truth values
0,0,,,,<0,,,,0,,,,,< =.
0,,,,,0,,,,>0,,,0> =.
0,,,,0,,,,,,<0,,,,0,,,,= =.
0,,0,,=0,0> =.
0,,0,,=00,,< =.
0,,,,0,,=0,,,,,0,,,< =.
0,,,,0,,=0,,,,,0,,,,< =.
00,,=0,,,,0,,,,,,> =.
0,,,,,,0,<0,0,,,> =.
0,,,,,0<0,,,,,,0,< =.
0,,,0,,=00,,< = not.
0,0,>0,,0,,= = not.
0,0,,,,=0,0,,,,< = not.
0,,,,,0,,,,=0,,,,0,,,,,,< = not.
0,,0,<00= = not.
0,,,,0,,,,,<0,,,,0,= = not.
00=0,,,,,0< = not.
0,,,,,0,,,,,=00> = not.
0,,,,,,,0,,,,,>0,,,,,0= = not.
00=0,,,,0,,,,,= = not.
true 0,,,,0,> =.
true 0,,,0,,,,< =.
true 0,,,,,,0,,,> =.
true 0,,,,0,,,,= =.
true 0,,0,,= =.
0,,,,,,0,,,> true =.
0,,,,0,,,,,,< true =.
0,,0,,= true =.
0,,,,0,,,,= true =.
0,,,,,,,0,,,,> true =.
false 0,,,0,,,> =.
false 00,,,> =.
false 00,> =.
false 00> =.
false 00> =.
0,,,0,,,,,,> false =.
0,,,,0< false =.
0,,,,,,0,,,,,< false =.
0,0,,,,,,> false =.
0,,,0< false =.
true true =.
false false =.
true false = not.
false true = not.
# introduce addition
00,,+0,,=.
0,,,0,,+0,,,,,=.
0,0+0,=.
0,,,0,,,,+0,,,,,,,=.
0,,0,,,,+0,,,,,,=.
00,+0,=.
0,,,0,,+0,,,,,=.
0,0+0,=.
0,,0,,+0,,,,=.
0,,,,0,,,,+0,,,,,,,,=.
# introduce multiplication
00*0=.
00,*0=.
00,,*0=.
00,,,*0=.
0,0*0=.
0,0,*0,=.
0,0,,*0,,=.
0,0,,,*0,,,=.
0,,0*0=.
0,,0,*0,,=.
0,,0,,*0,,,,=.
0,,0,,,*0,,,,,,=.
0,,,0*0=.
0,,,0,*0,,,=.
0,,,0,,*0,,,,,,=.
0,,,0,,,*0,,,,,,,,,=.
0,,0,,*0,,,,=.
0,,0,*0,,=.
0,,,0,*0,,,=.
0,0*0=.
00,*0=.
0,,,0,,*0,,,,,,=.
0,,,0,*0,,,=.
0,0,,*0,,=.
00,,*0=.
0,,,0*0=.
# introduce doubling as a special case of multiplication
# as prelude to binary representation
0:0=.
0,:0,,=.
0,,:0,,,,=.
0,,,:0,,,,,,=.
0,,,,:0,,,,,,,,=.
00:=.
0,,0,:=.
0,,,,0,,:=.
0,,,,,,0,,,:=.
0,,,,,,,,0,,,,:=.
00,,*0:=.
0,0,,*0,:=.
0,,0,,*0,,:=.
0,,,0,,*0,,,:=.
0,,,,0,,*0,,,,:=.
# introduce a simple form of binary notation
# (a previous lesson reinforcing how operators chain would help)
# essentially just use fact that '0' puts zero on stack, ',' increments it,
# and ':' doubles it.
# After this lesson, in the higher-level version of the message,
# will use [XX] to stand for the binary notation given.
00=.
0,0,=.
0,,0,:=.
0,,,0,:,=.
0,,,,0,::=.
0,,,,,0,::,=.
0,,,,,,0,:,:=.
0,,,,,,,0,:,:,=.
0,,,,,,,,0,:::=.
0,,,,,,,,,0,:::,=.
0,,,,,,,,,,0,::,:=.
0,,,,,,,,,,,0,::,:,=.
0,,,,,,,,,,,,0,:,::=.
0,,,,,,,,,,,,,0,:,::,=.
0,,,,,,,,,,,,,,0,:,:,:=.
0,,,,,,,,,,,,,,,0,:,:,:,=.
0,:::,0,,,,,,,,,=.
0,:0,,=.
0,::,:0,,,,,,,,,,=.
0,::,0,,,,,=.
00=.
0,0,=.
0,0,=.
0,::0,,,,=.
0,:,::0,,,,,,,,,,,,=.
0,:,:0,,,,,,=.
0,:0,,=.
0,:,0,,,=.
00=.
0,:,:,0,,,,,,,=.
0,::,:,0,,,,,,,,,,,=.
0,0,=.
0,0,::,:,+0,:,::=.
0,:,::0,:,:,:+0,:,::,:=.
0,::,:,0,:,::+0,::,:,:,=.
0,:,::,0,::,:+0,::,:,:,=.
0,:,:0,+0,:,:,=.
0,::,0,:+0,:,:,=.
00,:,:+0,:,:=.
00,:,:,:,+0,:,:,:,=.
0,:::,0*0=.
0,:,:,:0,:,::*0,::,::,:::=.
00,:,::,*0=.
0,0,*0,=.
0,:,:,0,:*0,:,:,:=.
0,::,0*0=.
0,::,0,:*0,::,:=.
0,:::0,:,::,*0,:,::,:::=.
# demonstrate idea of leaving gaps in an expression
# and then filling them in afterwards
[5]?+[18]=[13]!
[15]?+[21]=[6]!
[10]?+[12]=[2]!
[6]?+[9]=[3]!
[15]?+[28]=[13]!
[3]?+[16]=[13]!
[5]?+[14]=[9]!
[13]?+[18]=[5]!
??*[135]=[15]![9]!
??*[42]=[6]![7]!
??*[52]=[4]![13]!
??*[98]=[7]![14]!
??*[10]=[5]![2]!
??*[30]=[5]![6]!
??*[72]=[6]![12]!
??*[6]=[3]![2]!
# this example is important since it suggests the ordering on '!'
??+?=[11]![8]![3]!
??+?=[21]![13]![8]!
??+?=[21]![7]![14]!
??+?=[22]![12]![10]!
??+?=[24]![13]![11]!
??+?=[21]![12]![9]!
??+?=[25]![12]![13]!
??+?=[22]![12]![10]!
# start to illustrate the semantics of registers
[15] [0] set [6] [1] set [0] get [15] =.
[4] [3] set [15] [2] set [3] get [4] =.
[11] [2] set [10] [3] set [2] get [11] =.
[12] [1] set [6] [3] set [1] get [12] =.
[2] [2] set [7] [3] set [2] get [2] =.
[6] [0] set [12] [1] set [0] get [6] =.
[3] [0] set [6] [3] set [0] get [3] =.
[3] [3] set [2] [4] set [3] get [3] =.
[4] [0] set [11] [2] set [0] get [4] =.
[12] [3] set [2] [2] set [3] get [12] =.
[0] [3] set [9] [2] set [3] get [0] =.
[8] [0] set [1] [1] set [0] get [8] =.
[13] [1] set [1] [1] get + [14] =.
[13] [1] set [0] [1] get + [13] =.
[12] [1] set [10] [1] get + [22] =.
[11] [1] set [9] [1] get + [20] =.
[15] [2] set [14] [2] get + [29] =.
[7] [1] set [0] [1] get + [7] =.
[0] [2] set [4] [2] get + [4] =.
[12] [2] set [15] [2] get + [27] =.
[11] [2] set [1] [2] get + [12] =.
[4] [1] set [1] [1] get + [5] =.
[7] [2] set [6] [2] get + [13] =.
[15] [0] set [11] [0] get + [26] =.
? [0] set [0] [0] get + [14] = [14] !.
? [1] set [9] [1] get + [22] = [13] !.
? [0] set [4] [0] get + [9] = [5] !.
? [1] set [0] [1] get + [13] = [13] !.
? [2] set [14] [2] get + [19] = [5] !.
? [0] set [3] [0] get + [4] = [1] !.
? [2] set [7] [2] get + [9] = [2] !.
? [0] set [4] [0] get + [15] = [11] !.
? [0] set [14] [0] get + [24] = [10] !.
? [0] set [15] [0] get + [26] = [11] !.
? [1] set [2] [1] get + [14] = [12] !.
? [1] set [5] [1] get + [10] = [5] !.
[4] 0 set 0 get 0 get * [16] =.
[4] 0 set 0 get 0 get * [16] =.
[14] 0 set 0 get 0 get * [196] =.
[8] 0 set 0 get 0 get * [64] =.
[2] 0 set 0 get 0 get * [4] =.
[12] 0 set 0 get 0 get * [144] =.
[13] 0 set 0 get 0 get * [169] =.
[12] 0 set 0 get 0 get * [144] =.
? 0 set 0 get 0 get * [1] = [1] !.
? 0 set 0 get 0 get * [196] = [14] !.
? 0 set 0 get 0 get * [225] = [15] !.
? 0 set 0 get 0 get * [0] = [0] !.
? 0 set 0 get 0 get * [100] = [10] !.
? 0 set 0 get 0 get * [0] = [0] !.
? 0 set 0 get 0 get * [100] = [10] !.
? 0 set 0 get 0 get * [196] = [14] !.
# have enough machinery for simple functions
? 0 set 0 get 0 get * fx 0, set [0] get 0, [9] ! + [81] =.
? 0 set 0 get 0 get * fx 0, set [0] get 0, [8] ! + [64] =.
? 0 set 0 get 0 get * fx 0, set [7] get 0, [5] ! + [32] =.
? 0 set 0 get 0 get * fx 0, set [3] get 0, [8] ! + [67] =.
? 0 set 0 get 0 get * fx 0, set [9] get 0, [9] ! + [90] =.
? 0 set 0 get 0 get * fx 0, set [7] get 0, [2] ! + [11] =.
? 0 set 0 get 0 get * fx 0, set [5] get 0, [5] ! + [30] =.
? 0 set 0 get 0 get * fx 0, set [9] get 0, [5] ! + [34] =.
# show side-effects : storage lasts across sentences
[5] [9] set.
[9] get [5] =.
[6] [4] set.
[4] get [6] =.
[4] [5] set.
[5] get [4] =.
[6] [2] set.
[2] get [6] =.
[5] [2] set.
[2] get [5] =.
[9] [8] set.
[8] get [9] =.
[1] [1] set.
[1] get [1] =.
[9] [4] set.
[4] get [9] =.
# set up some simple scope rules for registers
[7] [5] set [6] [5] set [5] get [6] =.
[7] [5] set [5] nu [6] [5] set [5] un [5] get [7] =.
[7] [5] set [5] nu [6] [5] set [5] get [0] set [5] un [0] get [6] =.
[6] [2] set [8] [2] set [2] get [8] =.
[6] [2] set [2] nu [8] [2] set [2] un [2] get [6] =.
[6] [2] set [2] nu [8] [2] set [2] get [1] set [2] un [1] get [8] =.
[2] [5] set [8] [5] set [5] get [8] =.
[2] [5] set [5] nu [8] [5] set [5] un [5] get [2] =.
[2] [5] set [5] nu [8] [5] set [5] get [3] set [5] un [3] get [8] =.
[7] [6] set [2] [6] set [6] get [2] =.
[7] [6] set [6] nu [2] [6] set [6] un [6] get [7] =.
[7] [6] set [6] nu [2] [6] set [6] get [7] set [6] un [7] get [2] =.
[0] [0] set [2] [0] set [0] get [2] =.
[0] [0] set [0] nu [2] [0] set [0] un [0] get [0] =.
[0] [0] set [0] nu [2] [0] set [0] get [3] set [0] un [3] get [2] =.
[9] [5] set [2] [5] set [5] get [2] =.
[9] [5] set [5] nu [2] [5] set [5] un [5] get [9] =.
[9] [5] set [5] nu [2] [5] set [5] get [6] set [5] un [6] get [2] =.
[7] [1] set [6] [1] set [1] get [6] =.
[7] [1] set [1] nu [6] [1] set [1] un [1] get [7] =.
[7] [1] set [1] nu [6] [1] set [1] get [9] set [1] un [9] get [6] =.
[3] [1] set [2] [1] set [1] get [2] =.
[3] [1] set [1] nu [2] [1] set [1] un [1] get [3] =.
[3] [1] set [1] nu [2] [1] set [1] get [2] set [1] un [2] get [2] =.
# show some simple function calls
0 nu ? 0 set 0 get 0 get * 0 un {SQUARE} set.
{SQUARE} get [0] ! [0] =.
{SQUARE} get [1] ! [1] =.
{SQUARE} get [2] ! [4] =.
{SQUARE} get [3] ! [9] =.
{SQUARE} get [4] ! [16] =.
{SQUARE} get [5] ! [25] =.
{SQUARE} get [6] ! [36] =.
{SQUARE} get [7] ! [49] =.
{SQUAREROOT} get [0] ! [0] =.
{SQUAREROOT} get [1] ! [1] =.
{SQUAREROOT} get [4] ! [2] =.
{SQUAREROOT} get [9] ! [3] =.
{SQUAREROOT} get [16] ! [4] =.
{SQUAREROOT} get [25] ! [5] =.
{SQUAREROOT} get [36] ! [6] =.
{SQUAREROOT} get [49] ! [7] =.
# show mechanisms for branching
[1] [8] true if [1] =.
[5] [1] false if [1] =.
[7] [1] false if [1] =.
[7] [6] true if [7] =.
[5] [0] true if [5] =.
[7] [4] true if [7] =.
[2] [4] true if [2] =.
[0] [5] true if [0] =.
[4] [2] false if [2] =.
[5] [7] true if [5] =.
[2] [1] false if [1] =.
[6] [9] false if [9] =.
[6] [0] false if [0] =.
[2] [5] false if [5] =.
[4] [8] false if [8] =.
[2] [2] true if [2] =.