From: Dan Sugalski Date: 2002-01-03T11:21:16+09:00 Subject: [ruby-talk:30097] Re: Parrot (was re, Python and Ruby: a comparison) At 11:13 AM 1/3/2002 +0900, Rich Kilmer wrote: > > From: Dan Sugalski [mailto:dan@sidhe.org] > > 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? Sure. Parrot's got full closure support slated for inclusion. The block would be a little anonymous closure, so you'd have your lexical scope available. (Well, I suppose it could be a full continuation, or a coroutine block, as need be) Dan --------------------------------------"it's like this"------------------- Dan Sugalski even samurai dan@sidhe.org have teddy bears and even teddy bears get drunk