I mean something like this:

function f(x, state)
  # do something with x and state
end

type FunctionWithState
  state
end

call(fs::FunctionWithState, x) = f(x, fs.state)


Now write call(fs, x) wherever you would have written f(x).


On Fri, Aug 15, 2014 at 2:37 PM, Neal Becker <[email protected]> wrote:

> By closure I believe you mean a function that returns a function which
> binds the
> 2nd argument of the function F.
>
> For example:
>
> function bound_phase_noise (spec::phase_noise_spec)
>     function B (f)
>         return compute_phase_noise_spec (spec, f)
>     end
> end
>
> But I don't know what you mean by the 2nd option below:
>
> Stefan Karpinski wrote:
>
> > The approaches that occur to me immediately are that you can either
> > explicitly pass state or use a closure that closes over the state you
> need
> > to update. Another option would be to represent your function as an
> object
> > and use a generic function to apply that object to its argument.
> >
> >
> > On Fri, Aug 15, 2014 at 2:20 PM, Neal Becker
> > <[email protected]> wrote:
> >
> >> I'm trying to do numerical integration.  I want a function that has
> state
> >> information.
> >>
> >> Let's say I'm trying to integrate some function F over x.  In addition,
> F
> >> has
> >> some state
> >>
> >> function F (x, state) = <do something with x and state>
> >>
> >> In python (and in c++), one way is to make F a class (which can have
> >> state), and
> >> overload the function call operator.  Then this can be passed to the
> >> numerical
> >> integrator.
> >>
> >> But in julia, we can't overload the function call operator, so I don't
> >> know how
> >> to proceed.  Essentially, what we need is to transform the function F by
> >> binding
> >> one of it's arguments.
> >>
> >> What would you suggest here?
> >>
> >>
>
>
>

Reply via email to