First, are you looking for anonymous functions? http://docs.julialang.org/en/latest/manual/functions/#anonymous-functions
Second, I suspect Grid.jl already does exactly what you're asking re interpolation. https://github.com/timholy/Grid.jl --Tim On Tuesday, February 25, 2014 02:34:11 AM Marek Gagolewski wrote: > Dear all, > > Is it possible in Julia to define a C++-like operator() for its > "struct-like" composite types (defined with type....end)? Thanks to such a > method, one may treat an object as a function. > > Here's a GitHub gist illustrating what I'm trying to achieve: > https://gist.github.com/gagolews/9206364 > > In other words, I'd like to create a function which has some associated > (deep copied) objects with it, by calling new_function = > create_function(data) and such that new_function does not rely on > dataanymore (at least from its caller/user perspective). I tried to play > with Julia's macros, but I'm quite sure it's not the case here. > > My inspiration is R's approxfun() which returns a function object that > interpolates (linearly) a given set of points in 2D. I'm trying to develop > a similar tool in Julia, but I cannot move on because of this issue. > > > (x <- seq(0, 1, length.out=10)) > > [1] 0.0000000 0.1111111 0.2222222 0.3333333 0.4444444 0.5555556 0.6666667 > [8] 0.7777778 0.8888889 1.0000000 > > > (y <- x^2) > > [1] 0.00000000 0.01234568 0.04938272 0.11111111 0.19753086 0.30864198 > [7] 0.44444444 0.60493827 0.79012346 1.00000000 > > > f <- approxfun(x, y) > > f(0.35) > > [1] 0.1240741 > > > y <- sqrt(x) > > f(0.35) # no change (y is stored "within" f) > > [1] 0.1240741 > > > # more precisely it is a new environment ("hash table") > > # ASSOCIATED with the function > > ls(envir=environment(f)) > > [1] "f" "method" "x" "y" "yleft" "yright" > > > f # one source code, but operates on different data > > function (v) > .approxfun(x, y, v, method, yleft, yright, f) > <bytecode: 0x2ff5fb8> > <environment: 0x320a7d0> > > Anybody? > > Best regards, > Marek Gagolewski > http://gagolewski.rexamine.com
