function() guard

WILLIAMS Dominic D.WILLIAMS@REDACTED
Thu Aug 14 09:40:22 CEST 2003


Hello,

The function() guard does not seem to accept the {Module,Fun} form. Is this intentional, or am I doing something wrong?

----- THIS RETURNS ok --------

-module(funguard).
-export([run/0,global/0]).

f(Fun) when function(Fun) ->
	Fun().

local() ->
	ok.

global() ->
	ok.

run() ->
	ok = f(fun() -> ok end),
	ok = f(fun local/0).
%	ok = f({funguard,global}).  %% NOT ATTEMPTED

----- THIS ALSO RETURNS ok --------

-module(funguard).
-export([run/0,global/0]).

f(Fun) ->        %% REMOVED GUARD
	Fun().

local() ->
	ok.

global() ->
	ok.

run() ->
	ok = f(fun() -> ok end),
	ok = f(fun local/0),
	ok = f({funguard,global}).

----- THIS exits with function_clause  --------

-module(funguard).
-export([run/0,global/0]).

f(Fun) when function(Fun) ->
	Fun().

local() ->
	ok.

global() ->
	ok.

run() ->
	ok = f(fun() -> ok end),
	ok = f(fun local/0),
	ok = f({funguard,global}).

------

Cheers,

Dominic.



More information about the erlang-questions mailing list