Partial function application: Difference between revisions
→{{header|Bracmat}} The previous solution was wrong. The function fs did not take two arguments.
(→{{header|Kotlin}}: Updated example see https://github.com/dkandalov/rosettacode-kotlin for details) |
|||
Line 258:
=={{header|Bracmat}}==
This task is hard to solve if we use imperative/procedural style Bracmat functions. Instead, we use lambda expressions throughout the solution given below.
The the function <code>fs</code> consists of a lambda abstraction inside a lambda abstraction. In that way <code>fs</code> can take two arguments. Similarly, the function <code>partial</code>, which also needs to take two arguments, is defined using lambda abstractions.
Currying takes place by applying a two-argument function to its first argument. This happens in <code>($x)$($y)</code>.
& (partial=/('(x./('(y.($x)$($y))))))
& out$(!fsf1$(0 1 2 3))▼
& out$(!fsf2$(0 1 2 3))▼
& out$(!fsf1$(2 4 6 8))▼
& out$(!fsf2$(2 4 6 8))▼
▲ & /('(x./('(y.($x)$($y)))$!g))$!f
▲& (f1=.2*!arg)
▲& (f2=.!arg^2)
▲& partial$(fs.f1):(=?fsf1)
▲& partial$(fs.f2):(=?fsf2)
▲& out$(fsf1$(0 1 2 3))
▲& out$(fsf2$(0 1 2 3))
▲& out$(fsf1$(2 4 6 8))
▲& out$(fsf2$(2 4 6 8))
);</lang>
Output:
|