From: Dan Sugalski Date: 2002-01-03T12:18:54+09:00 Subject: [ruby-talk:30102] Re: Parrot (was re, Python and Ruby: a comparison) At 11:47 AM 1/3/2002 +0900, Avi Bryant wrote: >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. Fair enough. If there's nothing special in the behaviour of the block then it's just a matter of prototyping so the function goes in the right slot. (Which is what it looks like to me, but that doesn't necessarily mean much) The languages will need to make sure they have some form of syntax to make it possible, but luckily for me (and everyone else) language design issues are in other people's hands. If there's something special about the block, then I need to do more reading, and doc pointers would be greatly appreciated. Dan --------------------------------------"it's like this"------------------- Dan Sugalski even samurai dan@sidhe.org have teddy bears and even teddy bears get drunk