OSDN Git Service

Update zipper notebook to use Joy kernel.
authorSimon Forman <sforman@hushmail.com>
Thu, 25 Nov 2021 18:55:33 +0000 (10:55 -0800)
committerSimon Forman <sforman@hushmail.com>
Thu, 25 Nov 2021 18:55:33 +0000 (10:55 -0800)
docs/Zipper.ipynb

index a5d3ca4..18b6d5b 100644 (file)
    ]
   },
   {
-   "cell_type": "code",
-   "execution_count": 1,
-   "metadata": {},
-   "outputs": [],
-   "source": [
-    "from notebook_preamble import J, V, define"
-   ]
-  },
-  {
    "cell_type": "markdown",
    "metadata": {},
    "source": [
   },
   {
    "cell_type": "code",
-   "execution_count": 2,
+   "execution_count": 1,
    "metadata": {},
    "outputs": [
     {
      "name": "stdout",
      "output_type": "stream",
      "text": [
-      "[1 [2 [3 4 25 6] 7] 8]\n"
+      "[1 [2 [3 4 25 6] 7] 8]"
      ]
     }
    ],
    "source": [
-    "J('[1 [2 [3 4 25 6] 7] 8]')"
+    "[1 [2 [3 4 25 6] 7] 8]"
    ]
   },
   {
   },
   {
    "cell_type": "code",
-   "execution_count": 3,
-   "metadata": {},
-   "outputs": [],
-   "source": [
-    "define('z-down == [] swap uncons swap')\n",
-    "define('z-up == swons swap shunt')\n",
-    "define('z-right == [swons] cons dip uncons swap')\n",
-    "define('z-left == swons [uncons swap] dip swap')"
-   ]
-  },
-  {
-   "cell_type": "code",
-   "execution_count": 4,
+   "execution_count": 2,
    "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] . 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"
+      "[1 [2 [3 4 25 6] 7] 8]"
      ]
     }
    ],
    "source": [
-    "V('[1 [2 [3 4 25 6] 7] 8] z-down')"
+    "[z-down [] swap uncons swap] inscribe\n",
+    "[z-up swons swap shunt] inscribe\n",
+    "[z-right [swons] cons dip uncons swap] inscribe\n",
+    "[z-left swons [uncons swap] dip swap] inscribe"
    ]
   },
   {
    "cell_type": "code",
-   "execution_count": 5,
+   "execution_count": 3,
    "metadata": {},
    "outputs": [
     {
      "name": "stdout",
      "output_type": "stream",
      "text": [
-      "                                  . [] [[2 [3 4 25 6] 7] 8] 1 z-right\n",
-      "                               [] . [[2 [3 4 25 6] 7] 8] 1 z-right\n",
-      "          [] [[2 [3 4 25 6] 7] 8] . 1 z-right\n",
-      "        [] [[2 [3 4 25 6] 7] 8] 1 . z-right\n",
-      "        [] [[2 [3 4 25 6] 7] 8] 1 . [swons] cons dip uncons swap\n",
-      "[] [[2 [3 4 25 6] 7] 8] 1 [swons] . cons dip uncons swap\n",
-      "[] [[2 [3 4 25 6] 7] 8] [1 swons] . dip uncons swap\n",
-      "                               [] . 1 swons [[2 [3 4 25 6] 7] 8] uncons swap\n",
-      "                             [] 1 . swons [[2 [3 4 25 6] 7] 8] uncons swap\n",
-      "                             [] 1 . swap cons [[2 [3 4 25 6] 7] 8] uncons swap\n",
-      "                             1 [] . cons [[2 [3 4 25 6] 7] 8] uncons swap\n",
-      "                              [1] . [[2 [3 4 25 6] 7] 8] uncons swap\n",
-      "         [1] [[2 [3 4 25 6] 7] 8] . uncons swap\n",
-      "         [1] [2 [3 4 25 6] 7] [8] . swap\n",
-      "         [1] [8] [2 [3 4 25 6] 7] . \n"
+      "   [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"
      ]
     }
    ],
    "source": [
-    "V('[] [[2 [3 4 25 6] 7] 8] 1 z-right')"
+    "[z-down] trace"
    ]
   },
   {
    "cell_type": "code",
-   "execution_count": 6,
+   "execution_count": 4,
    "metadata": {},
    "outputs": [
     {
      "name": "stdout",
      "output_type": "stream",
      "text": [
-      "[1] [8] [] [[3 4 25 6] 7] 2\n"
+      "        [] [[2 [3 4 25 6] 7] 8] 1 • z-right\n",
+      "        [] [[2 [3 4 25 6] 7] 8] 1 • [swons] cons dip uncons swap\n",
+      "[] [[2 [3 4 25 6] 7] 8] 1 [swons] • cons dip uncons swap\n",
+      "[] [[2 [3 4 25 6] 7] 8] [1 swons] • dip uncons swap\n",
+      "                               [] • 1 swons [[2 [3 4 25 6] 7] 8] uncons swap\n",
+      "                             [] 1 • swons [[2 [3 4 25 6] 7] 8] uncons swap\n",
+      "                              [1] • [[2 [3 4 25 6] 7] 8] uncons swap\n",
+      "         [1] [[2 [3 4 25 6] 7] 8] • uncons swap\n",
+      "         [1] [2 [3 4 25 6] 7] [8] • swap\n",
+      "         [1] [8] [2 [3 4 25 6] 7] • \n",
+      "\n",
+      "[1] [8] [2 [3 4 25 6] 7]"
      ]
     }
    ],
    "source": [
-    "J('[1] [8] [2 [3 4 25 6] 7] z-down')"
+    "[z-right] trace"
    ]
   },
   {
    "cell_type": "code",
-   "execution_count": 7,
+   "execution_count": 5,
    "metadata": {},
    "outputs": [
     {
      "name": "stdout",
      "output_type": "stream",
      "text": [
-      "[1] [8] [2] [7] [3 4 25 6]\n"
+      "[1] [8] [] [[3 4 25 6] 7] 2"
      ]
     }
    ],
    "source": [
-    "J('[1] [8] [] [[3 4 25 6] 7] 2 z-right')"
+    "z-down"
    ]
   },
   {
    "cell_type": "code",
-   "execution_count": 8,
+   "execution_count": 6,
    "metadata": {},
    "outputs": [
     {
      "name": "stdout",
      "output_type": "stream",
      "text": [
-      "[1] [8] [2] [7] [] [4 25 6] 3\n"
+      "[1] [8] [2] [7] [3 4 25 6]"
      ]
     }
    ],
    "source": [
-    "J('[1] [8] [2] [7] [3 4 25 6] z-down')"
+    "z-right"
    ]
   },
   {
    "cell_type": "code",
-   "execution_count": 9,
+   "execution_count": 7,
    "metadata": {},
    "outputs": [
     {
      "name": "stdout",
      "output_type": "stream",
      "text": [
-      "[1] [8] [2] [7] [3] [25 6] 4\n"
+      "[1] [8] [2] [7] [] [4 25 6] 3"
      ]
     }
    ],
    "source": [
-    "J('[1] [8] [2] [7] [] [4 25 6] 3 z-right')"
+    "z-down"
    ]
   },
   {
    "cell_type": "code",
-   "execution_count": 10,
+   "execution_count": 8,
    "metadata": {},
    "outputs": [
     {
      "name": "stdout",
      "output_type": "stream",
      "text": [
-      "[1] [8] [2] [7] [4 3] [6] 25\n"
+      "[1] [8] [2] [7] [3] [25 6] 4"
      ]
     }
    ],
    "source": [
-    "J('[1] [8] [2] [7] [3] [25 6] 4 z-right')"
+    "z-right"
    ]
   },
   {
    "cell_type": "code",
-   "execution_count": 11,
+   "execution_count": 9,
    "metadata": {},
    "outputs": [
     {
      "name": "stdout",
      "output_type": "stream",
      "text": [
-      "[1] [8] [2] [7] [4 3] [6] 625\n"
+      "[1] [8] [2] [7] [4 3] [6] 25"
      ]
     }
    ],
    "source": [
-    "J('[1] [8] [2] [7] [4 3] [6] 25 sqr')"
+    "z-right"
    ]
   },
   {
    "cell_type": "code",
-   "execution_count": 12,
+   "execution_count": null,
    "metadata": {},
-   "outputs": [
-    {
-     "name": "stdout",
-     "output_type": "stream",
-     "text": [
-      "                              . [1] [8] [2] [7] [4 3] [6] 625 z-up\n",
-      "                          [1] . [8] [2] [7] [4 3] [6] 625 z-up\n",
-      "                      [1] [8] . [2] [7] [4 3] [6] 625 z-up\n",
-      "                  [1] [8] [2] . [7] [4 3] [6] 625 z-up\n",
-      "              [1] [8] [2] [7] . [4 3] [6] 625 z-up\n",
-      "        [1] [8] [2] [7] [4 3] . [6] 625 z-up\n",
-      "    [1] [8] [2] [7] [4 3] [6] . 625 z-up\n",
-      "[1] [8] [2] [7] [4 3] [6] 625 . z-up\n",
-      "[1] [8] [2] [7] [4 3] [6] 625 . swons swap shunt\n",
-      "[1] [8] [2] [7] [4 3] [6] 625 . swap cons swap shunt\n",
-      "[1] [8] [2] [7] [4 3] 625 [6] . cons swap shunt\n",
-      "[1] [8] [2] [7] [4 3] [625 6] . swap shunt\n",
-      "[1] [8] [2] [7] [625 6] [4 3] . shunt\n",
-      "  [1] [8] [2] [7] [3 4 625 6] . \n"
-     ]
-    }
-   ],
+   "outputs": [],
    "source": [
-    "V('[1] [8] [2] [7] [4 3] [6] 625 z-up')"
+    "sqr"
    ]
   },
   {
    "cell_type": "code",
-   "execution_count": 13,
+   "execution_count": 11,
    "metadata": {},
    "outputs": [
     {
      "name": "stdout",
      "output_type": "stream",
      "text": [
-      "[1] [8] [2 [3 4 625 6] 7]\n"
+      "!= % & * + ++ - -- / // /floor < << <= <> = > >= >> ^ _Tree_add_Ee _Tree_delete_R0 _Tree_delete_clear_stuff _Tree_get_E abs add and app1 app2 app3 at b bool branch ccons choice clear cmp concat cond cons dip dipd dipdd disenstacken div divmod drop dup dupd dupdd dupdip eq first first_two floor floordiv fourth gcd2 ge genrec getitem gt help i id infra inscribe le loop lshift lt map max min mod modulus mul ne neg not or over parse pick pm pop popd popdd popop popopd popopdd pow pred primrec rem remainder remove rest reverse roll< roll> rolldown rollup round rrest rshift second select sharing shunt sort sqrt stack step stuncons stununcons sub succ sum swaack swap swons take third times trace truthy tuck uncons unique unit unswons void warranty words x xor z-down z-left z-right z-up zip •\n",
+      "\n",
+      "[1] [8] [2] [7] [4 3] [6] 25"
      ]
     }
    ],
    "source": [
-    "J('[1] [8] [2] [7] [3 4 625 6] z-up')"
+    "words"
    ]
   },
   {
    "cell_type": "code",
-   "execution_count": 14,
+   "execution_count": null,
    "metadata": {},
-   "outputs": [
-    {
-     "name": "stdout",
-     "output_type": "stream",
-     "text": [
-      "[1 [2 [3 4 625 6] 7] 8]\n"
-     ]
-    }
-   ],
+   "outputs": [],
+   "source": [
+    "[z-up] trace"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "z-up"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
    "source": [
-    "J('[1] [8] [2 [3 4 625 6] 7] z-up')"
+    "z-up"
    ]
   },
   {
   },
   {
    "cell_type": "code",
-   "execution_count": 15,
+   "execution_count": null,
    "metadata": {},
-   "outputs": [
-    {
-     "name": "stdout",
-     "output_type": "stream",
-     "text": [
-      "                                                                . [1 [2 [3 4 25 6] 7] 8] [[[[[[sqr] dipd] infra] dip] infra] dip] infra\n",
-      "                                         [1 [2 [3 4 25 6] 7] 8] . [[[[[[sqr] dipd] infra] dip] infra] dip] infra\n",
-      "[1 [2 [3 4 25 6] 7] 8] [[[[[[sqr] dipd] infra] dip] infra] dip] . infra\n",
-      "                                           8 [2 [3 4 25 6] 7] 1 . [[[[[sqr] dipd] infra] dip] infra] dip [] swaack\n",
-      "        8 [2 [3 4 25 6] 7] 1 [[[[[sqr] dipd] infra] dip] infra] . dip [] swaack\n",
-      "                                             8 [2 [3 4 25 6] 7] . [[[[sqr] dipd] infra] dip] infra 1 [] swaack\n",
-      "                  8 [2 [3 4 25 6] 7] [[[[sqr] dipd] infra] dip] . infra 1 [] swaack\n",
-      "                                                 7 [3 4 25 6] 2 . [[[sqr] dipd] infra] dip [8] swaack 1 [] swaack\n",
-      "                            7 [3 4 25 6] 2 [[[sqr] dipd] infra] . dip [8] swaack 1 [] swaack\n",
-      "                                                   7 [3 4 25 6] . [[sqr] dipd] infra 2 [8] swaack 1 [] swaack\n",
-      "                                      7 [3 4 25 6] [[sqr] dipd] . infra 2 [8] swaack 1 [] swaack\n",
-      "                                                       6 25 4 3 . [sqr] dipd [7] swaack 2 [8] swaack 1 [] swaack\n",
-      "                                                 6 25 4 3 [sqr] . dipd [7] swaack 2 [8] swaack 1 [] swaack\n",
-      "                                                           6 25 . sqr 4 3 [7] swaack 2 [8] swaack 1 [] swaack\n",
-      "                                                           6 25 . dup mul 4 3 [7] swaack 2 [8] swaack 1 [] swaack\n",
-      "                                                        6 25 25 . mul 4 3 [7] swaack 2 [8] swaack 1 [] swaack\n",
-      "                                                          6 625 . 4 3 [7] swaack 2 [8] swaack 1 [] swaack\n",
-      "                                                        6 625 4 . 3 [7] swaack 2 [8] swaack 1 [] swaack\n",
-      "                                                      6 625 4 3 . [7] swaack 2 [8] swaack 1 [] swaack\n",
-      "                                                  6 625 4 3 [7] . swaack 2 [8] swaack 1 [] swaack\n",
-      "                                                  7 [3 4 625 6] . 2 [8] swaack 1 [] swaack\n",
-      "                                                7 [3 4 625 6] 2 . [8] swaack 1 [] swaack\n",
-      "                                            7 [3 4 625 6] 2 [8] . swaack 1 [] swaack\n",
-      "                                            8 [2 [3 4 625 6] 7] . 1 [] swaack\n",
-      "                                          8 [2 [3 4 625 6] 7] 1 . [] swaack\n",
-      "                                       8 [2 [3 4 625 6] 7] 1 [] . swaack\n",
-      "                                        [1 [2 [3 4 625 6] 7] 8] . \n"
-     ]
-    }
-   ],
+   "outputs": [],
    "source": [
-    "V('[1 [2 [3 4 25 6] 7] 8] [[[[[[sqr] dipd] infra] dip] infra] dip] infra')"
+    "[[[[[[sqr] dipd] infra] dip] infra] dip] [infra] trace"
    ]
   },
   {
   },
   {
    "cell_type": "code",
-   "execution_count": 16,
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "clear"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
    "metadata": {},
    "outputs": [],
    "source": [
-    "define('Z == [[] cons cons] step i')"
+    "[Z [[] ccons] step i] inscribe"
    ]
   },
   {
   },
   {
    "cell_type": "code",
-   "execution_count": 17,
+   "execution_count": null,
    "metadata": {},
-   "outputs": [
-    {
-     "name": "stdout",
-     "output_type": "stream",
-     "text": [
-      "                             . 1 [2 3 4] Z\n",
-      "                           1 . [2 3 4] Z\n",
-      "                   1 [2 3 4] . Z\n",
-      "                   1 [2 3 4] . [[] cons cons] step i\n",
-      "    1 [2 3 4] [[] cons cons] . step i\n",
-      "          1 2 [[] cons cons] . i [3 4] [[] cons cons] step i\n",
-      "                         1 2 . [] cons cons [3 4] [[] cons cons] step i\n",
-      "                      1 2 [] . cons cons [3 4] [[] cons cons] step i\n",
-      "                       1 [2] . cons [3 4] [[] cons cons] step i\n",
-      "                       [1 2] . [3 4] [[] cons cons] step i\n",
-      "                 [1 2] [3 4] . [[] cons cons] step i\n",
-      "  [1 2] [3 4] [[] cons cons] . step i\n",
-      "      [1 2] 3 [[] cons cons] . i [4] [[] cons cons] step i\n",
-      "                     [1 2] 3 . [] cons cons [4] [[] cons cons] step i\n",
-      "                  [1 2] 3 [] . cons cons [4] [[] cons cons] step i\n",
-      "                   [1 2] [3] . cons [4] [[] cons cons] step i\n",
-      "                   [[1 2] 3] . [4] [[] cons cons] step i\n",
-      "               [[1 2] 3] [4] . [[] cons cons] step i\n",
-      "[[1 2] 3] [4] [[] cons cons] . step i\n",
-      "  [[1 2] 3] 4 [[] cons cons] . i i\n",
-      "                 [[1 2] 3] 4 . [] cons cons i\n",
-      "              [[1 2] 3] 4 [] . cons cons i\n",
-      "               [[1 2] 3] [4] . cons i\n",
-      "               [[[1 2] 3] 4] . i\n",
-      "                             . [[1 2] 3] 4\n",
-      "                   [[1 2] 3] . 4\n",
-      "                 [[1 2] 3] 4 . \n"
-     ]
-    }
-   ],
+   "outputs": [],
+   "source": [
+    "1 [2 3 4] [Z] trace"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
    "source": [
-    "V('1 [2 3 4] Z')"
+    "clear"
    ]
   },
   {
    "cell_type": "markdown",
    "metadata": {},
    "source": [
-    "And here it is doing the main thing."
+    "And here it is doing the thing."
    ]
   },
   {
    "cell_type": "code",
-   "execution_count": 18,
+   "execution_count": null,
    "metadata": {},
-   "outputs": [
-    {
-     "name": "stdout",
-     "output_type": "stream",
-     "text": [
-      "[1 [2 [3 4 625 6] 7] 8]\n"
-     ]
-    }
-   ],
+   "outputs": [],
    "source": [
-    "J('[1 [2 [3 4 25 6] 7] 8] [sqr] [dip dip infra dip infra dip infra] Z')"
+    "[1 [2 [3 4 25 6] 7] 8] [sqr] [dip dip infra dip infra dip infra] Z"
    ]
   },
   {
     "    [ n [ n [ n n x ...\n",
     "    i d i d i d d Bingo!"
    ]
-  },
-  {
-   "cell_type": "code",
-   "execution_count": 19,
-   "metadata": {},
-   "outputs": [],
-   "source": []
   }
  ],
  "metadata": {