Redirecting functions calls ?
Sean Hinde
sean.hinde@REDACTED
Fri Apr 23 00:18:18 CEST 2004
Hi,
On 23 Apr 2004, at 00:39, yerl@REDACTED wrote:
> Hi All,
> Is there a method to redirect the call of a function and execute
> another one instead.
> For exemple, lets assume 2 functions "foo" and "bar":
>
> foo(X) ->
> blablabla,
> 26.
>
> bar(Y) ->
> blablabla,
> 38.
>
> When calling foo(10), I want to intercept this call and replace with
> bar(10). Of course, the result of foo(10) is replaced by the one of
> bar(10).
>
> Can anyboby help me!
Actually this is almost possible - I discovered a compiler bug just
today:
-module(compiler_bug).
-export([test/1, wow/1]).
test(A) when fred ->
{ok, A}.
wow(A) ->
wow.
This compiles fine. Trying this out:
175> compiler_bug:test(1).
=ERROR REPORT==== 22-Apr-2004::23:11:45 ===
Error in process <0.1000.0> on node 'eradius@REDACTED' with exit
value:
{function_clause,[{compiler_bug,wow,[1]},{erl_eval,do_apply,5},{shell,ev
al_loop,2}]}
** exited: {function_clause,[{compiler_bug,wow,[1]},
{erl_eval,do_apply,5},
{shell,eval_loop,2}]} **
I haven't managed to make it correctly call wow(1), but the error
report suggests that my call to test/1 did indeed result in a call to
wow/1
:-)
Sean
More information about the erlang-questions
mailing list