fun task ← void by text about, fun code writeLine(0U00b7, " ", about) code() end fun answer ← void by var message do writeLine(" ", message) end # few definitions fun noArgumentsFunction ← int by block do return 97 end fun fixedArgumentsFunction ← void by var a, var b do end fun variadicFunction ← void by text a, some var values do end fun funArgumentFunction ← var by fun f, var b do return f() + b end task("Calling a function that requires no arguments", void by block answer("Is supported.") noArgumentsFunction() end) task("Calling a function with a fixed number of arguments", void by block answer("Is supported.") fixedArgumentsFunction(97, 3.14) end) task("Calling a function with optional arguments", void by block answer("Not supported in EMal.") end) task("Calling a function with a variable number of arguments", void by block answer("Variadic functions are supported.") variadicFunction("mandatory", 97, 3.14) variadicFunction("mandatory", 97) end) task("Calling a function with named arguments", void by block answer("Not supported in EMal.") end) task("Using a function in statement context", void by block answer("Is supported.") if true do noArgumentsFunction() else do fixedArgumentsFunction(97, 3.14) end end) task("Using a function in first-class context within an expression", void by block answer("Functions are first class, can be passed as arguments and returned.") answer(funArgumentFunction(noArgumentsFunction, 3.14)) end) task("Obtaining the return value of a function", void by block answer("Is supported.") int value ← noArgumentsFunction() answer(value) end) task("Distinguishing built-in functions and user-defined functions", void by block answer("No distinction.") end) task("Distinguishing subroutines and functions", void by block answer("No distinction, we support void return type.") end) task("Stating whether arguments are passed by value or by reference", void by block answer("Pass by value, but text, blob, objects hold a reference.") end) task("Is partial application possible and how", void by block answer("Is supported.") ^|I had some confusion about partial application and currying, thanks to these links: | https://stackoverflow.com/questions/218025/what-is-the-difference-between-currying-and-partial-application | https://web.archive.org/web/20161023205431/http://www.uncarved.com/articles/not_curryin |^ # Partial applying fun add ← int by int a, int b do return a + b end fun partial ← fun by fun f, int a return int by int b return add(a, b) end end fun add7 ← partial(add, 7) answer(add(7, 5)) answer(add7(5)) # Currying fun addN ← fun by int n return int by int x return x + n end end fun plus ← int by int a, int b fun addA ← addN(a) return addA(b) end answer(plus(7, 5)) end)