Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
15
Task/Function-composition/Lang/function-composition.lang
Normal file
15
Task/Function-composition/Lang/function-composition.lang
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
fp.f = ($x) -> return parser.op($x * 3)
|
||||
fp.g = ($x) -> return parser.op($x + 2)
|
||||
|
||||
$x = 5
|
||||
|
||||
# In Lang this task can be achieved with the concat operator
|
||||
fn.println(parser.op((fp.g ||| fp.f)($x))) # Prints 21 [Internal execution: fp.f(fp.g($x))]
|
||||
|
||||
# Creating a user-defined function doing the same thing is a bit more difficult
|
||||
fp.compose = (fp.f, fp.g) -> {
|
||||
fp.innerFunc = (fp.f, fp.g, $x) -> return fp.f(fp.g($x))
|
||||
return fn.argCnt1(fn.combA3(fp.innerFunc, fp.f, fp.g)) # fn.combA3 must be used, because Lang does not support closures
|
||||
}
|
||||
|
||||
fn.println(fp.compose(fp.f, fp.g)($x)) # Prints also 21
|
||||
Loading…
Add table
Add a link
Reference in a new issue