From: avi@...4.com (Avi Bryant) Date: 2002-01-03T11:47:00+09:00 Subject: [ruby-talk:30099] Re: Parrot (was re, Python and Ruby: a comparison) Dan Sugalski wrote in message news:<5.1.0.14.2.20020102183407.01c57fa8@pop.sidhe.org>... > >for example: > >myObject.each { |x| puts x } > > > >How would that code look in perl(6) or python?? > > An interesting question, but from the interpreter's standpoint not an > important one. :) > If the iterators are methods that take a code chunk, you just call them > with the code chunk. For example: > > my $sub_ref = sub {print $_, "\n"}; > my $Obj = GetRubyObject(); > $Obj.each($sub_ref); > > would be the perl 6 equivalent, I think. It's somewhat more complicated than that, unfortunately - in Ruby, a block is passed to a method separately from any other arguments. There is a difference between myObject.each() {|x| puts x} and myObject.each(proc{|x| puts x}) This last is the equivalent of the perl code above, but it is not what the each method expects. Yes, this is just a calling convention issue, but you should be aware that Ruby has unusual calling conventions: in particular, each method can optionally be given a block (closure/code-chunk/anonymous sub) completely separately from whatever other parameters it takes. It can also take closures as normal parameters, but the block is treated specially. Somehow, you'll need to flag it as such from Perl/Python. Avi