Difference between revisions of "Combinators"
Line 18: | Line 18: | ||
From the Global Scope, the call could be λB([SUM,RECIPROCAL])(1..10) . All combinators are named such as λCOMBINATOR with a λ prefix at the global scope. The parameters are an array of functions, and the resulting function can be used later with parameters to provide results. | From the Global Scope, the call could be λB([SUM,RECIPROCAL])(1..10) . All combinators are named such as λCOMBINATOR with a λ prefix at the global scope. The parameters are an array of functions, and the resulting function can be used later with parameters to provide results. | ||
+ | |||
+ | Code Keyboard Helper contains a panel to aid the use of combinators. | ||
+ | |||
+ | [[Image:Combinators.png|center|600px|ZCubes Code Mode Combinator Quick Panel]] |
Revision as of 16:24, 6 March 2024
Combinators in z^3
Combinators are an advanced concept. But z^3 makes it simple.
For more details, please go through Combinators Theory.
Functional Languages often use patterns to combine function. These are called Combinators. For example, few of these patterns are given in Functional programming in JavaScript Part 2 - Combinators (such as Tap, Currying, Pipe/Compose, Fork, Alternation, Sequence, etc.).
In z^3, Combinators are accessible as a part of an array of functions, as well as in the Global Scope.
Take for example the B combinator, which is defined as B = a => b => c => a(b(c)), and takes functions and apply them one atop the other.
In z^3, [SUM,RECIPROCAL].$combinators("B") gives a function that can be called with arguments.
[SUM,RECIPROCAL].$combinators("B")(1..10)
gives 2.9289682539682538 (which is SUM(RECIPROCAL(1..10))).
From the Global Scope, the call could be λB([SUM,RECIPROCAL])(1..10) . All combinators are named such as λCOMBINATOR with a λ prefix at the global scope. The parameters are an array of functions, and the resulting function can be used later with parameters to provide results.
Code Keyboard Helper contains a panel to aid the use of combinators.