On Tuesday, February 3, 2015 at 1:11:36 PM UTC-5, Peter Simon wrote:
>
> I saw a suggestion from Miles Lubin in 
> https://groups.google.com/forum/#!topic/julia-opt/z8Ld4-kdvCI for 
> avoiding redundant calculations that appeared to involve saving state 
> between function calls, and I wonder what is the standard Julian way to do 
> this.  I'm asking here because this seems to be a general Julia question. 
>  In Matlab I would use a "persistent" variable.  What is the corresponding 
> idiom in Julia?  Closures?  Or something else?
>

I suppose you could simulate this with a functor object.  That is, you 
define a type that contains fields for the state you need to save, and 
overload call(::MyType, args...) so that you can call your type as a 
function.   (This is a new feature in Julia 0.4.)

(You can probably also use monads if you want to go all functional...)

Reply via email to