Jump to content

Higher-order functions: Difference between revisions

→‎{{header|Quackery}}: simplified fold
(→‎{{header|Quackery}}: improved flattening a nest from O(n^2) to O(log n))
(→‎{{header|Quackery}}: simplified fold)
Line 3,525:
First define the higher order functions <code>fold</code>, <code>map</code>, and <code>filter</code>.
 
<pre> [ stackover [] = iff drop is fold.act ( --> s )done
dip
protect fold.act
[ behead swap
 
' [ witheach ] ]
[ fold.act put
fold.act release ]nested join do ] is fold ( [ x --> x )
[ dup [] = if done
behead swap
witheach
[ fold.act share do ] ]
fold.act release ] is fold ( [ x --> x )
 
[ ' [ [ ] ] rot join swap
nested
' [ nested join ] join
fold ] is map ( [ x --> [ )
 
[ ' [ [ ] ] rot join swap
Line 3,544 ⟶ 3,540:
' [ iff [ nested join ]
else drop ] join
fold ] is filter ( [ x --> [ )
 
</pre>
 
1,462

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.