is there an equivalent to lisp's apply function?
Have a look at perform
& performWithArgList
methods.
To step back a bit you can replicate Lisp's FUNCALL
in a few different ways in Io:
1 - Passing a function ie. block():
plotf := method (fn, min, max, step,
for (i, min, max, step,
fn call(i) roundDown repeat(write("*"))
writeln
)
)
plotf( block(n, n exp), 0, 4, 1/2 )
2 - Passing a message:
plotm := method (msg, min, max, step,
for (i, min, max, step,
i doMessage(msg) roundDown repeat(write("*"))
writeln
)
)
plotm( message(exp), 0, 4, 1/2 )
3 - passing the function name as a string:
plots := method (str, min, max, step,
for (i, min, max, step,
i perform(str) roundDown repeat(write("*"))
writeln
)
)
plots( "exp", 0, 4, 1/2 )
So from all this you could create a Lisp APPLY
like so:
apply := method (
args := call message argsEvaluatedIn(call sender)
fn := args removeFirst
performWithArgList( fn, args )
)
apply( "plotf", block(n, n exp), 0, 4, 1/2 )
apply( "plotm", message(exp), 0, 4, 1/2 )
apply( "plots", "exp", 0, 4, 1/2 )