Higher Order Function Question

Fredrik Linder fredrik.linder@REDACTED
Fri May 24 18:06:33 CEST 2002


> As for
> 4> apply({attr, isPk}, [A1]).
>
> as I mentioned, I was just testing for eventual use in filter, and as far
as
> I know, in filter (and map, etc.) you *must* use the form {attr, isPk}. I
> always get errors when I try attr:isPk within map, filter etc.

You *must* supply a fun, but there are three alternatives to define one, the
one you chose I guess is considered to be the least elegant.

Fun = {M, F}
Fun = fun M:F/A, where A = arity (requires that M:F/A is a named existing
function)
Fun = fun(Arg) -> M:F(Arg) end

The apply call above can even be written:

{attr, isPk}(A1)     %% !!!
fun(X) -> attr:isPk(X) end(A1)

or simply

attr:isPk(A1)  ;-)

/Fredrik





More information about the erlang-questions mailing list