erl_eval function object

Paul Mineiro paul-trapexit@REDACTED
Tue Aug 4 19:38:30 CEST 2009


The documentation for erl_eval says that the NonlocalFunctionHandler is
called when a functional object (fun) is called; however I'm not seeing
this.

Any insight would be appreciated.

Cheers,

-- p

-----
-module (evaltest).
-compile (export_all).

doit (String) ->
  { ok, Scanned, _ } = erl_scan:string (String),
  { ok, Parsed } = erl_parse:parse_exprs (Scanned),
  Bindings = erl_eval:new_bindings (),
  erl_eval:exprs (Parsed,
                  Bindings,
                  { value, fun local/2 },
                  { value, fun non_local/2 }).

local (Name, Arguments) ->
  io:format ("local ~p ~p~n", [ Name, Arguments ]),
  false.

non_local (FuncSpec, Arguments) ->
  io:format ("non_local ~p ~p~n", [ FuncSpec, Arguments ]),
  case FuncSpec of
    { M, F } -> erlang:apply (M, F, Arguments);
    Func when is_function (Func) -> erlang:apply (Func, Arguments)
  end.
-----

% erl
Erlang (BEAM) emulator version 5.6.5 [source] [smp:2] [async-threads:0] [kernel-poll:false]
Eshell V5.6.5  (abort with ^G)
1> evaltest:doit ("(fun () -> 10 + 2 end) ().").
non_local {erlang,'+'} [10,2]
{value,12,[]}

-----


More information about the erlang-questions mailing list