Task

Invoke an object method where the name of the method to be invoked can be generated at run time.



Related tasks

 Respond to an unknown method call.
 Runtime evaluation


go =>
  println("Function: Use apply/n"),
  Fun = "fib",
  A = 10,
  % Convert F to an atom 
  println(apply(to_atom(Fun),A)),
  nl,
 
  println("Predicate: use call/n"),
  Pred = "pyth",
  call(Pred.to_atom,3,4,Z),
  println(z=Z),
 
  % Pred2 is an atom so it can be used directly with call/n.
  Pred2 = pyth,
  call(Pred.to_atom,13,14,Z2),
  println(z2=Z2),
 
  nl.
 
% A function
fib(1) = 1.
fib(2) = 1.
fib(N) = fib(N-1) + fib(N-2).
 
% A predicate
pyth(X,Y,Z) =>
  Z = X**2 + Y**2.