[Swift-devel] Call function.

Ben Clifford benc at hawaga.org.uk
Fri Aug 12 11:39:57 CDT 2011


What would be needed to write 'map' in swift(script) for use as a library 
function by other swift code? (rather than writing it in karajan or java)

It might look something like this: (standby for bleeding eyes on the first 
line)

(X out[]) map( (X)f(Y), Y inp[]) {
  foreach v,i in inp {
    out[i] = f(v);  // or equivalently out[i] = f( inp[i] );
  }
}

The above adds syntax for passing a function f which takes a value of type 
Y and returns a value of type X. f is invoked by juxtaposition rather than 
by an explicit call, though I think that is irrelevant for this message.

But for map to work for arbitrary 1-d arrays, X and Y need to be type 
variables of some kind, not actual concrete types.

We haven't discussed that at all in this thread, but I think it would be 
needed to do the above kind of thing. That's nothing particularly fancy 
though its another shift away from fortran-era types - C++ templates, java 
generics can both express this in some form, as can haskell.

Comments?

-- 
http://www.hawaga.org.uk/ben/




More information about the Swift-devel mailing list