16 lines
593 B
Plaintext
16 lines
593 B
Plaintext
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
|