Function composition: Difference between revisions

Content added Content deleted
(Emacs Lisp: Replace obsolete code with lexical binding example)
Line 1,771: Line 1,771:


=={{header|M2000 Interpreter}}==
=={{header|M2000 Interpreter}}==
===Using Lambda functions===
<lang M2000 Interpreter>
<lang M2000 Interpreter>
Module CheckIt {
Module CheckIt {
Line 1,782: Line 1,783:
}
}
CheckIt
CheckIt
</lang>
===Using EVAL and EVAL$===
<lang M2000 Interpreter>
class Compose {
private:
composition$
public:
function formula$ {
=.composition$
}
value (x){
=Eval(.composition$)
}
Class:
module compose(a$, b$) {
.composition$<=a$+"("+b$+"(x))"
}
}
function Global Exp(x) {
=round(2.7182818284590452**x)
}
class ComposeStr$ {
private:
composition$
public:
function formula$ {
=.composition$
}
value (x$){
=Eval$(.composition$.) // NEED A DOT AFTER STRING VARIABLE
}
Class:
module composeStr(a$, b$) {
.composition$<=a$+"("+b$+"(x$))"
}
}
ExpLog=Compose("Exp", "Ln")
Print ExpLog(3)
UcaseLcase$=ComposeStr$("Ucase$", "Lcase$")
Print UcaseLcase$("GOOD")
</lang>
</lang>