Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Why does Ruby have callcc?

Reply
Thread Tools

Why does Ruby have callcc?

 
 
Jim Bob
Guest
Posts: n/a
 
      08-06-2003
I understand, in a woozy sort of way, what callcc does. What I
don't understand is what it's really good for, and furthermore, what
it's doing in Ruby.

It seems like all the explanations of callcc, in its various
implementations, stick to pretty simple examples, and almost always with
the proviso "you could more easily do this another way, but...". The
exception might be with regard to Scheme, which, I guess, lacks a
catch/throw-like mechanism, so that callcc might be the best way to
escape from a deeply nested loop. Ruby, though, obviously has catch and
throw.

With some other languages, I wouldn't think much of the inclusion of
such an apparently abstruse feature. But, from my reading of this list,
it seems like Matz is pretty conservative about adding features that
won't get used, for whatever reason. I can only guess that he'd be twice
less likely to add features that don't get used and are just plain
*weird*, as callcc seems to me even after having spent no short amount
of time trying to wrap my thick head around it.

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?
 
Reply With Quote
 
 
 
 
Harry Ohlsen
Guest
Posts: n/a
 
      08-06-2003
Jim Bob wrote:

> 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'd be interested to read about some real-world examples where people have used callcc, not just to try it out, but because it was the "right" way to do something (for efficiency, or code brevity or whatever reason).

So, as opposed to the examples we find on some of the Ruby web pages, which are, as Bob said, effectively tutorials on how one *might* use callcc, can someone give us some examples of production code they've written that uses continuations?



 
Reply With Quote
 
 
 
 
Brian Candler
Guest
Posts: n/a
 
      08-06-2003
On Wed, Aug 06, 2003 at 08:38:25PM +0900, Harry Ohlsen wrote:
> I'd be interested to read about some real-world examples where people have
> used callcc, not just to try it out, but because it was the "right" way to
> do something (for efficiency, or code brevity or whatever reason).


I think Seaside/Borges falls into this category.

I haven't had a chance to use it in anger, but I think the idea is that
continuations can represent CGI session state; you code can be written in a
linear fashion (e.g. display page, fetch response, display next page, fetch
next response etc) without any explicit session maintenance. Furthermore, by
retaining continuation objects which represent earlier pages, it will work
even if the user clicks 'back' in their browser and re-enters data in a
previous form.

I'd have a number of concerns in a practical application - I'd want old
continuations to expire and be garbage-collected so that they don't cause
infinite memory growth - but otherwise it sounds like a great way to write
web applications.

Regards,

Brian.

 
Reply With Quote
 
Harry Ohlsen
Guest
Posts: n/a
 
      08-06-2003
Brian Candler wrote:

> I think Seaside/Borges falls into this category.


Do you have any URLs for this? I did a quick Google, but found a Smalltalk site. As far as I can tell, Seaside was some Ruby code that ended up in Smalltalk as Borges?

H.




 
Reply With Quote
 
Robert Klemme
Guest
Posts: n/a
 
      08-06-2003

"Harry Ohlsen" <(E-Mail Removed)> schrieb im Newsbeitrag
news:(E-Mail Removed)...
> Jim Bob wrote:
>
> > 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'd be interested to read about some real-world examples where people

have used callcc, not just to try it out, but because it was the "right"
way to do something (for efficiency, or code brevity or whatever reason).

Standalone iterators. Jim Weirich posted some code here about 1 or 2
months ago. Maybe you'll find it here: http://onestepback.org/

> So, as opposed to the examples we find on some of the Ruby web pages,

which are, as Bob said, effectively tutorials on how one *might* use
callcc, can someone give us some examples of production code they've
written that uses continuations?

http://www.rubygarden.org/ruby?ContinuationExplanation

robert

 
Reply With Quote
 
Brian Candler
Guest
Posts: n/a
 
      08-06-2003
On Wed, Aug 06, 2003 at 09:15:59PM +0900, Harry Ohlsen wrote:
> Brian Candler wrote:
>
> > I think Seaside/Borges falls into this category.

