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.

Hmmm, in looking at this, and Kazimir's suggestion, will the following
work?:

    procedure mapFun(f,L)
        every put(a := [], f(!L))
        return a
    end

This is similar to what ListPDCO does, without co-expressions. (Note
that, if you want to use ListPDCO, you should call it with the 2nd
argument of *L, since the default is 'only' a max of 100 results
from the expression in argument 1 [assuming you don't want L to be
forced to be less than 100 in length].)

I suppose you may want to do it in place, instead of having to run:

    L := mapFun(f, L)

right?  An ugly solution would be:

    procedure mapFun(f,L)
        every L[i := 1 to *L] := f(L[i])
    end

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

Well, you could customize the above approaches easily enough to include
extra arguments to f, or generalize the approach to use Closures and
the invoke() procedure provided along with the Closure class.

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

Reply via email to