Function composition: Difference between revisions
Content added Content deleted
(Add bruijn) |
|||
Line 616: | Line 616: | ||
b = compose(->double ->add1) |
b = compose(->double ->add1) |
||
p b 1 #should print 4</syntaxhighlight> |
p b 1 #should print 4</syntaxhighlight> |
||
=={{header|Bruijn}}== |
|||
Composition operators as defined in <syntaxhighlight>std/Combinator</syntaxhighlight>: |
|||
<syntaxhighlight lang="bruijn"> |
|||
:import std/Number . |
|||
# 1x composition, bluebird combinator |
|||
…∘… [[[2 (1 0)]]] |
|||
:test (((inc ∘ (mul (+2))) (+3)) =? (+7)) ([[1]]) |
|||
# 2x composition, blackbird combinator |
|||
…∘∘… [[[[3 (2 1 0)]]]] |
|||
:test (((inc ∘∘ mul) (+2) (+3)) =? (+7)) ([[1]]) |
|||
# 3x composition, bunting combinator |
|||
…∘∘∘… [[[[[4 (3 2 1 0)]]]]] |
|||
:test (((inc ∘∘∘ (add ∘∘ mul)) (+1) (+2) (+4)) =? (+7)) ([[1]]) |
|||
# reverse composition, queer bird combinator |
|||
…→… [[[1 (2 0)]]] |
|||
:test ((((mul (+2)) → inc) (+3)) =? (+7)) ([[1]]) |
|||
</syntaxhighlight> |
|||
=={{header|C}}== |
=={{header|C}}== |