Higher Order Function Question

Alex Peake apeake@REDACTED
Fri May 24 17:27:22 CEST 2002


Richard,

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
need.

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}]} **


Thanks,

Alex



> -----Original Message-----
> From: owner-erlang-questions@REDACTED
> [mailto:owner-erlang-questions@REDACTED]On Behalf Of Raimo Niskanen
> Sent: Friday, May 24, 2002 12:18 AM
> To: erlang-questions@REDACTED
> Subject: Re: Higher Order Function Question
>
>
> I cannot come up with anything better than:
>
> 	lists:filter(fun (Attr) -> not attr:isPk(Attr) end, SomeList)
>
> or
>
> 	complement(Fun) -> fun (Attr) -> not Fun(Attr) end.
>
> 	lists:filter(complement({attr, isPk}), SomeList)
> 	% or
> 	lists:filter(complement(fun isPk/1), SomeList) % within
> module 'attr'
> 	% or
> 	lists:filter(complement(fun(Attr) -> attr:isPk(Attr) end,
> SomeList) %
> Very pointless with the complement() function
>
> / Raimo Niskanen, Erlang/OTP, Ericsson AB
>
>
>
>
> Alex Peake wrote:
> >
> > Can someone help me with this (no doubt simple) problem.
> >
> > I try:
> >
> > 1> attr:isPk(Attr).
> > false
> >
> > 2> not attr:isPk(Attr).
> > true
> >
> > 3> not(attr:isPk(Attr)).
> > true
> >
> > but cannot find a permutation/combination of:
> >
> > 4> apply({attr, isPk}, [A1]).
> > false
> >
> > that can include "not" and work.
> >
> > Actually, I am trying to lists:filter( ...not isPk... SomeList).
> >
> > The simple is to define notIsPk(Attr), or perhaps lists:filter(
> fun(Attr) ->
> > .. end  but they are not an abstraction of "complement".
> >
> > Perhaps I should define a function complement(Fn) that returns
> a function
> > that is the complement of the function passed?
> >
> > Perhaps there is already an Erlang way to do this (I hope).
> >
> > Alex
>





More information about the erlang-questions mailing list