From: Rich Kilmer Date: 2002-01-03T11:13:04+09:00 Subject: [ruby-talk:30093] Re: Parrot (was re, Python and Ruby: a comparison) > -----Original Message----- > From: Dan Sugalski [mailto:dan@sidhe.org] > Sent: Wednesday, January 02, 2002 6:50 PM > To: ruby-talk ML > Subject: [ruby-talk:30087] Re: Parrot (was re, Python and Ruby: a > comparison) > > > At 05:02 AM 1/3/2002 +0900, Erik B�gfors wrote: > >On Tue, 2002-01-01 at 21:07, Dan Sugalski wrote: > > > >* How will blocks be used from other languages that doesn't > do blocks?? > > > > > > You're talking semi-standalone chunks of code that can be > executed as a > > > sort of anonymous subroutine or method, right? Perl and > Python both have > > > those. If a language doesn't have 'em, then it can't call > into a function > > > that requires one. Not much to be done about that. (Though I > don't see it > > > as a problem--the inter-language calling conventions define > how you call > > > from one language to another, they don't require any language > to actually > > > implement everything the convention allows) > > > >Well. The way blocks and iterators are used in ruby is not like it is > >in perl (I don't know python very well but I don't know of anything like > >that. > > > >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. :) > > For this example, the code in the {} would get turned into an anonymous > function, which the interpreter would then execute for each > element of the > list myObject.each generates. One issue is that Ruby's blocks carry with them the context of where they were called so if you had this: x = 2 myObject.each { |p| puts p*x} Is that possible with Parrot? Can your functions be defined with a local scope of some context? > > As far as the interpreter's concerned, the steps are: > > generate small anon function > call myObject's each method with anon function as parameter > > Now, of course the each method creates an array of elements and iterates > across them, but that's all within Ruby code. The function called doesn't > have to be Ruby code--it could be perl or python or scheme if you wanted. >