-
-.. code:: ipython2
+.. code:: ipython3
from notebook_preamble import D, DefinitionWrapper, J, V, define
Bird & Meertens
+`PDF paper available
+here <https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.694.2614>`__
+
Define ``scan`` in terms of a reduction.
----------------------------------------
::
- â¨\82\x = f(a)⨂f(b)⨂...⨂f(z)
+ â¨\81\x = f(a)⨂f(b)⨂...⨂f(z)
Designing the Recursive Function
--------------------------------
This works to a point, but it throws away the last term:
-.. code:: ipython2
+.. code:: ipython3
J('[1 2 3] [size 1 <=] [pop []] [[[+] infra] dupdip first] [dip swons] genrec')
Hmm... Let's take out the ``pop`` for a sec...
-.. code:: ipython2
+.. code:: ipython3
J('[1 2 3] [size 1 <=] [[]] [[[+] infra] dupdip first] [dip swons] genrec')
empty list, they will be ``swons``'d onto that list that already has the
last item.
-.. code:: ipython2
+.. code:: ipython3
J('[1 2 3] [size 1 <=] [] [[[+] infra] dupdip first] [dip swons] genrec')
scan == [infra] cons [dupdip first] cons [size 1 <=] [] roll< [dip swons] genrec
-.. code:: ipython2
+.. code:: ipython3
- define('scan == [infra] cons [dupdip first] cons [size 1 <=] [] roll< [dip swons] genrec')
+ define('scan [infra] cons [dupdip first] cons [size 1 <=] [] roll< [dip swons] genrec')
-.. code:: ipython2
+.. code:: ipython3
J('[1 2 3 4] [+] scan')
[1 3 6 10]
-.. code:: ipython2
+.. code:: ipython3
J('[1 2 3 4] [*] scan')
[1 2 6 24]
-.. code:: ipython2
+.. code:: ipython3
J('[1 2 3 4 5 6 7] [neg +] scan')
Unlines = uncons ['\n' swap + +] step
-.. code:: ipython2
+.. code:: ipython3
J('["hello" "world"] uncons ["\n" swap + +] step')