How to resolve the algorithm Partial function application step by step in the E programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Partial function application step by step in the E programming language
Table of Contents
Problem Statement
Partial function application is the ability to take a function of many parameters and apply arguments to some of the parameters to create a new function that needs only the application of the remaining arguments to produce the equivalent of applying all arguments to the original function. E.g:
Note that in the partial application of a parameter, (in the above case param1), other parameters are not explicitly mentioned. This is a recurring feature of partial function application.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Partial function application step by step in the E programming language
Source code in the e programming language
def pa(f, args1) {
return def partial {
match [`run`, args2] {
E.call(f, "run", args1 + args2)
}
}
}
def fs(f, s) {
var r := []
for n in s {
r with= f(n)
}
return r
}
def f1(n) { return n * 2 }
def f2(n) { return n ** 2 }
def fsf1 := pa(fs, [f1])
def fsf2 := pa(fs, [f2])
for s in [0..3, [2, 4, 6, 8]] {
for f in [fsf1, fsf2] {
println(f(s))
}
}
You may also check:How to resolve the algorithm 15 puzzle solver step by step in the Nim programming language
You may also check:How to resolve the algorithm Sequence: nth number with exactly n divisors step by step in the Julia programming language
You may also check:How to resolve the algorithm Sum and product puzzle step by step in the D programming language
You may also check:How to resolve the algorithm Associative array/Iteration step by step in the Frink programming language
You may also check:How to resolve the algorithm Miller–Rabin primality test step by step in the Prolog programming language