on master help sign in
Merge pull request #1132 from urbit/roll-reel-redux

roll and reel order of operations

commit2246b1cb566f8f1333787eb7b0ea08d68fd1b047 authorpoprox <51337059+drbeefsupreme@users.noreply.github.com> dateThu 30 Sep 2021, 14:12 (5 years ago) parentb12efd52b16725
1 file changed+37
content/docs/hoon/reference/stdlib/2b.md+37
content/docs/hoon/reference/stdlib/2b.md+37
@@ -785,6 +785,19 @@ We can fix this with `|:`:
78578524
786786```
787787
788+If you check the definition of `+mul`, you'll see that it also utilizes this
789+pattern.
790+
791+We can check explicitly what sequence of operations `+reel` performs like this:
792+```
793+> =f |: [l='e_l' r='e_r']
794+ ^- @t
795+ :((cury cat 3) '(' l '*' r ')')
796+> (reel "abcde" f)
797+'(a*(b*(c*(d*(e*e_r)))))'
798+```
799+
800+
788801---
789802
790803## `++roll`
@@ -863,6 +876,30 @@ We can fix this with `|:`:
863876> (roll `(list @)`~[1 2 3 4] |:([a=1 b=1] (mul a b)))
86487724
865878```
879+If you check the definition of `+mul`, you'll see that it also utilizes this
880+pattern.
881+
882+We can check explicitly what sequence of operations `+roll` performs like this:
883+```
884+> =f |: [l='e_l' r='e_r']
885+ ^- @t
886+ :((cury cat 3) '(' l '*' r ')')
887+> (roll "abcde" f)
888+'(e*(d*(c*(b*(a*e_r)))))
889+```
890+This is in contrast to what one might expect:
891+```
892+> =foldl
893+ |* [l=(list) f=$-([* *] *)]
894+ ^- f
895+ ?~ l +<-.f
896+ %= $
897+ +<-.f (f +<-.f i.l)
898+ l t.l
899+ ==
900+> (foldl "abcde" f)
901+'(((((e_l*a)*b)*c)*d)*e)'
902+```
866903
867904---
868905