From: Dan Sugalski Date: 2002-01-03T08:49:37+09:00 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. 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. >that code differs alot between the languages. Ruby uses alot of >iterators and I don't see how they can be used from other languages. 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. >I'm sure it's solvable, I just don't know how? With properly defined calling conventions, it's pretty simple. No different than writing C code that gets a function pointer from a Fortran object module and executing it, say. > > >BTW, it's VERY nice to see a parrot designer here on the ruby-list :) > > > > I'm taking notes and trying to stay out of the way for now. :) > >Why?? I think ALOT of people here are interested. I know I am. Why? Because it's not directly related to Ruby as it is now. I'm a guest here, and I don't want to be rude about it. >btw, is perl6-internals the list for parrot-stuff?? Even if they are >ruby-questions?? perl6-internals is absolutely the list for all parrot-related things. (Even Ruby ones) The name's working on becoming a historical artifact, and at some point we may split things up so there's a generic parrot internals list and language-specific internals lists, but we're not there at the moment. Dan --------------------------------------"it's like this"------------------- Dan Sugalski even samurai dan@sidhe.org have teddy bears and even teddy bears get drunk