Send an unknown method call: Difference between revisions

Line 532:
echo call_user_func(array($example, $name), 5), "\n";
?></lang>
 
=={{header|Picat}}==
For functions use apply/n and for predicates call/n. The name of the function/predicate must be an atom, strings must be converted to atom, e.g. with to_atom/1.
<lang Picat>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.</lang>
 
{{out}}
<pre>Function: Use apply/n
55
 
Predicate: use call/n
z = 25
z2 = 365</pre>
 
=={{header|PicoLisp}}==
495

edits