Bunch of minor docs edits.

This commit is contained in:
Simon Forman 2018-06-06 12:47:11 -07:00
parent 3fb1e0ea81
commit 09276fdc13
16 changed files with 23 additions and 12439 deletions

View File

@ -27,3 +27,6 @@ docs:
cd ./docs && python -m nbconvert --to html *.ipynb
cd ./docs && python -m nbconvert --to markdown *.ipynb
cd ./docs && python -m nbconvert --to rst *.ipynb
%.md : %.ipynb ;

View File

@ -5,6 +5,7 @@
"metadata": {},
"source": [
"# Joypy\n",
"\n",
"## Joy in Python\n",
"\n",
"This implementation is meant as a tool for exploring the programming model and method of Joy. Python seems like a great implementation language for Joy for several reasons.\n",

File diff suppressed because it is too large Load Diff

View File

@ -1,149 +0,0 @@
### Preamble
```python
from notebook_preamble import D, J, V
```
### A long trace
```python
V('[23 18] average')
```
. [23 18] average
[23 18] . average
[23 18] . [sum 1.0 *] [size] cleave /
[23 18] [sum 1.0 *] . [size] cleave /
[23 18] [sum 1.0 *] [size] . cleave /
[23 18] [sum 1.0 *] [size] . [i] app2 [popd] dip /
[23 18] [sum 1.0 *] [size] [i] . app2 [popd] dip /
[23 18] [[sum 1.0 *] [23 18]] [i] . infra first [[size] [23 18]] [i] infra first [popd] dip /
[23 18] [sum 1.0 *] . i [[23 18]] swaack first [[size] [23 18]] [i] infra first [popd] dip /
[23 18] . sum 1.0 * [[23 18]] swaack first [[size] [23 18]] [i] infra first [popd] dip /
41 . 1.0 * [[23 18]] swaack first [[size] [23 18]] [i] infra first [popd] dip /
41 1.0 . * [[23 18]] swaack first [[size] [23 18]] [i] infra first [popd] dip /
41.0 . [[23 18]] swaack first [[size] [23 18]] [i] infra first [popd] dip /
41.0 [[23 18]] . swaack first [[size] [23 18]] [i] infra first [popd] dip /
[23 18] [41.0] . first [[size] [23 18]] [i] infra first [popd] dip /
[23 18] 41.0 . [[size] [23 18]] [i] infra first [popd] dip /
[23 18] 41.0 [[size] [23 18]] . [i] infra first [popd] dip /
[23 18] 41.0 [[size] [23 18]] [i] . infra first [popd] dip /
[23 18] [size] . i [41.0 [23 18]] swaack first [popd] dip /
[23 18] . size [41.0 [23 18]] swaack first [popd] dip /
[23 18] . 0 swap [pop ++] step [41.0 [23 18]] swaack first [popd] dip /
[23 18] 0 . swap [pop ++] step [41.0 [23 18]] swaack first [popd] dip /
0 [23 18] . [pop ++] step [41.0 [23 18]] swaack first [popd] dip /
0 [23 18] [pop ++] . step [41.0 [23 18]] swaack first [popd] dip /
0 23 [pop ++] . i [18] [pop ++] step [41.0 [23 18]] swaack first [popd] dip /
0 23 . pop ++ [18] [pop ++] step [41.0 [23 18]] swaack first [popd] dip /
0 . ++ [18] [pop ++] step [41.0 [23 18]] swaack first [popd] dip /
1 . [18] [pop ++] step [41.0 [23 18]] swaack first [popd] dip /
1 [18] . [pop ++] step [41.0 [23 18]] swaack first [popd] dip /
1 [18] [pop ++] . step [41.0 [23 18]] swaack first [popd] dip /
1 18 [pop ++] . i [41.0 [23 18]] swaack first [popd] dip /
1 18 . pop ++ [41.0 [23 18]] swaack first [popd] dip /
1 . ++ [41.0 [23 18]] swaack first [popd] dip /
2 . [41.0 [23 18]] swaack first [popd] dip /
2 [41.0 [23 18]] . swaack first [popd] dip /
[23 18] 41.0 [2] . first [popd] dip /
[23 18] 41.0 2 . [popd] dip /
[23 18] 41.0 2 [popd] . dip /
[23 18] 41.0 . popd 2 /
41.0 . 2 /
41.0 2 . /
20.5 .
### Replacing `sum` and `size` with "compiled" versions.
Both `sum` and `size` are [catamorphisms](https://en.wikipedia.org/wiki/Catamorphism), they each convert a sequence to a single value.
```python
J('[sum] help')
```
Given a quoted sequence of numbers return the sum.
sum == 0 swap [+] step
```python
J('[size] help')
```
0 swap [pop ++] step
We can use "compiled" versions (they're not really compiled in this case, they're hand-written in Python) to speed up evaluation and make the trace more readable. The `sum` function is already in the library. It gets shadowed by the definition version above during `initialize()`.
```python
from joy.library import SimpleFunctionWrapper, primitives
from joy.utils.stack import iter_stack
@SimpleFunctionWrapper
def size(stack):
'''Return the size of the sequence on the stack.'''
sequence, stack = stack
n = 0
for _ in iter_stack(sequence):
n += 1
return n, stack
sum_ = next(p for p in primitives if p.name == 'sum')
```
Now we replace them old versions in the dictionary with the new versions and re-evaluate the expression.
```python
old_sum, D['sum'] = D['sum'], sum_
old_size, D['size'] = D['size'], size
```
You can see that `size` and `sum` now execute in a single step.
```python
V('[23 18] average')
```
. [23 18] average
[23 18] . average
[23 18] . [sum 1.0 *] [size] cleave /
[23 18] [sum 1.0 *] . [size] cleave /
[23 18] [sum 1.0 *] [size] . cleave /
[23 18] [sum 1.0 *] [size] . [i] app2 [popd] dip /
[23 18] [sum 1.0 *] [size] [i] . app2 [popd] dip /
[23 18] [[sum 1.0 *] [23 18]] [i] . infra first [[size] [23 18]] [i] infra first [popd] dip /
[23 18] [sum 1.0 *] . i [[23 18]] swaack first [[size] [23 18]] [i] infra first [popd] dip /
[23 18] . sum 1.0 * [[23 18]] swaack first [[size] [23 18]] [i] infra first [popd] dip /
41 . 1.0 * [[23 18]] swaack first [[size] [23 18]] [i] infra first [popd] dip /
41 1.0 . * [[23 18]] swaack first [[size] [23 18]] [i] infra first [popd] dip /
41.0 . [[23 18]] swaack first [[size] [23 18]] [i] infra first [popd] dip /
41.0 [[23 18]] . swaack first [[size] [23 18]] [i] infra first [popd] dip /
[23 18] [41.0] . first [[size] [23 18]] [i] infra first [popd] dip /
[23 18] 41.0 . [[size] [23 18]] [i] infra first [popd] dip /
[23 18] 41.0 [[size] [23 18]] . [i] infra first [popd] dip /
[23 18] 41.0 [[size] [23 18]] [i] . infra first [popd] dip /
[23 18] [size] . i [41.0 [23 18]] swaack first [popd] dip /
[23 18] . size [41.0 [23 18]] swaack first [popd] dip /
2 . [41.0 [23 18]] swaack first [popd] dip /
2 [41.0 [23 18]] . swaack first [popd] dip /
[23 18] 41.0 [2] . first [popd] dip /
[23 18] 41.0 2 . [popd] dip /
[23 18] 41.0 2 [popd] . dip /
[23 18] 41.0 . popd 2 /
41.0 . 2 /
41.0 2 . /
20.5 .

View File

@ -1,164 +0,0 @@
Preamble
~~~~~~~~
.. code:: ipython2
from notebook_preamble import D, J, V
A long trace
~~~~~~~~~~~~
.. code:: ipython2
V('[23 18] average')
.. parsed-literal::
. [23 18] average
[23 18] . average
[23 18] . [sum 1.0 *] [size] cleave /
[23 18] [sum 1.0 *] . [size] cleave /
[23 18] [sum 1.0 *] [size] . cleave /
[23 18] [sum 1.0 *] [size] . [i] app2 [popd] dip /
[23 18] [sum 1.0 *] [size] [i] . app2 [popd] dip /
[23 18] [[sum 1.0 *] [23 18]] [i] . infra first [[size] [23 18]] [i] infra first [popd] dip /
[23 18] [sum 1.0 *] . i [[23 18]] swaack first [[size] [23 18]] [i] infra first [popd] dip /
[23 18] . sum 1.0 * [[23 18]] swaack first [[size] [23 18]] [i] infra first [popd] dip /
41 . 1.0 * [[23 18]] swaack first [[size] [23 18]] [i] infra first [popd] dip /
41 1.0 . * [[23 18]] swaack first [[size] [23 18]] [i] infra first [popd] dip /
41.0 . [[23 18]] swaack first [[size] [23 18]] [i] infra first [popd] dip /
41.0 [[23 18]] . swaack first [[size] [23 18]] [i] infra first [popd] dip /
[23 18] [41.0] . first [[size] [23 18]] [i] infra first [popd] dip /
[23 18] 41.0 . [[size] [23 18]] [i] infra first [popd] dip /
[23 18] 41.0 [[size] [23 18]] . [i] infra first [popd] dip /
[23 18] 41.0 [[size] [23 18]] [i] . infra first [popd] dip /
[23 18] [size] . i [41.0 [23 18]] swaack first [popd] dip /
[23 18] . size [41.0 [23 18]] swaack first [popd] dip /
[23 18] . 0 swap [pop ++] step [41.0 [23 18]] swaack first [popd] dip /
[23 18] 0 . swap [pop ++] step [41.0 [23 18]] swaack first [popd] dip /
0 [23 18] . [pop ++] step [41.0 [23 18]] swaack first [popd] dip /
0 [23 18] [pop ++] . step [41.0 [23 18]] swaack first [popd] dip /
0 23 [pop ++] . i [18] [pop ++] step [41.0 [23 18]] swaack first [popd] dip /
0 23 . pop ++ [18] [pop ++] step [41.0 [23 18]] swaack first [popd] dip /
0 . ++ [18] [pop ++] step [41.0 [23 18]] swaack first [popd] dip /
1 . [18] [pop ++] step [41.0 [23 18]] swaack first [popd] dip /
1 [18] . [pop ++] step [41.0 [23 18]] swaack first [popd] dip /
1 [18] [pop ++] . step [41.0 [23 18]] swaack first [popd] dip /
1 18 [pop ++] . i [41.0 [23 18]] swaack first [popd] dip /
1 18 . pop ++ [41.0 [23 18]] swaack first [popd] dip /
1 . ++ [41.0 [23 18]] swaack first [popd] dip /
2 . [41.0 [23 18]] swaack first [popd] dip /
2 [41.0 [23 18]] . swaack first [popd] dip /
[23 18] 41.0 [2] . first [popd] dip /
[23 18] 41.0 2 . [popd] dip /
[23 18] 41.0 2 [popd] . dip /
[23 18] 41.0 . popd 2 /
41.0 . 2 /
41.0 2 . /
20.5 .
Replacing ``sum`` and ``size`` with "compiled" versions.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Both ``sum`` and ``size`` are
`catamorphisms <https://en.wikipedia.org/wiki/Catamorphism>`__, they
each convert a sequence to a single value.
.. code:: ipython2
J('[sum] help')
.. parsed-literal::
Given a quoted sequence of numbers return the sum.
sum == 0 swap [+] step
.. code:: ipython2
J('[size] help')
.. parsed-literal::
0 swap [pop ++] step
We can use "compiled" versions (they're not really compiled in this
case, they're hand-written in Python) to speed up evaluation and make
the trace more readable. The ``sum`` function is already in the library.
It gets shadowed by the definition version above during
``initialize()``.
.. code:: ipython2
from joy.library import SimpleFunctionWrapper, primitives
from joy.utils.stack import iter_stack
@SimpleFunctionWrapper
def size(stack):
'''Return the size of the sequence on the stack.'''
sequence, stack = stack
n = 0
for _ in iter_stack(sequence):
n += 1
return n, stack
sum_ = next(p for p in primitives if p.name == 'sum')
Now we replace them old versions in the dictionary with the new versions
and re-evaluate the expression.
.. code:: ipython2
old_sum, D['sum'] = D['sum'], sum_
old_size, D['size'] = D['size'], size
You can see that ``size`` and ``sum`` now execute in a single step.
.. code:: ipython2
V('[23 18] average')
.. parsed-literal::
. [23 18] average
[23 18] . average
[23 18] . [sum 1.0 *] [size] cleave /
[23 18] [sum 1.0 *] . [size] cleave /
[23 18] [sum 1.0 *] [size] . cleave /
[23 18] [sum 1.0 *] [size] . [i] app2 [popd] dip /
[23 18] [sum 1.0 *] [size] [i] . app2 [popd] dip /
[23 18] [[sum 1.0 *] [23 18]] [i] . infra first [[size] [23 18]] [i] infra first [popd] dip /
[23 18] [sum 1.0 *] . i [[23 18]] swaack first [[size] [23 18]] [i] infra first [popd] dip /
[23 18] . sum 1.0 * [[23 18]] swaack first [[size] [23 18]] [i] infra first [popd] dip /
41 . 1.0 * [[23 18]] swaack first [[size] [23 18]] [i] infra first [popd] dip /
41 1.0 . * [[23 18]] swaack first [[size] [23 18]] [i] infra first [popd] dip /
41.0 . [[23 18]] swaack first [[size] [23 18]] [i] infra first [popd] dip /
41.0 [[23 18]] . swaack first [[size] [23 18]] [i] infra first [popd] dip /
[23 18] [41.0] . first [[size] [23 18]] [i] infra first [popd] dip /
[23 18] 41.0 . [[size] [23 18]] [i] infra first [popd] dip /
[23 18] 41.0 [[size] [23 18]] . [i] infra first [popd] dip /
[23 18] 41.0 [[size] [23 18]] [i] . infra first [popd] dip /
[23 18] [size] . i [41.0 [23 18]] swaack first [popd] dip /
[23 18] . size [41.0 [23 18]] swaack first [popd] dip /
2 . [41.0 [23 18]] swaack first [popd] dip /
2 [41.0 [23 18]] . swaack first [popd] dip /
[23 18] 41.0 [2] . first [popd] dip /
[23 18] 41.0 2 . [popd] dip /
[23 18] 41.0 2 [popd] . dip /
[23 18] 41.0 . popd 2 /
41.0 . 2 /
41.0 2 . /
20.5 .

View File

@ -12218,7 +12218,7 @@ G == [direco] cons [swap] swoncat cons</code></pre>
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Generating-Multiples-of-Three-and-Five">Generating Multiples of Three and Five<a class="anchor-link" href="#Generating-Multiples-of-Three-and-Five">&#182;</a></h2><p>Look at the treatment of the Project Euler Problem One in <a href="./Developing a Program.ipynb">Developing a Program.ipynb</a> and you'll see that we might be interested in generating an endless cycle of:</p>
<h2 id="Generating-Multiples-of-Three-and-Five">Generating Multiples of Three and Five<a class="anchor-link" href="#Generating-Multiples-of-Three-and-Five">&#182;</a></h2><p>Look at the treatment of the Project Euler Problem One in the "Developing a Program" notebook and you'll see that we might be interested in generating an endless cycle of:</p>
<pre><code>3 2 1 3 1 2 3

View File

@ -164,7 +164,7 @@ J('23 [dup ++] G 5 [x] times')
## Generating Multiples of Three and Five
Look at the treatment of the Project Euler Problem One in [Developing a Program.ipynb](./Developing a Program.ipynb) and you'll see that we might be interested in generating an endless cycle of:
Look at the treatment of the Project Euler Problem One in the "Developing a Program" notebook and you'll see that we might be interested in generating an endless cycle of:
3 2 1 3 1 2 3

View File

@ -208,9 +208,9 @@ with the ``x`` combinator.
Generating Multiples of Three and Five
--------------------------------------
Look at the treatment of the Project Euler Problem One in `Developing a
Program.ipynb <./Developing%20a%20Program.ipynb>`__ and you'll see that
we might be interested in generating an endless cycle of:
Look at the treatment of the Project Euler Problem One in the
"Developing a Program" notebook and you'll see that we might be
interested in generating an endless cycle of:
::

View File

@ -26,9 +26,7 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"scrolled": true
},
"metadata": {},
"outputs": [
{
"name": "stdout",

View File

@ -11778,14 +11778,6 @@ div#notebook {
<p>This notebook is about using the "zipper" with joy datastructures. See the <a href="https://en.wikipedia.org/wiki/Zipper_%28data_structure%29">Zipper wikipedia entry</a> or the original paper: <a href="https://www.st.cs.uni-saarland.de/edu/seminare/2005/advanced-fp/docs/huet-zipper.pdf">"FUNCTIONAL PEARL The Zipper" by Gérard Huet</a></p>
<p>Given a datastructure on the stack we can navigate through it, modify it, and rebuild it using the "zipper" technique.</p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h3 id="Preamble">Preamble<a class="anchor-link" href="#Preamble">&#182;</a></h3>
</div>
</div>
</div>

View File

@ -6,16 +6,10 @@
"source": [
"This notebook is about using the \"zipper\" with joy datastructures. See the [Zipper wikipedia entry](https://en.wikipedia.org/wiki/Zipper_%28data_structure%29) or the original paper: [\"FUNCTIONAL PEARL The Zipper\" by Gérard Huet](https://www.st.cs.uni-saarland.de/edu/seminare/2005/advanced-fp/docs/huet-zipper.pdf)\n",
"\n",
"\n",
"Given a datastructure on the stack we can navigate through it, modify it, and rebuild it using the \"zipper\" technique."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Preamble"
]
},
{
"cell_type": "code",
"execution_count": 1,

View File

@ -1,9 +1,8 @@
This notebook is about using the "zipper" with joy datastructures. See the [Zipper wikipedia entry](https://en.wikipedia.org/wiki/Zipper_%28data_structure%29) or the original paper: ["FUNCTIONAL PEARL The Zipper" by Gérard Huet](https://www.st.cs.uni-saarland.de/edu/seminare/2005/advanced-fp/docs/huet-zipper.pdf)
Given a datastructure on the stack we can navigate through it, modify it, and rebuild it using the "zipper" technique.
### Preamble
Given a datastructure on the stack we can navigate through it, modify it, and rebuild it using the "zipper" technique.
```python

View File

@ -8,9 +8,6 @@ Huet <https://www.st.cs.uni-saarland.de/edu/seminare/2005/advanced-fp/docs/huet-
Given a datastructure on the stack we can navigate through it, modify
it, and rebuild it using the "zipper" technique.
Preamble
~~~~~~~~
.. code:: ipython2
from notebook_preamble import J, V, define

Binary file not shown.

View File

@ -46,7 +46,7 @@
</li>
<li class="toctree-l1"><a class="reference internal" href="Replacing.html">Replacing Functions in the Dictionary</a><ul>
<li class="toctree-l2"><a class="reference internal" href="Replacing.html#a-long-trace">A long trace</a></li>
<li class="toctree-l2"><a class="reference internal" href="Replacing.html#replacing-size-with-a-python-version">Replacing <code class="docutils literal notranslate"><span class="pre">size</span></code> with a Python Version</a></li>
<li class="toctree-l2"><a class="reference internal" href="Replacing.html#replacing-size-with-a-python-version">Replacing <code class="docutils literal notranslate"><span class="pre">size</span></code> with a Python version</a></li>
<li class="toctree-l2"><a class="reference internal" href="Replacing.html#a-shorter-trace">A shorter trace</a></li>
</ul>
</li>

View File

@ -1,15 +1,13 @@
*************************************
Replacing Functions in the Dictionary
*************************************
Replacing Functions in the Dictionary
=====================================
.. code:: ipython2
from notebook_preamble import D, J, V
A long trace
~~~~~~~~~~~~
------------
.. code:: ipython2
@ -62,8 +60,8 @@ A long trace
20.5 .
Replacing ``size`` with a Python Version
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Replacing ``size`` with a Python version
----------------------------------------
Both ``sum`` and ``size`` each convert a sequence to a single value.
@ -71,10 +69,10 @@ Both ``sum`` and ``size`` each convert a sequence to a single value.
sum == 0 swap [+] step
size == 0 swap [pop ++] step
An efficient ``sum`` function is already in the library. But for ``size`` we can use
a "compiled" version hand-written in Python to speed up evaluation and make the trace more readable.
An efficient ``sum`` function is already in the library. But for
``size`` we can use a “compiled” version hand-written in Python to speed
up evaluation and make the trace more readable.
.. code:: ipython2
@ -98,11 +96,10 @@ and re-evaluate the expression.
D['size'] = size
A shorter trace
~~~~~~~~~~~~~~~~~~~~
---------------
You can see that ``size`` and ``sum`` now execute in a single step.
You can see that ``size`` now executes in a single step.
.. code:: ipython2