< :the previous in number
^ :the list in numerical order
> :the next in number
P :the previous artilce (have the same parent)
N :the next (in thread)
|<:the top of this thread
>|:the next thread
^ :the parent (reply-to)
_:the child (an article replying to this)
>:the elder article having the same parent
<:the youger article having the same parent
---:split window and show thread lists
| :split window (vertically) and show thread lists
~ :close the thread frame
.:the index
..:the index of indices
Jim Bob <invalid / invalid.com> writes:
> So, how'd it get there? Is there some killer use for callcc that I'm
> missing? Was it just for the "gee whiz" factor?
I can't explain the "how'd it get there" part; I'll leave that to Matz
and friends.
Continuations are great for any situation in which you not only need
to jump out of a context (multiple nested loops, etc.), but also get
back in to the same context you left. You can't do that with
catch/throw.
A good example of this is co-routines -- you need to save your state
in the first function, start the second one, then jump back to where
you were in the first, and so on. This example runs two iterators
simultaneously:
# Iterate simultaneously from a to b, and from b to a
def updown(a, b)
iter1, iter2 = ( a < b ? [a.method(:upto), b.method(:downto)] :
[a.method(:downto), b.method(:upto)] )
f, cc1, cc2 = nil
iter1.call(b) do |o|
callcc do |cc1|
f = o
cc2.call if(cc2)
iter2.call(a) do |i|
callcc do |cc2|
yield f, i
cc1.call if(cc1)
end
end
end
end
end
Of course, one can't discount the considerable "Gee wiz" factor of
continuations ;-).
Dan
--
/^Dan Debertin$/ |
airboss / nodewarrior.org |
www.nodewarrior.org |