Functionality like the SAVE statement in Fortran?

Simple example of a closure:

function create_counter()
    count = 0
    return function()
        count += 1
        return count
    end
end

counter = create_counter()

Perhaps like this (untested)?

function find_interval(t::Float64, ts::Vector{Float64})
  i = 1
  return function result(t::Float64, ts::Vector{Float64})
    while !(ts[i] < t < ts[i+1])
      if t > ts[i+1]
        i += 1
      else
        i -= 1
      end
    end
  end
end
5 Likes