IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New Call/CC
So I'm reading [link|http://www.ccs.neu.edu/home/dorai/t-y-scheme/t-y-scheme.html|Teach Yourself Scheme in Fixnum Days] and I'm looking at the section on [link|http://www.ccs.neu.edu/home/dorai/t-y-scheme/t-y-scheme-Z-H-15.html#node_sec_13.1|call/cc]. The simple example given is as follows:

\n(+ 1 (call/cc\n       (lambda (k)\n         (+ 2 (k 3)))))\n

Which ends up passing (+ 1 []) as the parameter into the lambda method. The lambda method then evaluates (k 3) as (+ 1 3) and returns 4 -- totally ignoring the (+ 2 ) part.

While I understand what it does, I don't understand what it's purpose is other than as a way to escape a function. Does anyone have any real world examples that help explain how call/cc is used?

Thanks,
John
New Completely and utterly OT
I hated lisp and friends at university.

It made me ((((((scream))))))

Ba-dum TISH.

Thangyew, thangyew. I'll be here all week.


Peter
[link|http://www.debian.org|Shill For Hire]
[link|http://www.kuro5hin.org|There is no K5 Cabal]
[link|http://guildenstern.dyndns.org|Blog]
New Lots of Idiotic Stupid Parentheses
And the reason Emacs was invented. Well, paren-matching mode, at least.
Regards,

-scott anderson

"Welcome to Rivendell, Mr. Anderson..."
New Usual suspects
Stealing from Noel Welsh's [link|http://schematics.sourceforge.net/scheme-london/continuations.html|Continuations]:

Continuations are useful wherever we want to alter the control flow of a computation. Examples include:
  • Loops
  • Coroutines
  • Exceptions, including exceptions that allow you to resume the computation having fixed the problem
  • Backtracking as in Prolog
  • Non-deterministic programming
  • Cooperative Threading


In the case of backtracking, think of things like regular expression searches where you need to traverse up and down (sideways and backwards) through text to find matches. Continuations help in keeping things moving forward.

In the case of coroutines, think of more sophisticated for-each type loops, where the iteration calls a feeder process to supply the iteration.
New Re: Call/CC
One real world example ... turning internal interators into external iterators. See [link|http://jimweirich.umlcoop.net/articles/same_fringe/index.html|http://jimweirich.um...fringe/index.html] for details.

Another real world example ... programming web page navigation (supporting the use of the back button) in a linear manner. See Avi Bryant's work with Seaside (Smalltalk version -- [link|http://beta4.com/seaside2/|http://beta4.com/seaside2/]) and related work with Borges (Ruby version -- [link|http://segment7.net/ruby-code/borges/borges.html|http://segment7.net/...orges/borges.html]).

I've also written some stuff on Continuation Passing Style, tail recursion and call/cc at [link|http://onestepback.org/index.cgi/Tech/Programming/Kata|http://onestepback.o.../Programming/Kata], although this is probably much the same stuff that you are getting from your Scheme book.
--
-- Jim Weirich jweirich@one.net [link|http://onestepback.org|http://onestepback.org]
---------------------------------------------------------------------
"Beware of bugs in the above code; I have only proved it correct,
not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)
New Duplication
Hmmm ... I took a peek at the web page for "Teach yourself scheme". Cool. I see that they also solve the same-fringe problem. Oh well. The Seaside stuff is still interesting.

BTW, the (amb) function in the next chapter looks interesting. I remember someone doing a similar thing in FORTH, except it wasn't "angelic" (if I'm using the term properly).
--
-- Jim Weirich jweirich@one.net [link|http://onestepback.org|http://onestepback.org]
---------------------------------------------------------------------
"Beware of bugs in the above code; I have only proved it correct,
not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)
New Self-modifying code? That is non-angelic - and good :)
-drl
New Thanks
The links were helpful. Once I get the call/cc thing down, I can go on to trying to figure out amb!

Thanks again,
John
     Call/CC - (johnu) - (7)
         Completely and utterly OT - (pwhysall) - (1)
             Lots of Idiotic Stupid Parentheses - (admin)
         Usual suspects - (ChrisR)
         Re: Call/CC - (JimWeirich) - (2)
             Duplication - (JimWeirich) - (1)
                 Self-modifying code? That is non-angelic - and good :) -NT - (deSitter)
         Thanks - (johnu)

¡Despierte, Estupido-idiota!
86 ms