I have 3 invites. First people to answer these questions correctly gets one (only answer one question):
* What is the integral of "x + 2"?
* How would you implement coroutines with continuations? (Just a very brief description is fine) (edit, if nobody answers this in a few min I'll just invite people)
You can implement coroutines with continuations with two functions:
def resume
callcc do |cc|
$current = self
@caller = cc
@resumer.call
end
end
def self.yield
callcc do |cc|
$current.resumer = cc
$current.caller.call(cc)
end
end
`resume` (on a coro) will store what coroutine we're entering (globally) and the caller-continuation (so we know where to go to after Coro.yield). It will then invoke the `resumer`-continuation. `Coro.yield` will store the `resumer`-continuation on the coro (so we know where to go to after `.resume`).
You need something to kick it off though. The simplest way is probably to use `(@resumer || @code).call`.
memoization, basically remember the results of methods that have a particular parameter values. so it does not actually execute the method it retrieves the remembered value
* What is the integral of "x + 2"?
* How would you implement coroutines with continuations? (Just a very brief description is fine) (edit, if nobody answers this in a few min I'll just invite people)
* What is memoization?