diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 0000000..27eae21 --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,27 @@ +#docs := $(wildcard *.ipynb) +#docs_html := $(patsubst %.ipynb,%.html,$(docs)) + +.PHONY: poop nospaces yesspaces + +# https://stackoverflow.com/a/45531875 +# Make cannot handle spaces in filenames, so temporarily rename them +nospaces: + rename -v 's/ /%20/g' *\ * + +# After Make is done, rename files back to having spaces +yesspaces: + rename -v 's/%20/ /g' *%20* + + +poop: *.ipynb + make "$(patsubst %.ipynb,%.html,$<)" + +%.html : %.ipynb + python -m nbconvert --to html $< + +%.md : %.ipynb + python -m nbconvert --to markdown $< + +%.rst : %.ipynb + python -m nbconvert --to rst $< + diff --git a/docs/Replacing.html b/docs/Replacing.html new file mode 100644 index 0000000..657674b --- /dev/null +++ b/docs/Replacing.html @@ -0,0 +1,12025 @@ + + +
+from notebook_preamble import D, J, V
+V('[23 18] average')
+size with a Python version¶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.
from joy.library import SimpleFunctionWrapper
+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
+Now we replace the old version in the dictionary with the new version, and re-evaluate the expression.
+ +D['size'] = size
+You can see that size now executes in a single step.
V('[23 18] average')
+