On Wed, 2004-07-21 at 16:37, Kostas Oikonomou wrote:
> Suppose I have a function f(), and a list L = [x1,x2,...].
> Is there an elegant way to map f onto L, i.e. compute [f(x1),f(x2),...]?
> I thought something like that was in the IPL, but if so, I can't find it.
>
> And does this work if my f has arguments? E.g. L is a list of real numbers, and
> I want to format each one by applying frn(.,,2) to it.
Just because my brain is fried and I'm too tired to do any real work,
here's a general solution based on Closure for the 2nd part of the
above:
use "Utils" # From http://tapestry.tucson.az.us/unicon
procedure mapF(f, L)
every put(a := [], Utils::invoke(f, !L))
return a
end
where the call would be something like:
L := mapF(Closure(f, [arg1, AGap(), arg3]), L)
which is (in this case) an approximation of:
procedure mapFun(f, L)
every put(a := [], f(arg1, !L, arg3])
return a
end
[For a single-valued function g(x), mapF(g, L) also works (no need
for a Closure as the invoke() procedure works with functions as
well as Closures.]
--
Steve Wampler <[EMAIL PROTECTED]>
-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=4721&alloc_id=10040&op=click
_______________________________________________
Unicon-group mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/unicon-group