I don't know you're getting much benefit from the apparent
contiuationess of this so much as the captured binding. I think you
get the same effect from something like the following
yeah, we were calling it a "poor man's continuation" when we were
hacking on it. it's not really a continuation, yet it is a thing which
allows you to continue. (so to speak.)
To Giles: no this is not a continuation, I have however never been up
to the task to understand continuations, so unfortunately I cannot
really answer your questions.
OTOH Why use the complicated stuff if the simple does? Or do you have
a hidden agenda ;).
Actually I hacked on it some more and ended up with a much simpler
version, no continuations or bindings, much easier to work with.
http://pastie.caboo.se/102939
It just creates an object which stores stuff, basically.
I'm curious though about the difference between a continuation and a
proc you call manually when you want to continue with it. I had a book
somewhere that explained what callcc is really for, it showed how to
use call/cc in Lisp, I think Scheme, but I'm not sure where I left it.
Actually I think it was "The Scheme Programming Language."
There seems to be a problem with reopen too, I guess I fixed that, I
have changed the name from @continuation to closure.
What do you think about this version?
------------------------- 8< ----------------------------
require 'tempfile'
def closure
file = Tempfile.new("irb_tempfile")
lambda do
system("vim #{file.path}")
eval(file.read)
file.rewind
end
end
def vi
(@closure = closure).call
rescue => error
puts error
end
def reopen
@closure.call if @closure
rescue => error
puts error
end
I think the file.rewind might not be necessary any more. I think
refactoring it into a method like that was a good idea. reopen was
kind of a hack in the original, the more fully worked-out version will
automatically reopen if you created a file (and will create different
buffers if you use different editors, brag brag brag) but I think you
could accomplish very much the same thing if you combine #vi and
#reopen like this:
def vi
(@closure ||= closure).call
rescue => error
puts error
end
···
--
Giles Bowkett
Blog: http://gilesbowkett.blogspot.com
Portfolio: http://www.gilesgoatboy.org
Tumblelog: http://giles.tumblr.com/