From: Paul Brannan Date: 2002-02-06T04:48:10+09:00 Subject: Re: Call/CC and Ruby iterators. On Wed, Feb 06, 2002 at 03:20:46AM +0900, Thaddeus L Olczyk wrote: > Reading about call/cc in Scheme I get the impression that it is very > like Ruby's iterators. > Not being an expert in others I thought I would ask. I am not a scheme programmer, but... I think Scheme's lambda is like Ruby's iterators (or more precisely, it is like Ruby's procs/blocks). For example, if I write the following: (define (each lst f) (define (each-helper lst) (if (not (null? lst)) (begin (f (car lst)) (each (cdr lst) f)))) (each-helper lst) lst ) then the following Scheme code: (each '(1 2 3) (lambda (x) (display x) (newline))) is equivalent to the following Ruby code: [1, 2, 3].each { |x| puts x } I think Scheme's call/cc is like Ruby's callcc (or, to be more precise, mzscheme's let/cc is like Ruby's callcc). If I write: (define (foo f) (display "here!") (newline) (f) (display "you should not see this message") (newline) ) (call/cc foo) then this is equivalent to: def foo(f) puts "here!" f.call() puts "you should not see this message" end callcc { |cc| foo(cc) } Any thoughts? Paul