Higher Order Function Question

Hakan Stenholm <>
Fri May 24 18:23:34 CEST 2002

>Thanks you for the list comprehension suggestion. I had not thought of that
>(it does not exist in the Lisp world where I come from).
>I do use complement a lot, so I think, for me, it is worth the definition --
>but perhaps if I re-examine my approach, list comprehensions may obviate the
>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.
>150> lists:map(attr:varName, rel:attrList(rel:findNamed(ng,"Member"))).
>** exited: {{badexpr,':'},[{erl_eval,expr,3}]} **

lists:map({attr,varName}, rel:attrList(rel:findNamed(ng,"Member"))).
should work, see examples below:
1>  lists:map({lists,append},[[[1],[2],[3]], [[b],[c]]]).
3> {lists,append}([[1,2,3],[a,b,c]]).

There are three basic ways to define a fun:
Fun = fun(Arg1, Arg2 ....) -> ... end  % anynomouse fun
Fun = fun FunctionName/Arity           % local fun in current file
Fun = {Module, FunctionName}           % any exported function can be used

all which can be called as Fun(A1,A2, ....) as can be seen below:

2> fun(L) -> lists:append(L) end([[1,2,3],[a,b,c]]).


head([A|_]) -> A.

test_call() ->
    fun head/1([1,2,3,4]).
1> test:test_call().
Ofcourse we usally write something like:
Fun = ....
Fun(A1,A2, ....)  


More information about the erlang-questions mailing list