>
> Do you have any URLs for this? I did a quick Google, but found a
> Smalltalk site. As far as I can tell, Seaside was some Ruby code that
> ended up in Smalltalk as Borges?


No, it was the other way round Anyway,

http://raa.ruby-lang.org/list.rhtml?name=borges links to
http://segment7.net/ruby-code/borges/borges.html

which in turn links to information on Seaside. Also search for 'seaside' or
'borges' at http://ruby-talk.org/ as it's been discussed before.

ISTR it uses Webrick, and since that's now part of ruby-1.8.0, it should be
easier to install.

Cheers,

Brian.

 
Reply With Quote
 
Brian Candler
Guest
Posts: n/a
 
      08-06-2003
On Wed, Aug 06, 2003 at 10:25:31PM +0900, Brian Candler wrote:
> ISTR it uses Webrick, and since that's now part of ruby-1.8.0, it should be
> easier to install.


Just installed, it was a doddle: you need 'installpkg-0.0.1' and
'borges-0.2.0', then

cd /usr/local/share/examples/ruby/borges
ruby counter.rb

and then point your web browser at
http://yourmachine:7000/counter

It doesn't work with 'back' in the way I thought though; if I increment to
4, click back a few times, then click 'inc' on 1, I still get 5. But I have
a lot to learn about this framework

Also I couldn't get pagecounter.rb to work as-is; you need to change
"counter2" to something which doesn't end with a number, e.g. "pagecounter"
because a request to http://foo:7000/counter2 seems to be interpreted as
'counter'.

Cheers,

Brian.

 
Reply With Quote
 
Yukihiro Matsumoto
Guest
Posts: n/a
 
      08-06-2003
Hi,

In message "Re: Why does Ruby have callcc?"
on 03/08/06, Dan Debertin <(E-Mail Removed)> 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.

The official answer is "why not". I provide the features, you use
them.
matz.

 
Reply With Quote
 
Ben Giddings
Guest
Posts: n/a
 
      08-06-2003
On Wed August 6 2003 11:34 am, Yukihiro Matsumoto wrote:
> I provide the features, you use them.


Heh, best quite ever.



 
Reply With Quote
 
Julian Fitzell
Guest
Posts: n/a
 
      08-06-2003
Brian Candler wrote:
> On Wed, Aug 06, 2003 at 08:38:25PM +0900, Harry Ohlsen wrote:
>
>>I'd be interested to read about some real-world examples where people have
>>used callcc, not just to try it out, but because it was the "right" way to
>>do something (for efficiency, or code brevity or whatever reason).

>
>
> I think Seaside/Borges falls into this category.


Yup, absolutely.

> I haven't had a chance to use it in anger, but I think the idea is that
> continuations can represent CGI session state; you code can be written in a
> linear fashion (e.g. display page, fetch response, display next page, fetch
> next response etc) without any explicit session maintenance. Furthermore, by
> retaining continuation objects which represent earlier pages, it will work
> even if the user clicks 'back' in their browser and re-enters data in a
> previous form.


That's a pretty decent summary.

> I'd have a number of concerns in a practical application - I'd want old
> continuations to expire and be garbage-collected so that they don't cause
> infinite memory growth - but otherwise it sounds like a great way to write
> web applications.


They certainly are expired and GC'ed. And you can control how many
continuations you keep around for a particular session. You can also
control how long sessions hang around - or you could swap them to disk
and keep them forever. Again, this is all speaking about the Smalltalk
version since I haven't seent he Ruby code in quite some time and it may
well be true that you have less control of these things there.

If anyone's interested in discussing Seaside or the benefits of
continuations further, the Seaside (Smalltalk people but others welcome)
community is all on the mailing list which you can sign up for at:

http://lists.squeakfoundation.org/listinfo/seaside

Cheers,

Julian


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
what does "execfile" mean within profiler output and why does it not have a attached line number Rahul Python 4 04-07-2009 03:19 AM
Why does String have to_str and Integer have to_int? Nanostuff Ruby 9 03-01-2007 09:44 PM
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM



Advertisments