diff --git a/docs/notebooks/2._Library_Examples.ipynb b/docs/notebooks/2._Library_Examples.ipynb index bbc1cc0..1388145 100644 --- a/docs/notebooks/2._Library_Examples.ipynb +++ b/docs/notebooks/2._Library_Examples.ipynb @@ -7,15 +7,6 @@ "# Examples (and some documentation) for the Words in the Library" ] }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "from notebook_preamble import J, V" - ] - }, { "cell_type": "markdown", "metadata": {}, @@ -33,19 +24,34 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 132, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "\n" + "1 1 3 1 2 3" ] } ], "source": [ - "J('1 2 3 clear')" + "1 2 3 " + ] + }, + { + "cell_type": "code", + "execution_count": 133, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [] + } + ], + "source": [ + "clear" ] }, { @@ -57,36 +63,66 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 134, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "1 2 3 3\n" + "1 2 3 3" ] } ], "source": [ - "J('1 2 3 dup')" + "1 2 3 dup" ] }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 135, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [] + } + ], + "source": [ + "clear" + ] + }, + { + "cell_type": "code", + "execution_count": 136, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "1 2 2 3\n" + "1 2 2 3" ] } ], "source": [ - "J('1 2 3 dupd')" + "1 2 3 dupd" + ] + }, + { + "cell_type": "code", + "execution_count": 137, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [] + } + ], + "source": [ + "clear" ] }, { @@ -100,19 +136,34 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 138, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "[3 2 1]\n" + "[3 2 1]" ] } ], "source": [ - "J('1 2 3 enstacken')" + "1 2 3 enstacken" + ] + }, + { + "cell_type": "code", + "execution_count": 139, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [] + } + ], + "source": [ + "clear" ] }, { @@ -123,20 +174,10 @@ ] }, { - "cell_type": "code", - "execution_count": 6, + "cell_type": "markdown", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "4 5 6 3 2 1\n" - ] - } - ], "source": [ - "J('4 5 6 [3 2 1] unstack')" + "4 5 6 [3 2 1] unstack" ] }, { @@ -148,19 +189,34 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 140, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "1 2 3 [3 2 1]\n" + "1 2 3 [3 2 1]" ] } ], "source": [ - "J('1 2 3 stack')" + "1 2 3 stack" + ] + }, + { + "cell_type": "code", + "execution_count": 141, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [] + } + ], + "source": [ + "clear" ] }, { @@ -174,19 +230,19 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 142, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "6 5 4\n" + "6 5 4" ] } ], "source": [ - "J('1 2 3 [4 5 6] disenstacken')" + "1 2 3 [4 5 6] disenstacken" ] }, { @@ -198,53 +254,56 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 143, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "1 2\n" + "1 2" ] } ], "source": [ - "J('1 2 3 pop')" + "clear\n", + "1 2 3 pop" ] }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 144, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "1 3\n" + "1 3" ] } ], "source": [ - "J('1 2 3 popd')" + "clear\n", + "1 2 3 popd" ] }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 145, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "1\n" + "1" ] } ], "source": [ - "J('1 2 3 popop')" + "clear\n", + "1 2 3 popop" ] }, { @@ -257,36 +316,38 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 146, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "2 3 1\n" + "2 3 1" ] } ], "source": [ - "J('1 2 3 roll<')" + "clear\n", + "1 2 3 roll<" ] }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 147, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "3 1 2\n" + "3 1 2" ] } ], "source": [ - "J('1 2 3 roll>')" + "clear\n", + "1 2 3 roll>" ] }, { @@ -298,19 +359,20 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 148, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "1 3 2\n" + "1 3 2" ] } ], "source": [ - "J('1 2 3 swap')" + "clear\n", + "1 2 3 swap" ] }, { @@ -322,36 +384,38 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 149, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "1 3 2 3\n" + "1 3 2 3" ] } ], "source": [ - "J('1 2 3 tuck')" + "clear\n", + "1 2 3 tuck" ] }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 150, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "1 2 3 2\n" + "1 2 3 2" ] } ], "source": [ - "J('1 2 3 over')" + "clear\n", + "1 2 3 over" ] }, { @@ -363,7 +427,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 151, "metadata": { "scrolled": true }, @@ -372,17 +436,18 @@ "name": "stdout", "output_type": "stream", "text": [ - "1 2 [3]\n" + "1 2 [3]" ] } ], "source": [ - "J('1 2 3 unit')" + "clear\n", + "1 2 3 unit" ] }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 152, "metadata": { "scrolled": true }, @@ -391,55 +456,56 @@ "name": "stdout", "output_type": "stream", "text": [ - "1 [2] 3\n" + "1 [2] 3" ] } ], "source": [ - "J('1 2 3 quoted')" + "clear\n", + "1 2 3 quoted" ] }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 153, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "1 2 3\n" + "1 2 3" ] } ], "source": [ - "J('1 [2] 3 unquoted')" + "clear\n", + "1 [2] 3 unquoted" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Unquoting evaluates. Be aware." ] }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 154, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - " • 1 [dup] 3 unquoted\n", - " 1 • [dup] 3 unquoted\n", - " 1 [dup] • 3 unquoted\n", - " 1 [dup] 3 • unquoted\n", - " 1 [dup] 3 • [i] dip\n", - "1 [dup] 3 [i] • dip\n", - " 1 [dup] • i 3\n", - " 1 • dup 3\n", - " 1 1 • 3\n", - " 1 1 3 • \n" + "1 1 3" ] } ], "source": [ - "V('1 [dup] 3 unquoted') # Unquoting evaluates. Be aware." + "clear\n", + "1 [dup] 3 unquoted" ] }, { @@ -458,7 +524,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 155, "metadata": { "scrolled": true }, @@ -467,17 +533,18 @@ "name": "stdout", "output_type": "stream", "text": [ - "[1 2 3 4 5 6]\n" + "[1 2 3 4 5 6]" ] } ], "source": [ - "J('[1 2 3] [4 5 6] concat')" + "clear\n", + "[1 2 3] [4 5 6] concat" ] }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 156, "metadata": { "scrolled": true }, @@ -486,17 +553,18 @@ "name": "stdout", "output_type": "stream", "text": [ - "[4 5 6 1 2 3]\n" + "[4 5 6 1 2 3]" ] } ], "source": [ - "J('[1 2 3] [4 5 6] swoncat')" + "clear\n", + "[1 2 3] [4 5 6] swoncat" ] }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 157, "metadata": { "scrolled": true }, @@ -505,12 +573,13 @@ "name": "stdout", "output_type": "stream", "text": [ - "[6 5 4 1 2 3]\n" + "[6 5 4 1 2 3]" ] } ], "source": [ - "J('[1 2 3] [4 5 6] shunt')" + "clear\n", + "[1 2 3] [4 5 6] shunt" ] }, { @@ -522,53 +591,56 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 158, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "[1 2 3]\n" + "[1 2 3]" ] } ], "source": [ - "J('1 [2 3] cons')" + "clear\n", + "1 [2 3] cons" ] }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 159, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "[1 2 3]\n" + "[1 2 3]" ] } ], "source": [ - "J('[2 3] 1 swons')" + "clear\n", + "[2 3] 1 swons" ] }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 160, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "1 [2 3]\n" + "1 [2 3]" ] } ], "source": [ - "J('[1 2 3] uncons')" + "clear\n", + "[1 2 3] uncons" ] }, { @@ -580,58 +652,61 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 161, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "1\n" + "1" ] } ], "source": [ - "J('[1 2 3 4] first')" + "clear\n", + "[1 2 3 4] first" ] }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 162, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "2\n" + "2" ] } ], "source": [ - "J('[1 2 3 4] second')" + "clear\n", + "[1 2 3 4] second" ] }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 163, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "3\n" + "3" ] } ], "source": [ - "J('[1 2 3 4] third')" + "clear\n", + "[1 2 3 4] third" ] }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 166, "metadata": { "scrolled": true }, @@ -640,12 +715,13 @@ "name": "stdout", "output_type": "stream", "text": [ - "[2 3 4]\n" + "[2 3 4]" ] } ], "source": [ - "J('[1 2 3 4] rest')" + "clear\n", + "[1 2 3 4] rest" ] }, { @@ -657,19 +733,20 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 167, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "[1 2 [3] 4 5 6]\n" + "[1 2 [3] 4 5 6]" ] } ], "source": [ - "J('[[1] [2 [3] 4] [5 6]] flatten')" + "clear\n", + "[[1] [2 [3] 4] [5 6]] flatten" ] }, { @@ -683,7 +760,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 168, "metadata": { "scrolled": true }, @@ -692,80 +769,92 @@ "name": "stdout", "output_type": "stream", "text": [ - "12\n" + "12" ] } ], "source": [ - "J('[10 11 12 13 14] 2 getitem')" + "clear\n", + "[10 11 12 13 14] 2 getitem" ] }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 169, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "1\n" + "1" ] } ], "source": [ - "J('[1 2 3 4] 0 at')" + "clear\n", + "[1 2 3 4] 0 at" ] }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 170, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "3\n" + "3" ] } ], "source": [ - "J('2 [1 2 3 4] of')" + "clear\n", + "2 [1 2 3 4] of" ] }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 171, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "[3 4]\n" + "[3 4]" ] } ], "source": [ - "J('[1 2 3 4] 2 drop')" + "clear\n", + "[1 2 3 4] 2 drop" ] }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 172, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "[2 1]\n" + "[2 1]" ] } ], "source": [ - "J('[1 2 3 4] 2 take') # reverses the order" + "clear\n", + "[1 2 3 4] 2 take" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + " `take` reverses the order." ] }, { @@ -784,19 +873,20 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 173, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "[2 3 1 4]\n" + "[2 3 1 4]" ] } ], "source": [ - "J('[1 2 3 1 4] 1 remove')" + "clear\n", + "[1 2 3 1 4] 1 remove" ] }, { @@ -808,7 +898,7 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 174, "metadata": { "scrolled": true }, @@ -817,12 +907,13 @@ "name": "stdout", "output_type": "stream", "text": [ - "[4 3 2 1]\n" + "[4 3 2 1]" ] } ], "source": [ - "J('[1 2 3 4] reverse')" + "clear\n", + "[1 2 3 4] reverse" ] }, { @@ -834,7 +925,7 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 175, "metadata": { "scrolled": true }, @@ -843,12 +934,13 @@ "name": "stdout", "output_type": "stream", "text": [ - "4\n" + "4" ] } ], "source": [ - "J('[1 1 1 1] size')" + "clear\n", + "[1 1 1 1] size" ] }, { @@ -861,7 +953,7 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 176, "metadata": { "scrolled": true }, @@ -870,12 +962,13 @@ "name": "stdout", "output_type": "stream", "text": [ - "6 5 4 [3 2 1]\n" + "6 5 4 [3 2 1]" ] } ], "source": [ - "J('1 2 3 [4 5 6] swaack')" + "clear\n", + "1 2 3 [4 5 6] swaack" ] }, { @@ -887,7 +980,7 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 180, "metadata": { "scrolled": true }, @@ -896,65 +989,76 @@ "name": "stdout", "output_type": "stream", "text": [ - "9\n" + "9" ] } ], "source": [ - "J('23 9 1 choice')" + "clear\n", + "23 9 true choice" ] }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 181, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "23\n" + "23" ] } ], "source": [ - "J('23 9 0 choice')" + "clear\n", + "23 9 false choice" ] }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 182, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "9" + ] + } + ], + "source": [ + "clear\n", + "[23 9 7] 1 select" + ] + }, + { + "cell_type": "markdown", "metadata": { "scrolled": true }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "9\n" - ] - } - ], "source": [ - "J('[23 9 7] 1 select') # select is basically getitem, should retire it?" + "(`select` is basically `getitem`, should retire it?)" ] }, { "cell_type": "code", - "execution_count": 44, + "execution_count": 183, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "23\n" + "23" ] } ], "source": [ - "J('[23 9 7] 0 select')" + "clear\n", + "[23 9 7] 0 select" ] }, { @@ -966,36 +1070,38 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 184, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "[[6 1] [5 2] [4 3]]\n" + "[[6 1] [5 2] [4 3]]" ] } ], "source": [ - "J('[1 2 3] [6 5 4] zip')" + "clear\n", + "[1 2 3] [6 5 4] zip" ] }, { "cell_type": "code", - "execution_count": 46, + "execution_count": 185, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "[7 7 7]\n" + "[7 7 7]" ] } ], "source": [ - "J('[1 2 3] [6 5 4] zip [sum] map')" + "clear\n", + "[1 2 3] [6 5 4] zip [sum] map" ] }, { @@ -1014,19 +1120,20 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 186, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "32\n" + "32" ] } ], "source": [ - "J('23 9 +')" + "clear\n", + "23 9 +" ] }, { @@ -1038,19 +1145,20 @@ }, { "cell_type": "code", - "execution_count": 48, + "execution_count": 187, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "14\n" + "14" ] } ], "source": [ - "J('23 9 -')" + "clear\n", + "23 9 -" ] }, { @@ -1062,31 +1170,32 @@ }, { "cell_type": "code", - "execution_count": 49, + "execution_count": 188, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "207\n" + "207" ] } ], "source": [ - "J('23 9 *')" + "clear\n", + "23 9 *" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "### `/` `div` `floordiv` `truediv`" + "### `/` `div`" ] }, { "cell_type": "code", - "execution_count": 50, + "execution_count": 189, "metadata": { "scrolled": true }, @@ -1095,17 +1204,18 @@ "name": "stdout", "output_type": "stream", "text": [ - "2.5555555555555554\n" + "2" ] } ], "source": [ - "J('23 9 /')" + "clear\n", + "23 9 /" ] }, { "cell_type": "code", - "execution_count": 51, + "execution_count": 191, "metadata": { "scrolled": false }, @@ -1114,17 +1224,18 @@ "name": "stdout", "output_type": "stream", "text": [ - "-2.5555555555555554\n" + "2" ] } ], "source": [ - "J('23 -9 truediv')" + "clear\n", + "23 9 div" ] }, { "cell_type": "code", - "execution_count": 52, + "execution_count": 193, "metadata": { "scrolled": false }, @@ -1133,69 +1244,13 @@ "name": "stdout", "output_type": "stream", "text": [ - "2.5555555555555554\n" + "-3" ] } ], "source": [ - "J('23 9 div')" - ] - }, - { - "cell_type": "code", - "execution_count": 53, - "metadata": { - "scrolled": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "2\n" - ] - } - ], - "source": [ - "J('23 9 floordiv')" - ] - }, - { - "cell_type": "code", - "execution_count": 54, - "metadata": { - "scrolled": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "-2.5555555555555554\n" - ] - } - ], - "source": [ - "J('23 -9 div')" - ] - }, - { - "cell_type": "code", - "execution_count": 55, - "metadata": { - "scrolled": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "-3\n" - ] - } - ], - "source": [ - "J('23 -9 floordiv')" + "clear\n", + "23 -9 div" ] }, { @@ -1207,19 +1262,20 @@ }, { "cell_type": "code", - "execution_count": 56, + "execution_count": 195, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "5\n" + "5" ] } ], "source": [ - "J('23 9 %')" + "clear\n", + "23 9 %" ] }, { @@ -1231,19 +1287,20 @@ }, { "cell_type": "code", - "execution_count": 57, + "execution_count": 196, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "-23 5\n" + "-23 5" ] } ], "source": [ - "J('23 neg -5 neg')" + "clear\n", + "23 neg -5 neg" ] }, { @@ -1255,60 +1312,45 @@ }, { "cell_type": "code", - "execution_count": 58, + "execution_count": 197, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "1024\n" + "1024" ] } ], "source": [ - "J('2 10 pow')" + "clear\n", + "2 10 pow" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "### `sqr` `sqrt`" + "### `sqr`" ] }, { "cell_type": "code", - "execution_count": 59, + "execution_count": 198, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "529\n" + "529" ] } ], "source": [ - "J('23 sqr')" - ] - }, - { - "cell_type": "code", - "execution_count": 60, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "4.795831523312719\n" - ] - } - ], - "source": [ - "J('23 sqrt')" + "clear\n", + "23 sqr" ] }, { @@ -1320,24 +1362,25 @@ }, { "cell_type": "code", - "execution_count": 61, + "execution_count": 199, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "2\n" + "2" ] } ], "source": [ - "J('1 ++')" + "clear\n", + "1 ++" ] }, { "cell_type": "code", - "execution_count": 62, + "execution_count": 200, "metadata": { "scrolled": true }, @@ -1346,12 +1389,13 @@ "name": "stdout", "output_type": "stream", "text": [ - "0\n" + "0" ] } ], "source": [ - "J('1 --')" + "clear\n", + "1 --" ] }, { @@ -1363,60 +1407,38 @@ }, { "cell_type": "code", - "execution_count": 63, + "execution_count": 201, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "16\n" + "16" ] } ], "source": [ - "J('8 1 <<')" + "clear\n", + "8 1 <<" ] }, { "cell_type": "code", - "execution_count": 64, + "execution_count": 202, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "4\n" + "4" ] } ], "source": [ - "J('8 1 >>')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### `average`" - ] - }, - { - "cell_type": "code", - "execution_count": 65, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "2.75\n" - ] - } - ], - "source": [ - "J('[1 2 3 5] average')" + "clear\n", + "8 1 >>" ] }, { @@ -1428,53 +1450,74 @@ }, { "cell_type": "code", - "execution_count": 66, + "execution_count": 204, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "[4 3 2 1 0]\n" + "[4 3 2 1 0]" ] } ], "source": [ - "J('5 range')" + "clear\n", + "5 range" ] }, { "cell_type": "code", - "execution_count": 67, + "execution_count": 205, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "[0 1 2 3 4 5]\n" + "[0 1 2 3 4 5]" ] } ], "source": [ - "J('5 range_to_zero')" + "clear\n", + "5 range_to_zero" ] }, { "cell_type": "code", - "execution_count": 68, + "execution_count": 206, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "5 4 3 2 1 0\n" + "5 4 3 2 1 0" ] } ], "source": [ - "J('5 down_to_zero')" + "clear\n", + "5 down_to_zero" + ] + }, + { + "cell_type": "code", + "execution_count": 207, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[0 1 2 3 4 5]" + ] + } + ], + "source": [ + "clear\n", + "[5 down_to_zero] run" ] }, { @@ -1486,19 +1529,20 @@ }, { "cell_type": "code", - "execution_count": 69, + "execution_count": 208, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "30\n" + "30" ] } ], "source": [ - "J('[1 2 3 5] product')" + "clear\n", + "[1 2 3 5] product" ] }, { @@ -1510,19 +1554,20 @@ }, { "cell_type": "code", - "execution_count": 70, + "execution_count": 209, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "11\n" + "11" ] } ], "source": [ - "J('[1 2 3 5] sum')" + "clear\n", + "[1 2 3 5] sum" ] }, { @@ -1534,19 +1579,20 @@ }, { "cell_type": "code", - "execution_count": 71, + "execution_count": 210, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "1\n" + "1" ] } ], "source": [ - "J('[1 2 3 5] min')" + "clear\n", + "[1 2 3 5] min" ] }, { @@ -1558,61 +1604,20 @@ }, { "cell_type": "code", - "execution_count": 72, + "execution_count": 211, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "15\n" + "15" ] } ], "source": [ - "J('45 30 gcd')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### `least_fraction`\n", - "If we represent fractions as a quoted pair of integers [q d] this word reduces them to their ... least common factors or whatever." - ] - }, - { - "cell_type": "code", - "execution_count": 73, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[3.0 2.0]\n" - ] - } - ], - "source": [ - "J('[45 30] least_fraction')" - ] - }, - { - "cell_type": "code", - "execution_count": 74, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[23.0 12.0]\n" - ] - } - ], - "source": [ - "J('[23 12] least_fraction')" + "clear\n", + "45 30 gcd" ] }, { @@ -1632,53 +1637,56 @@ }, { "cell_type": "code", - "execution_count": 75, + "execution_count": 216, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "True\n" + "true" ] } ], "source": [ - "J('23 truthy')" + "clear\n", + "23 bool" ] }, { "cell_type": "code", - "execution_count": 76, + "execution_count": 217, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "False\n" + "false" ] } ], "source": [ - "J('[] truthy') # Python semantics." + "clear\n", + "[] bool" ] }, { "cell_type": "code", - "execution_count": 77, + "execution_count": 218, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "False\n" + "false" ] } ], "source": [ - "J('0 truthy')" + "clear\n", + "0 bool" ] }, { @@ -1690,57 +1698,56 @@ }, { "cell_type": "code", - "execution_count": 78, + "execution_count": 219, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - " • 23 ?\n", - " 23 • ?\n", - " 23 • dup truthy\n", - " 23 23 • truthy\n", - "23 True • \n" + "23 true" ] } ], "source": [ - "V('23 ?')" + "clear\n", + "23 ?" ] }, { "cell_type": "code", - "execution_count": 79, + "execution_count": 220, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "[] False\n" + "[] false" ] } ], "source": [ - "J('[] ?')" + "clear\n", + "[] ?" ] }, { "cell_type": "code", - "execution_count": 80, + "execution_count": 221, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "0 False\n" + "0 false" ] } ], "source": [ - "J('0 ?')" + "clear\n", + "0 ?" ] }, { @@ -1752,19 +1759,20 @@ }, { "cell_type": "code", - "execution_count": 81, + "execution_count": 223, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "1\n" + "false" ] } ], "source": [ - "J('23 9 &')" + "clear\n", + "true false &" ] }, { @@ -1776,19 +1784,20 @@ }, { "cell_type": "code", - "execution_count": 82, + "execution_count": 224, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "True\n" + "true" ] } ], "source": [ - "J('23 9 !=')" + "clear\n", + "23 9 !=" ] }, { @@ -1805,47 +1814,6 @@ "- `or`" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### `^` `xor`" - ] - }, - { - "cell_type": "code", - "execution_count": 83, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "0\n" - ] - } - ], - "source": [ - "J('1 1 ^')" - ] - }, - { - "cell_type": "code", - "execution_count": 84, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1\n" - ] - } - ], - "source": [ - "J('1 0 ^')" - ] - }, { "cell_type": "markdown", "metadata": {}, @@ -1862,7 +1830,7 @@ }, { "cell_type": "code", - "execution_count": 85, + "execution_count": 228, "metadata": { "scrolled": true }, @@ -1876,64 +1844,15 @@ "\n", "Accepts a quoted symbol on the top of the stack and prints its docs.\n", "\n", - "---- end (help)\n", + "---- end ( help )\n", "\n", "\n" ] } ], "source": [ - "J('[help] help')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### `parse`" - ] - }, - { - "cell_type": "code", - "execution_count": 86, - "metadata": { - "scrolled": true - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "==== Help on parse ====\n", - "\n", - "Parse the string on the stack to a Joy expression.\n", - "\n", - "---- end (parse)\n", - "\n", - "\n" - ] - } - ], - "source": [ - "J('[parse] help')" - ] - }, - { - "cell_type": "code", - "execution_count": 87, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1 [2 [3] dup]\n" - ] - } - ], - "source": [ - "J('1 \"2 [3] dup\" parse')" + "clear\n", + "[help] help" ] }, { @@ -1946,19 +1865,20 @@ }, { "cell_type": "code", - "execution_count": 88, + "execution_count": 229, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "[5]\n" + "[5]" ] } ], "source": [ - "J('[1 2 dup + +] run')" + "clear\n", + "[1 2 dup + +] run" ] }, { @@ -1977,7 +1897,7 @@ }, { "cell_type": "code", - "execution_count": 89, + "execution_count": 230, "metadata": {}, "outputs": [ { @@ -1987,62 +1907,58 @@ "\n", "==== Help on app1 ====\n", "\n", - "Given a quoted program on TOS and anything as the second stack item run\n", - "the program and replace the two args with the first result of the\n", - "program.\n", - "::\n", + "app1 ≡ grba infrst\n", "\n", - " ... x [Q] . app1\n", - " -----------------------------------\n", - " ... [x ...] [Q] . infra first\n", - "\n", - "---- end (app1)\n", + "---- end ( app1 )\n", "\n", "\n" ] } ], "source": [ - "J('[app1] help')" + "clear\n", + "[app1] help" ] }, { "cell_type": "code", - "execution_count": 90, + "execution_count": 231, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "10 160\n" + "10 160" ] } ], "source": [ - "J('10 4 [sqr *] app1')" + "clear\n", + "10 4 [sqr *] app1" ] }, { "cell_type": "code", - "execution_count": 91, + "execution_count": 232, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "10 90 160\n" + "10 90 160" ] } ], "source": [ - "J('10 3 4 [sqr *] app2')" + "clear\n", + "10 3 4 [sqr *] app2" ] }, { "cell_type": "code", - "execution_count": 92, + "execution_count": 233, "metadata": {}, "outputs": [ { @@ -2052,39 +1968,87 @@ "\n", "==== Help on app2 ====\n", "\n", - "Like app1 with two items.\n", - "::\n", + "app2 ≡ [grba swap grba swap] dip [infrst] cons ii\n", "\n", - " ... y x [Q] . app2\n", - " -----------------------------------\n", - " ... [y ...] [Q] . infra first\n", - " [x ...] [Q] infra first\n", - "\n", - "---- end (app2)\n", + "---- end ( app2 )\n", "\n", "\n" ] } ], "source": [ - "J('[app2] help')" + "clear\n", + "[app2] help" ] }, { "cell_type": "code", - "execution_count": 93, + "execution_count": 234, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "10 40 90 160\n" + "160 90 40" ] } ], "source": [ - "J('10 2 3 4 [sqr *] app3')" + "clear\n", + "10 2 3 4 [sqr *] app3" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "(Wait... is that... backwards?)\n", + "\n", + "It should be `40 90 160` shouldn't it?" + ] + }, + { + "cell_type": "code", + "execution_count": 235, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "40 90 160" + ] + } + ], + "source": [ + "clear\n", + "10 2 3 4 [sqr *] 3 [grabN] codi map reverse disenstacken" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Ah! See? It needs `reverse` in there!" + ] + }, + { + "cell_type": "code", + "execution_count": 236, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "40 90 160 250" + ] + } + ], + "source": [ + "clear\n", + "10 2 3 4 5 [sqr *] 4 [grabN] codi map reverse disenstacken" ] }, { @@ -2105,17 +2069,9 @@ }, { "cell_type": "code", - "execution_count": 94, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[2 1 0]\n" - ] - } - ], + "outputs": [], "source": [ "J('3 [0 <=] [1 - dup] anamorphism')" ] @@ -2129,34 +2085,18 @@ }, { "cell_type": "code", - "execution_count": 95, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "12\n" - ] - } - ], + "outputs": [], "source": [ "J('3 4 1 [+] [*] branch')" ] }, { "cell_type": "code", - "execution_count": 96, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "7\n" - ] - } - ], + "outputs": [], "source": [ "J('3 4 0 [+] [*] branch')" ] @@ -2181,17 +2121,9 @@ }, { "cell_type": "code", - "execution_count": 97, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "10 12 8\n" - ] - } - ], + "outputs": [], "source": [ "J('10 2 [+] [-] cleave')" ] @@ -2205,51 +2137,27 @@ }, { "cell_type": "code", - "execution_count": 98, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1 2 7 5\n" - ] - } - ], + "outputs": [], "source": [ "J('1 2 3 4 5 [+] dip')" ] }, { "cell_type": "code", - "execution_count": 99, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1 5 4 5\n" - ] - } - ], + "outputs": [], "source": [ "J('1 2 3 4 5 [+] dipd')" ] }, { "cell_type": "code", - "execution_count": 100, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "3 3 4 5\n" - ] - } - ], + "outputs": [], "source": [ "J('1 2 3 4 5 [+] dipdd')" ] @@ -2266,23 +2174,9 @@ }, { "cell_type": "code", - "execution_count": 101, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " • 23 [++] dupdip *\n", - " 23 • [++] dupdip *\n", - "23 [++] • dupdip *\n", - " 23 • ++ 23 *\n", - " 24 • 23 *\n", - " 24 23 • *\n", - " 552 • \n" - ] - } - ], + "outputs": [], "source": [ "V('23 [++] dupdip *') # N(N + 1)" ] @@ -2296,88 +2190,18 @@ }, { "cell_type": "code", - "execution_count": 102, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "==== Help on genrec ====\n", - "\n", - "General Recursion Combinator.\n", - "::\n", - "\n", - " [if] [then] [rec1] [rec2] genrec\n", - " ---------------------------------------------------------------------\n", - " [if] [then] [rec1 [[if] [then] [rec1] [rec2] genrec] rec2] ifte\n", - "\n", - "From \"Recursion Theory and Joy\" (j05cmp.html) by Manfred von Thun:\n", - "\"The genrec combinator takes four program parameters in addition to\n", - "whatever data parameters it needs. Fourth from the top is an if-part,\n", - "followed by a then-part. If the if-part yields true, then the then-part\n", - "is executed and the combinator terminates. The other two parameters are\n", - "the rec1-part and the rec2-part. If the if-part yields false, the\n", - "rec1-part is executed. Following that the four program parameters and\n", - "the combinator are again pushed onto the stack bundled up in a quoted\n", - "form. Then the rec2-part is executed, where it will find the bundled\n", - "form. Typically it will then execute the bundled form, either with i or\n", - "with app2, or some other combinator.\"\n", - "\n", - "The way to design one of these is to fix your base case [then] and the\n", - "test [if], and then treat rec1 and rec2 as an else-part \"sandwiching\"\n", - "a quotation of the whole function.\n", - "\n", - "For example, given a (general recursive) function 'F':\n", - "::\n", - "\n", - " F == [I] [T] [R1] [R2] genrec\n", - "\n", - "If the [I] if-part fails you must derive R1 and R2 from:\n", - "::\n", - "\n", - " ... R1 [F] R2\n", - "\n", - "Just set the stack arguments in front, and figure out what R1 and R2\n", - "have to do to apply the quoted [F] in the proper way. In effect, the\n", - "genrec combinator turns into an ifte combinator with a quoted copy of\n", - "the original definition in the else-part:\n", - "::\n", - "\n", - " F == [I] [T] [R1] [R2] genrec\n", - " == [I] [T] [R1 [F] R2] ifte\n", - "\n", - "Primitive recursive functions are those where R2 == i.\n", - "::\n", - "\n", - " P == [I] [T] [R] tailrec\n", - " == [I] [T] [R [P] i] ifte\n", - " == [I] [T] [R P] ifte\n", - "\n", - "---- end (genrec)\n", - "\n", - "\n" - ] - } - ], + "outputs": [], "source": [ "J('[genrec] help')" ] }, { "cell_type": "code", - "execution_count": 103, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "6\n" - ] - } - ], + "outputs": [], "source": [ "J('3 [1 <=] [] [dup --] [i *] genrec')" ] @@ -2391,26 +2215,11 @@ }, { "cell_type": "code", - "execution_count": 104, + "execution_count": null, "metadata": { "scrolled": true }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " • 1 2 3 [+ +] i\n", - " 1 • 2 3 [+ +] i\n", - " 1 2 • 3 [+ +] i\n", - " 1 2 3 • [+ +] i\n", - "1 2 3 [+ +] • i\n", - " 1 2 3 • + +\n", - " 1 5 • +\n", - " 6 • \n" - ] - } - ], + "outputs": [], "source": [ "V('1 2 3 [+ +] i')" ] @@ -2425,34 +2234,18 @@ }, { "cell_type": "code", - "execution_count": 105, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "3\n" - ] - } - ], + "outputs": [], "source": [ "J('1 2 [1] [+] [*] ifte')" ] }, { "cell_type": "code", - "execution_count": 106, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "2\n" - ] - } - ], + "outputs": [], "source": [ "J('1 2 [0] [+] [*] ifte')" ] @@ -2466,27 +2259,9 @@ }, { "cell_type": "code", - "execution_count": 107, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " • 1 2 3 [4 5 6] [* +] infra\n", - " 1 • 2 3 [4 5 6] [* +] infra\n", - " 1 2 • 3 [4 5 6] [* +] infra\n", - " 1 2 3 • [4 5 6] [* +] infra\n", - " 1 2 3 [4 5 6] • [* +] infra\n", - "1 2 3 [4 5 6] [* +] • infra\n", - " 6 5 4 • * + [3 2 1] swaack\n", - " 6 20 • + [3 2 1] swaack\n", - " 26 • [3 2 1] swaack\n", - " 26 [3 2 1] • swaack\n", - " 1 2 3 [26] • \n" - ] - } - ], + "outputs": [], "source": [ "V('1 2 3 [4 5 6] [* +] infra')" ] @@ -2500,69 +2275,18 @@ }, { "cell_type": "code", - "execution_count": 108, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "==== Help on loop ====\n", - "\n", - "Basic loop combinator.\n", - "::\n", - "\n", - " ... True [Q] loop\n", - " -----------------------\n", - " ... Q [Q] loop\n", - "\n", - " ... False [Q] loop\n", - " ------------------------\n", - " ...\n", - "\n", - "---- end (loop)\n", - "\n", - "\n" - ] - } - ], + "outputs": [], "source": [ "J('[loop] help')" ] }, { "cell_type": "code", - "execution_count": 109, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " • 3 dup [1 - dup] loop\n", - " 3 • dup [1 - dup] loop\n", - " 3 3 • [1 - dup] loop\n", - "3 3 [1 - dup] • loop\n", - " 3 • 1 - dup [1 - dup] loop\n", - " 3 1 • - dup [1 - dup] loop\n", - " 2 • dup [1 - dup] loop\n", - " 2 2 • [1 - dup] loop\n", - "2 2 [1 - dup] • loop\n", - " 2 • 1 - dup [1 - dup] loop\n", - " 2 1 • - dup [1 - dup] loop\n", - " 1 • dup [1 - dup] loop\n", - " 1 1 • [1 - dup] loop\n", - "1 1 [1 - dup] • loop\n", - " 1 • 1 - dup [1 - dup] loop\n", - " 1 1 • - dup [1 - dup] loop\n", - " 0 • dup [1 - dup] loop\n", - " 0 0 • [1 - dup] loop\n", - "0 0 [1 - dup] • loop\n", - " 0 • \n" - ] - } - ], + "outputs": [], "source": [ "V('3 dup [1 - dup] loop')" ] @@ -2576,34 +2300,18 @@ }, { "cell_type": "code", - "execution_count": 110, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "10 [10 20 30]\n" - ] - } - ], + "outputs": [], "source": [ "J('10 [1 2 3] [*] map')" ] }, { "cell_type": "code", - "execution_count": 111, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "10 5 [50 2.0 15 5]\n" - ] - } - ], + "outputs": [], "source": [ "J('10 5 [[*][/][+][-]] pam')" ] @@ -2618,68 +2326,36 @@ }, { "cell_type": "code", - "execution_count": 112, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1 2 3 4 5 9\n" - ] - } - ], + "outputs": [], "source": [ "J('1 2 3 4 5 [+] nullary')" ] }, { "cell_type": "code", - "execution_count": 113, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1 2 3 4 9\n" - ] - } - ], + "outputs": [], "source": [ "J('1 2 3 4 5 [+] unary')" ] }, { "cell_type": "code", - "execution_count": 114, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1 2 3 9\n" - ] - } - ], + "outputs": [], "source": [ "J('1 2 3 4 5 [+] binary') # + has arity 2 so this is technically pointless..." ] }, { "cell_type": "code", - "execution_count": 115, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1 2 9\n" - ] - } - ], + "outputs": [], "source": [ "J('1 2 3 4 5 [+] ternary')" ] @@ -2693,77 +2369,20 @@ }, { "cell_type": "code", - "execution_count": 116, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "==== Help on step ====\n", - "\n", - "Run a quoted program on each item in a sequence.\n", - "::\n", - "\n", - " ... [] [Q] . step\n", - " -----------------------\n", - " ... .\n", - "\n", - "\n", - " ... [a] [Q] . step\n", - " ------------------------\n", - " ... a . Q\n", - "\n", - "\n", - " ... [a b c] [Q] . step\n", - " ----------------------------------------\n", - " ... a . Q [b c] [Q] step\n", - "\n", - "The step combinator executes the quotation on each member of the list\n", - "on top of the stack.\n", - "\n", - "---- end (step)\n", - "\n", - "\n" - ] - } - ], + "outputs": [], "source": [ "J('[step] help')" ] }, { "cell_type": "code", - "execution_count": 117, + "execution_count": null, "metadata": { "scrolled": true }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " • 0 [1 2 3] [+] step\n", - " 0 • [1 2 3] [+] step\n", - " 0 [1 2 3] • [+] step\n", - "0 [1 2 3] [+] • step\n", - " 0 1 [+] • i [2 3] [+] step\n", - " 0 1 • + [2 3] [+] step\n", - " 1 • [2 3] [+] step\n", - " 1 [2 3] • [+] step\n", - " 1 [2 3] [+] • step\n", - " 1 2 [+] • i [3] [+] step\n", - " 1 2 • + [3] [+] step\n", - " 3 • [3] [+] step\n", - " 3 [3] • [+] step\n", - " 3 [3] [+] • step\n", - " 3 3 [+] • i\n", - " 3 3 • +\n", - " 6 • \n" - ] - } - ], + "outputs": [], "source": [ "V('0 [1 2 3] [+] step')" ] @@ -2777,28 +2396,9 @@ }, { "cell_type": "code", - "execution_count": 118, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " • 3 2 1 2 [+] times\n", - " 3 • 2 1 2 [+] times\n", - " 3 2 • 1 2 [+] times\n", - " 3 2 1 • 2 [+] times\n", - " 3 2 1 2 • [+] times\n", - "3 2 1 2 [+] • times\n", - " 3 2 1 • + 1 [+] times\n", - " 3 3 • 1 [+] times\n", - " 3 3 1 • [+] times\n", - " 3 3 1 [+] • times\n", - " 3 3 • +\n", - " 6 • \n" - ] - } - ], + "outputs": [], "source": [ "V('3 2 1 2 [+] times')" ] @@ -2812,53 +2412,18 @@ }, { "cell_type": "code", - "execution_count": 119, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "==== Help on b ====\n", - "\n", - "::\n", - "\n", - " b == [i] dip i\n", - "\n", - " ... [P] [Q] b == ... [P] i [Q] i\n", - " ... [P] [Q] b == ... P Q\n", - "\n", - "---- end (b)\n", - "\n", - "\n" - ] - } - ], + "outputs": [], "source": [ "J('[b] help')" ] }, { "cell_type": "code", - "execution_count": 120, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " • 1 2 [3] [4] b\n", - " 1 • 2 [3] [4] b\n", - " 1 2 • [3] [4] b\n", - " 1 2 [3] • [4] b\n", - "1 2 [3] [4] • b\n", - " 1 2 • 3 4\n", - " 1 2 3 • 4\n", - " 1 2 3 4 • \n" - ] - } - ], + "outputs": [], "source": [ "V('1 2 [3] [4] b')" ] @@ -2873,17 +2438,9 @@ }, { "cell_type": "code", - "execution_count": 121, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "3 2 1 0\n" - ] - } - ], + "outputs": [], "source": [ "J('3 [0 >] [dup --] while')" ] @@ -2897,56 +2454,18 @@ }, { "cell_type": "code", - "execution_count": 122, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "==== Help on x ====\n", - "\n", - "::\n", - "\n", - " x == dup i\n", - "\n", - " ... [Q] x = ... [Q] dup i\n", - " ... [Q] x = ... [Q] [Q] i\n", - " ... [Q] x = ... [Q] Q\n", - "\n", - "---- end (x)\n", - "\n", - "\n" - ] - } - ], + "outputs": [], "source": [ "J('[x] help')" ] }, { "cell_type": "code", - "execution_count": 123, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " • 1 [2] [i 3] x\n", - " 1 • [2] [i 3] x\n", - " 1 [2] • [i 3] x\n", - "1 [2] [i 3] • x\n", - "1 [2] [i 3] • i 3\n", - " 1 [2] • i 3 3\n", - " 1 • 2 3 3\n", - " 1 2 • 3 3\n", - " 1 2 3 • 3\n", - " 1 2 3 3 • \n" - ] - } - ], + "outputs": [], "source": [ "V('1 [2] [i 3] x') # Kind of a pointless example." ] @@ -2961,68 +2480,36 @@ }, { "cell_type": "code", - "execution_count": 124, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "False\n" - ] - } - ], + "outputs": [], "source": [ "J('[] void')" ] }, { "cell_type": "code", - "execution_count": 125, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "True\n" - ] - } - ], + "outputs": [], "source": [ "J('[[]] void')" ] }, { "cell_type": "code", - "execution_count": 126, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "True\n" - ] - } - ], + "outputs": [], "source": [ "J('[[][[]]] void')" ] }, { "cell_type": "code", - "execution_count": 127, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "False\n" - ] - } - ], + "outputs": [], "source": [ "J('[[[]][[][]]] void')" ] @@ -3030,21 +2517,14 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 2", - "language": "python", - "name": "python2" + "display_name": "Joypy", + "language": "", + "name": "thun" }, "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.8.3" + "file_extension": ".joy", + "mimetype": "text/plain", + "name": "Joy" } }, "nbformat": 4, diff --git a/docs/notebooks/3._Developing_a_Program.ipynb b/docs/notebooks/3._Developing_a_Program.ipynb index 82dd516..b0c1a22 100644 --- a/docs/notebooks/3._Developing_a_Program.ipynb +++ b/docs/notebooks/3._Developing_a_Program.ipynb @@ -11,29 +11,50 @@ " Find the sum of all the multiples of 3 or 5 below 1000." ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Let's create a predicate that returns `True` if a number is a multiple of 3 or 5 and `False` otherwise.\n", + "\n", + "First we write `multiple-of` which take two numbers and return true if the first is a multiple of the second. We use the `mod` operator, convert the remainder to a Boolean value, then invert it to get our answer:" + ] + }, { "cell_type": "code", "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [] + } + ], "source": [ - "from notebook_preamble import J, V, define" + "[multiple-of mod bool not] inscribe" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Let's create a predicate that returns `True` if a number is a multiple of 3 or 5 and `False` otherwise." + "Next we can use that with `app2` to get both Boolean values (for 3 and 5) and the `or` them. (We use `popd` to get rid of the original number):" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [] + } + ], "source": [ - "define('P [3 % not] dupdip 5 % not or')" + "[P 3 5 [multiple-of] app2 or popd] inscribe" ] }, { @@ -45,24 +66,27 @@ "name": "stdout", "output_type": "stream", "text": [ - " • 80 P\n", - " 80 • P\n", - " 80 • [3 % not] dupdip 5 % not or\n", - "80 [3 % not] • dupdip 5 % not or\n", - " 80 • 3 % not 80 5 % not or\n", - " 80 3 • % not 80 5 % not or\n", - " 2 • not 80 5 % not or\n", - " False • 80 5 % not or\n", - " False 80 • 5 % not or\n", - " False 80 5 • % not or\n", - " False 0 • not or\n", - " False True • or\n", - " True • \n" + "[true false false true true]" ] } ], "source": [ - "V('80 P')" + "[6 7 8 9 10] [P] map" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [] + } + ], + "source": [ + "clear" ] }, { @@ -118,15 +142,6 @@ " PE1.1 == + [+] dupdip" ] }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [], - "source": [ - "define('PE1.1 + [+] dupdip')" - ] - }, { "cell_type": "code", "execution_count": 5, @@ -135,27 +150,33 @@ { "name": "stdout", "output_type": "stream", - "text": [ - " • 0 0 3 PE1.1\n", - " 0 • 0 3 PE1.1\n", - " 0 0 • 3 PE1.1\n", - " 0 0 3 • PE1.1\n", - " 0 0 3 • + [+] dupdip\n", - " 0 3 • [+] dupdip\n", - "0 3 [+] • dupdip\n", - " 0 3 • + 3\n", - " 3 • 3\n", - " 3 3 • \n" - ] + "text": [] } ], "source": [ - "V('0 0 3 PE1.1')" + "[PE1.1 + [+] dupdip] inscribe" ] }, { "cell_type": "code", "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3 3" + ] + } + ], + "source": [ + "0 0 3 PE1.1" + ] + }, + { + "cell_type": "code", + "execution_count": 7, "metadata": { "scrolled": false }, @@ -164,84 +185,14 @@ "name": "stdout", "output_type": "stream", "text": [ - " • 0 0 [3 2 1 3 1 2 3] [PE1.1] step\n", - " 0 • 0 [3 2 1 3 1 2 3] [PE1.1] step\n", - " 0 0 • [3 2 1 3 1 2 3] [PE1.1] step\n", - " 0 0 [3 2 1 3 1 2 3] • [PE1.1] step\n", - "0 0 [3 2 1 3 1 2 3] [PE1.1] • step\n", - " 0 0 3 [PE1.1] • i [2 1 3 1 2 3] [PE1.1] step\n", - " 0 0 3 • PE1.1 [2 1 3 1 2 3] [PE1.1] step\n", - " 0 0 3 • + [+] dupdip [2 1 3 1 2 3] [PE1.1] step\n", - " 0 3 • [+] dupdip [2 1 3 1 2 3] [PE1.1] step\n", - " 0 3 [+] • dupdip [2 1 3 1 2 3] [PE1.1] step\n", - " 0 3 • + 3 [2 1 3 1 2 3] [PE1.1] step\n", - " 3 • 3 [2 1 3 1 2 3] [PE1.1] step\n", - " 3 3 • [2 1 3 1 2 3] [PE1.1] step\n", - " 3 3 [2 1 3 1 2 3] • [PE1.1] step\n", - " 3 3 [2 1 3 1 2 3] [PE1.1] • step\n", - " 3 3 2 [PE1.1] • i [1 3 1 2 3] [PE1.1] step\n", - " 3 3 2 • PE1.1 [1 3 1 2 3] [PE1.1] step\n", - " 3 3 2 • + [+] dupdip [1 3 1 2 3] [PE1.1] step\n", - " 3 5 • [+] dupdip [1 3 1 2 3] [PE1.1] step\n", - " 3 5 [+] • dupdip [1 3 1 2 3] [PE1.1] step\n", - " 3 5 • + 5 [1 3 1 2 3] [PE1.1] step\n", - " 8 • 5 [1 3 1 2 3] [PE1.1] step\n", - " 8 5 • [1 3 1 2 3] [PE1.1] step\n", - " 8 5 [1 3 1 2 3] • [PE1.1] step\n", - " 8 5 [1 3 1 2 3] [PE1.1] • step\n", - " 8 5 1 [PE1.1] • i [3 1 2 3] [PE1.1] step\n", - " 8 5 1 • PE1.1 [3 1 2 3] [PE1.1] step\n", - " 8 5 1 • + [+] dupdip [3 1 2 3] [PE1.1] step\n", - " 8 6 • [+] dupdip [3 1 2 3] [PE1.1] step\n", - " 8 6 [+] • dupdip [3 1 2 3] [PE1.1] step\n", - " 8 6 • + 6 [3 1 2 3] [PE1.1] step\n", - " 14 • 6 [3 1 2 3] [PE1.1] step\n", - " 14 6 • [3 1 2 3] [PE1.1] step\n", - " 14 6 [3 1 2 3] • [PE1.1] step\n", - " 14 6 [3 1 2 3] [PE1.1] • step\n", - " 14 6 3 [PE1.1] • i [1 2 3] [PE1.1] step\n", - " 14 6 3 • PE1.1 [1 2 3] [PE1.1] step\n", - " 14 6 3 • + [+] dupdip [1 2 3] [PE1.1] step\n", - " 14 9 • [+] dupdip [1 2 3] [PE1.1] step\n", - " 14 9 [+] • dupdip [1 2 3] [PE1.1] step\n", - " 14 9 • + 9 [1 2 3] [PE1.1] step\n", - " 23 • 9 [1 2 3] [PE1.1] step\n", - " 23 9 • [1 2 3] [PE1.1] step\n", - " 23 9 [1 2 3] • [PE1.1] step\n", - " 23 9 [1 2 3] [PE1.1] • step\n", - " 23 9 1 [PE1.1] • i [2 3] [PE1.1] step\n", - " 23 9 1 • PE1.1 [2 3] [PE1.1] step\n", - " 23 9 1 • + [+] dupdip [2 3] [PE1.1] step\n", - " 23 10 • [+] dupdip [2 3] [PE1.1] step\n", - " 23 10 [+] • dupdip [2 3] [PE1.1] step\n", - " 23 10 • + 10 [2 3] [PE1.1] step\n", - " 33 • 10 [2 3] [PE1.1] step\n", - " 33 10 • [2 3] [PE1.1] step\n", - " 33 10 [2 3] • [PE1.1] step\n", - " 33 10 [2 3] [PE1.1] • step\n", - " 33 10 2 [PE1.1] • i [3] [PE1.1] step\n", - " 33 10 2 • PE1.1 [3] [PE1.1] step\n", - " 33 10 2 • + [+] dupdip [3] [PE1.1] step\n", - " 33 12 • [+] dupdip [3] [PE1.1] step\n", - " 33 12 [+] • dupdip [3] [PE1.1] step\n", - " 33 12 • + 12 [3] [PE1.1] step\n", - " 45 • 12 [3] [PE1.1] step\n", - " 45 12 • [3] [PE1.1] step\n", - " 45 12 [3] • [PE1.1] step\n", - " 45 12 [3] [PE1.1] • step\n", - " 45 12 3 [PE1.1] • i\n", - " 45 12 3 • PE1.1\n", - " 45 12 3 • + [+] dupdip\n", - " 45 15 • [+] dupdip\n", - " 45 15 [+] • dupdip\n", - " 45 15 • + 15\n", - " 60 • 15\n", - " 60 15 • \n" + "60 15" ] } ], "source": [ - "V('0 0 [3 2 1 3 1 2 3] [PE1.1] step')" + "clear\n", + "\n", + "0 0 [3 2 1 3 1 2 3] [PE1.1] step" ] }, { @@ -251,44 +202,23 @@ "So one `step` through all seven terms brings the counter to 15 and the total to 60." ] }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "66.66666666666667" - ] - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "1000 / 15" - ] - }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { - "data": { - "text/plain": [ - "990" - ] - }, - "execution_count": 8, - "metadata": {}, - "output_type": "execute_result" + "name": "stdout", + "output_type": "stream", + "text": [ + "66" + ] } ], "source": [ - "66 * 15" + "clear\n", + "\n", + "1000 15 div" ] }, { @@ -297,76 +227,43 @@ "metadata": {}, "outputs": [ { - "data": { - "text/plain": [ - "10" - ] - }, - "execution_count": 9, - "metadata": {}, - "output_type": "execute_result" + "name": "stdout", + "output_type": "stream", + "text": [ + "990" + ] } ], "source": [ - "1000 - 990" + "15 *" ] }, { "cell_type": "markdown", "metadata": {}, - "source": [] + "source": [ + "That means we want to run the full list of numbers sixty-six times to get to 990 and then, obviously, the first four numbers 3 2 1 3 to get to 999." + ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "9" - ] - }, - "execution_count": 10, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "999 - 990" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "That means we want to run the full list of numbers sixty-six times to get to 990 and then the first four numbers 3 2 1 3 to get to 999." - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [], - "source": [ - "define('PE1 0 0 66 [[3 2 1 3 1 2 3] [PE1.1] step] times [3 2 1 3] [PE1.1] step pop')" - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "233168\n" + "233168" ] } ], "source": [ - "J('PE1')" + "clear\n", + "\n", + "[PE1 0 0 66 [[3 2 1 3 1 2 3] [PE1.1] step] times [3 2 1 3] [PE1.1] step pop] inscribe\n", + "\n", + "PE1" ] }, { @@ -387,239 +284,59 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 11, "metadata": {}, "outputs": [ { - "data": { - "text/plain": [ - "14811" - ] - }, - "execution_count": 13, - "metadata": {}, - "output_type": "execute_result" + "name": "stdout", + "output_type": "stream", + "text": [] } ], "source": [ - "0b11100111011011" + "clear" ] }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [] + } + ], + "source": [ + "[PE1.2 [3 & PE1.1] dupdip 2 >>] inscribe" + ] + }, + { + "cell_type": "code", + "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "define('PE1.2 [3 & PE1.1] dupdip 2 >>')" + "0 0 14811 PE1.2" ] }, { "cell_type": "code", - "execution_count": 15, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " • 0 0 14811 PE1.2\n", - " 0 • 0 14811 PE1.2\n", - " 0 0 • 14811 PE1.2\n", - " 0 0 14811 • PE1.2\n", - " 0 0 14811 • [3 & PE1.1] dupdip 2 >>\n", - "0 0 14811 [3 & PE1.1] • dupdip 2 >>\n", - " 0 0 14811 • 3 & PE1.1 14811 2 >>\n", - " 0 0 14811 3 • & PE1.1 14811 2 >>\n", - " 0 0 3 • PE1.1 14811 2 >>\n", - " 0 0 3 • + [+] dupdip 14811 2 >>\n", - " 0 3 • [+] dupdip 14811 2 >>\n", - " 0 3 [+] • dupdip 14811 2 >>\n", - " 0 3 • + 3 14811 2 >>\n", - " 3 • 3 14811 2 >>\n", - " 3 3 • 14811 2 >>\n", - " 3 3 14811 • 2 >>\n", - " 3 3 14811 2 • >>\n", - " 3 3 3702 • \n" - ] - } - ], - "source": [ - "V('0 0 14811 PE1.2')" - ] - }, - { - "cell_type": "code", - "execution_count": 16, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " • 3 3 3702 PE1.2\n", - " 3 • 3 3702 PE1.2\n", - " 3 3 • 3702 PE1.2\n", - " 3 3 3702 • PE1.2\n", - " 3 3 3702 • [3 & PE1.1] dupdip 2 >>\n", - "3 3 3702 [3 & PE1.1] • dupdip 2 >>\n", - " 3 3 3702 • 3 & PE1.1 3702 2 >>\n", - " 3 3 3702 3 • & PE1.1 3702 2 >>\n", - " 3 3 2 • PE1.1 3702 2 >>\n", - " 3 3 2 • + [+] dupdip 3702 2 >>\n", - " 3 5 • [+] dupdip 3702 2 >>\n", - " 3 5 [+] • dupdip 3702 2 >>\n", - " 3 5 • + 5 3702 2 >>\n", - " 8 • 5 3702 2 >>\n", - " 8 5 • 3702 2 >>\n", - " 8 5 3702 • 2 >>\n", - " 8 5 3702 2 • >>\n", - " 8 5 925 • \n" - ] - } - ], + "outputs": [], "source": [ "V('3 3 3702 PE1.2')" ] }, { "cell_type": "code", - "execution_count": 17, + "execution_count": null, "metadata": { "scrolled": true }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " • 0 0 14811 7 [PE1.2] times pop\n", - " 0 • 0 14811 7 [PE1.2] times pop\n", - " 0 0 • 14811 7 [PE1.2] times pop\n", - " 0 0 14811 • 7 [PE1.2] times pop\n", - " 0 0 14811 7 • [PE1.2] times pop\n", - " 0 0 14811 7 [PE1.2] • times pop\n", - " 0 0 14811 • PE1.2 6 [PE1.2] times pop\n", - " 0 0 14811 • [3 & PE1.1] dupdip 2 >> 6 [PE1.2] times pop\n", - "0 0 14811 [3 & PE1.1] • dupdip 2 >> 6 [PE1.2] times pop\n", - " 0 0 14811 • 3 & PE1.1 14811 2 >> 6 [PE1.2] times pop\n", - " 0 0 14811 3 • & PE1.1 14811 2 >> 6 [PE1.2] times pop\n", - " 0 0 3 • PE1.1 14811 2 >> 6 [PE1.2] times pop\n", - " 0 0 3 • + [+] dupdip 14811 2 >> 6 [PE1.2] times pop\n", - " 0 3 • [+] dupdip 14811 2 >> 6 [PE1.2] times pop\n", - " 0 3 [+] • dupdip 14811 2 >> 6 [PE1.2] times pop\n", - " 0 3 • + 3 14811 2 >> 6 [PE1.2] times pop\n", - " 3 • 3 14811 2 >> 6 [PE1.2] times pop\n", - " 3 3 • 14811 2 >> 6 [PE1.2] times pop\n", - " 3 3 14811 • 2 >> 6 [PE1.2] times pop\n", - " 3 3 14811 2 • >> 6 [PE1.2] times pop\n", - " 3 3 3702 • 6 [PE1.2] times pop\n", - " 3 3 3702 6 • [PE1.2] times pop\n", - " 3 3 3702 6 [PE1.2] • times pop\n", - " 3 3 3702 • PE1.2 5 [PE1.2] times pop\n", - " 3 3 3702 • [3 & PE1.1] dupdip 2 >> 5 [PE1.2] times pop\n", - " 3 3 3702 [3 & PE1.1] • dupdip 2 >> 5 [PE1.2] times pop\n", - " 3 3 3702 • 3 & PE1.1 3702 2 >> 5 [PE1.2] times pop\n", - " 3 3 3702 3 • & PE1.1 3702 2 >> 5 [PE1.2] times pop\n", - " 3 3 2 • PE1.1 3702 2 >> 5 [PE1.2] times pop\n", - " 3 3 2 • + [+] dupdip 3702 2 >> 5 [PE1.2] times pop\n", - " 3 5 • [+] dupdip 3702 2 >> 5 [PE1.2] times pop\n", - " 3 5 [+] • dupdip 3702 2 >> 5 [PE1.2] times pop\n", - " 3 5 • + 5 3702 2 >> 5 [PE1.2] times pop\n", - " 8 • 5 3702 2 >> 5 [PE1.2] times pop\n", - " 8 5 • 3702 2 >> 5 [PE1.2] times pop\n", - " 8 5 3702 • 2 >> 5 [PE1.2] times pop\n", - " 8 5 3702 2 • >> 5 [PE1.2] times pop\n", - " 8 5 925 • 5 [PE1.2] times pop\n", - " 8 5 925 5 • [PE1.2] times pop\n", - " 8 5 925 5 [PE1.2] • times pop\n", - " 8 5 925 • PE1.2 4 [PE1.2] times pop\n", - " 8 5 925 • [3 & PE1.1] dupdip 2 >> 4 [PE1.2] times pop\n", - " 8 5 925 [3 & PE1.1] • dupdip 2 >> 4 [PE1.2] times pop\n", - " 8 5 925 • 3 & PE1.1 925 2 >> 4 [PE1.2] times pop\n", - " 8 5 925 3 • & PE1.1 925 2 >> 4 [PE1.2] times pop\n", - " 8 5 1 • PE1.1 925 2 >> 4 [PE1.2] times pop\n", - " 8 5 1 • + [+] dupdip 925 2 >> 4 [PE1.2] times pop\n", - " 8 6 • [+] dupdip 925 2 >> 4 [PE1.2] times pop\n", - " 8 6 [+] • dupdip 925 2 >> 4 [PE1.2] times pop\n", - " 8 6 • + 6 925 2 >> 4 [PE1.2] times pop\n", - " 14 • 6 925 2 >> 4 [PE1.2] times pop\n", - " 14 6 • 925 2 >> 4 [PE1.2] times pop\n", - " 14 6 925 • 2 >> 4 [PE1.2] times pop\n", - " 14 6 925 2 • >> 4 [PE1.2] times pop\n", - " 14 6 231 • 4 [PE1.2] times pop\n", - " 14 6 231 4 • [PE1.2] times pop\n", - " 14 6 231 4 [PE1.2] • times pop\n", - " 14 6 231 • PE1.2 3 [PE1.2] times pop\n", - " 14 6 231 • [3 & PE1.1] dupdip 2 >> 3 [PE1.2] times pop\n", - " 14 6 231 [3 & PE1.1] • dupdip 2 >> 3 [PE1.2] times pop\n", - " 14 6 231 • 3 & PE1.1 231 2 >> 3 [PE1.2] times pop\n", - " 14 6 231 3 • & PE1.1 231 2 >> 3 [PE1.2] times pop\n", - " 14 6 3 • PE1.1 231 2 >> 3 [PE1.2] times pop\n", - " 14 6 3 • + [+] dupdip 231 2 >> 3 [PE1.2] times pop\n", - " 14 9 • [+] dupdip 231 2 >> 3 [PE1.2] times pop\n", - " 14 9 [+] • dupdip 231 2 >> 3 [PE1.2] times pop\n", - " 14 9 • + 9 231 2 >> 3 [PE1.2] times pop\n", - " 23 • 9 231 2 >> 3 [PE1.2] times pop\n", - " 23 9 • 231 2 >> 3 [PE1.2] times pop\n", - " 23 9 231 • 2 >> 3 [PE1.2] times pop\n", - " 23 9 231 2 • >> 3 [PE1.2] times pop\n", - " 23 9 57 • 3 [PE1.2] times pop\n", - " 23 9 57 3 • [PE1.2] times pop\n", - " 23 9 57 3 [PE1.2] • times pop\n", - " 23 9 57 • PE1.2 2 [PE1.2] times pop\n", - " 23 9 57 • [3 & PE1.1] dupdip 2 >> 2 [PE1.2] times pop\n", - " 23 9 57 [3 & PE1.1] • dupdip 2 >> 2 [PE1.2] times pop\n", - " 23 9 57 • 3 & PE1.1 57 2 >> 2 [PE1.2] times pop\n", - " 23 9 57 3 • & PE1.1 57 2 >> 2 [PE1.2] times pop\n", - " 23 9 1 • PE1.1 57 2 >> 2 [PE1.2] times pop\n", - " 23 9 1 • + [+] dupdip 57 2 >> 2 [PE1.2] times pop\n", - " 23 10 • [+] dupdip 57 2 >> 2 [PE1.2] times pop\n", - " 23 10 [+] • dupdip 57 2 >> 2 [PE1.2] times pop\n", - " 23 10 • + 10 57 2 >> 2 [PE1.2] times pop\n", - " 33 • 10 57 2 >> 2 [PE1.2] times pop\n", - " 33 10 • 57 2 >> 2 [PE1.2] times pop\n", - " 33 10 57 • 2 >> 2 [PE1.2] times pop\n", - " 33 10 57 2 • >> 2 [PE1.2] times pop\n", - " 33 10 14 • 2 [PE1.2] times pop\n", - " 33 10 14 2 • [PE1.2] times pop\n", - " 33 10 14 2 [PE1.2] • times pop\n", - " 33 10 14 • PE1.2 1 [PE1.2] times pop\n", - " 33 10 14 • [3 & PE1.1] dupdip 2 >> 1 [PE1.2] times pop\n", - " 33 10 14 [3 & PE1.1] • dupdip 2 >> 1 [PE1.2] times pop\n", - " 33 10 14 • 3 & PE1.1 14 2 >> 1 [PE1.2] times pop\n", - " 33 10 14 3 • & PE1.1 14 2 >> 1 [PE1.2] times pop\n", - " 33 10 2 • PE1.1 14 2 >> 1 [PE1.2] times pop\n", - " 33 10 2 • + [+] dupdip 14 2 >> 1 [PE1.2] times pop\n", - " 33 12 • [+] dupdip 14 2 >> 1 [PE1.2] times pop\n", - " 33 12 [+] • dupdip 14 2 >> 1 [PE1.2] times pop\n", - " 33 12 • + 12 14 2 >> 1 [PE1.2] times pop\n", - " 45 • 12 14 2 >> 1 [PE1.2] times pop\n", - " 45 12 • 14 2 >> 1 [PE1.2] times pop\n", - " 45 12 14 • 2 >> 1 [PE1.2] times pop\n", - " 45 12 14 2 • >> 1 [PE1.2] times pop\n", - " 45 12 3 • 1 [PE1.2] times pop\n", - " 45 12 3 1 • [PE1.2] times pop\n", - " 45 12 3 1 [PE1.2] • times pop\n", - " 45 12 3 • PE1.2 pop\n", - " 45 12 3 • [3 & PE1.1] dupdip 2 >> pop\n", - " 45 12 3 [3 & PE1.1] • dupdip 2 >> pop\n", - " 45 12 3 • 3 & PE1.1 3 2 >> pop\n", - " 45 12 3 3 • & PE1.1 3 2 >> pop\n", - " 45 12 3 • PE1.1 3 2 >> pop\n", - " 45 12 3 • + [+] dupdip 3 2 >> pop\n", - " 45 15 • [+] dupdip 3 2 >> pop\n", - " 45 15 [+] • dupdip 3 2 >> pop\n", - " 45 15 • + 15 3 2 >> pop\n", - " 60 • 15 3 2 >> pop\n", - " 60 15 • 3 2 >> pop\n", - " 60 15 3 • 2 >> pop\n", - " 60 15 3 2 • >> pop\n", - " 60 15 0 • pop\n", - " 60 15 • \n" - ] - } - ], + "outputs": [], "source": [ "V('0 0 14811 7 [PE1.2] times pop')" ] @@ -633,7 +350,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -642,19 +359,11 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": null, "metadata": { "scrolled": true }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "233168\n" - ] - } - ], + "outputs": [], "source": [ "J('PE1')" ] @@ -673,7 +382,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -689,7 +398,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -698,19 +407,11 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": null, "metadata": { "scrolled": true }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "233168\n" - ] - } - ], + "outputs": [], "source": [ "J('PE1')" ] @@ -737,7 +438,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -746,19 +447,11 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": null, "metadata": { "scrolled": true }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 [0 swap [dup [pop 14811] [] branch [3 &] dupdip 2 >>] dip rest cons]\n" - ] - } - ], + "outputs": [], "source": [ "J('PE1.terms 21 [x] times')" ] @@ -772,17 +465,9 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "466\n" - ] - } - ], + "outputs": [], "source": [ "J('7 66 * 4 +')" ] @@ -796,19 +481,11 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": null, "metadata": { "scrolled": true }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3 1 2 3 3 2 1 3\n" - ] - } - ], + "outputs": [], "source": [ "J('PE1.terms 466 [x] times pop')" ] @@ -822,19 +499,11 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": null, "metadata": { "scrolled": true }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "999\n" - ] - } - ], + "outputs": [], "source": [ "J('[PE1.terms 466 [x] times pop] run sum')" ] @@ -848,19 +517,11 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": null, "metadata": { "scrolled": true }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "233168\n" - ] - } - ], + "outputs": [], "source": [ "J('0 0 PE1.terms 466 [x [PE1.1] dip] times popop')" ] @@ -875,17 +536,9 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "55\n" - ] - } - ], + "outputs": [], "source": [ "J('[10 9 8 7 6 5 4 3 2 1] sum')" ] @@ -912,7 +565,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -921,24 +574,9 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " • 10 F\n", - " 10 • F\n", - " 10 • dup ++ * 2 floordiv\n", - "10 10 • ++ * 2 floordiv\n", - "10 11 • * 2 floordiv\n", - " 110 • 2 floordiv\n", - "110 2 • floordiv\n", - " 55 • \n" - ] - } - ], + "outputs": [], "source": [ "V('10 F')" ] @@ -963,38 +601,22 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": null, "metadata": { "scrolled": true }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[[978 15] [980 12] [981 10] [984 9] [985 6] [987 5] [990 3]]\n" - ] - } - ], + "outputs": [], "source": [ "J('[3 5 6 9 10 12 15] reverse [978 980 981 984 985 987 990] zip')" ] }, { "cell_type": "code", - "execution_count": 33, + "execution_count": null, "metadata": { "scrolled": true }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[993 992 991 993 991 992 993]\n" - ] - } - ], + "outputs": [], "source": [ "J('[3 5 6 9 10 12 15] reverse [978 980 981 984 985 987 990] zip [sum] map')" ] @@ -1008,19 +630,11 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": null, "metadata": { "scrolled": true }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "6945\n" - ] - } - ], + "outputs": [], "source": [ "J('[ 3 5 6 9 10 12 15] reverse [978 980 981 984 985 987 990] zip [sum] map sum')" ] @@ -1038,17 +652,9 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "233168\n" - ] - } - ], + "outputs": [], "source": [ "J('6945 33 * [993 995 996 999] cons sum')" ] @@ -1090,21 +696,14 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" + "display_name": "Joypy", + "language": "", + "name": "thun" }, "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.7.10" + "file_extension": ".joy", + "mimetype": "text/plain", + "name": "Joy" } }, "nbformat": 4, diff --git a/docs/notebooks/Quadratic.ipynb b/docs/notebooks/Quadratic.ipynb index d98a26f..3a1f9ed 100644 --- a/docs/notebooks/Quadratic.ipynb +++ b/docs/notebooks/Quadratic.ipynb @@ -1,14 +1,5 @@ { "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "from notebook_preamble import J, V, define" - ] - }, { "cell_type": "markdown", "metadata": {}, @@ -110,11 +101,17 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [] + } + ], "source": [ - "define('quadratic == over [[[neg] dupdip sqr 4] dipd * * - sqrt pm] dip 2 * [/] cons app2')" + "[quadratic over [[[neg] dupdip sqr 4] dipd * * - sqrt pm] dip 2 * [/] cons app2] inscribe" ] }, { @@ -126,19 +123,11 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "-0.3819660112501051 -2.618033988749895\n" - ] - } - ], + "outputs": [], "source": [ - "J('3 1 1 quadratic')" + "3 1 1 quadratic" ] }, { @@ -219,21 +208,14 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" + "display_name": "Joypy", + "language": "", + "name": "thun" }, "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.7.10" + "file_extension": ".joy", + "mimetype": "text/plain", + "name": "Joy" } }, "nbformat": 4, diff --git a/docs/notebooks/Zipper.ipynb b/docs/notebooks/Zipper.ipynb index 6514fe3..8dec4f4 100644 --- a/docs/notebooks/Zipper.ipynb +++ b/docs/notebooks/Zipper.ipynb @@ -75,24 +75,9 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " [1 [2 [3 4 25 6] 7] 8] • z-down\n", - " [1 [2 [3 4 25 6] 7] 8] • [] swap uncons swap\n", - "[1 [2 [3 4 25 6] 7] 8] [] • swap uncons swap\n", - "[] [1 [2 [3 4 25 6] 7] 8] • uncons swap\n", - "[] 1 [[2 [3 4 25 6] 7] 8] • swap\n", - "[] [[2 [3 4 25 6] 7] 8] 1 • \n", - "\n", - "[] [[2 [3 4 25 6] 7] 8] 1" - ] - } - ], + "outputs": [], "source": [ "[z-down] trace" ] diff --git a/docs/notebooks/jupyter_kernel/joy_kernel.py b/docs/notebooks/jupyter_kernel/joy_kernel.py index 65d2ce1..fee5a57 100644 --- a/docs/notebooks/jupyter_kernel/joy_kernel.py +++ b/docs/notebooks/jupyter_kernel/joy_kernel.py @@ -1,12 +1,16 @@ import sys from ipykernel.kernelbase import Kernel -from joy.library import default_defs, initialize, inscribe -from joy.joy import run -from joy.utils.stack import stack_to_string -from joy.utils.pretty_print import trace +from simplejoy import ( + default_defs, + initialize, + inscribe, + run, + stack_to_string, + ) +#from joy.utils.pretty_print import trace -inscribe(trace) +#inscribe(trace) class FileFaker: @@ -35,13 +39,13 @@ class JoyKernel(Kernel): implementation = 'Joypy' implementation_version = '1.0' language = 'Joy' - language_version = '0.1' + language_version = '0.5' language_info = { 'name': 'Joy', 'mimetype': 'text/plain', 'file_extension': '.joy', } - banner = "Echo kernel - as useful as a parrot" + banner = "Joy kernel" def __init__(self, *a, **b): self.D = initialize() diff --git a/implementations/Python/simplejoy.py b/implementations/Python/simplejoy.py index 33bc982..9015152 100755 --- a/implementations/Python/simplejoy.py +++ b/implementations/Python/simplejoy.py @@ -115,7 +115,7 @@ anamorphism ≡ [pop []] swap [dip swons] genrec app1 ≡ grba infrst app2 ≡ [grba swap grba swap] dip [infrst] cons ii app3 ≡ 3 appN -appN ≡ [grabN] codi map disenstacken +appN ≡ [grabN] codi map reverse disenstacken at ≡ drop first @@ -307,9 +307,9 @@ def joy(stack, expression, dictionary): ''' expr = push_quote(expression) # We keep a stack-of-stacks, see below. while expr: - print( - f'{stack_to_string(stack)} • {expr_to_string(expr)}' - ) +## print( +## f'{stack_to_string(stack)} • {expr_to_string(expr)}' +## ) term, expr = next_term(expr) if isinstance(term, Symbol): try: @@ -2226,12 +2226,16 @@ def times(stack, expr, dictionary): return stack, expr, dictionary +def default_defs(dictionary): + Def.load_definitions(__doc__.splitlines(), dictionary) + + if __name__ == '__main__': import sys J = interp if '-q' in sys.argv else repl dictionary = initialize() - Def.load_definitions(__doc__.splitlines(), dictionary) + default_defs(dictionary) try: stack = J(dictionary=dictionary) except SystemExit: diff --git a/implementations/defs.txt b/implementations/defs.txt index 570293f..251127e 100644 --- a/implementations/defs.txt +++ b/implementations/defs.txt @@ -11,7 +11,7 @@ anamorphism [pop []] swap [dip swons] genrec app1 grba infrst app2 [grba swap grba swap] dip [infrst] cons ii app3 3 appN -appN [grabN] codi map disenstacken +appN [grabN] codi map reverse disenstacken at drop first average [sum] [size] cleave / b [i] dip i