From: Florian Gross Date: 2004-10-21T10:24:17+09:00 Subject: Re: Python vs. Ruby (Re: A concise description of Ruby?) gabriele renzi wrote: > Nikolai Weibull ha scritto: >> * gabriele renzi [Oct 21, 2004 00:40]: > self.var , I mean is a var in self , what @ is supposed to mean?? > global var > > *this* is descouraging! @ is used in rogue likes (like NetHack) to represent your*self*. Not sure if this is why matz choose that symbol, but it sure makes sense. :) > (pythoneers do really strange tricks with function objects that we just > would never think of.. I'd like some more syntax sugar for Proc#call > anyway ) Any samples? Sounds interesting. > zope iirc, and shows how __mro__ makes it simple to linearize the > hierarchy> __mro__? > they're basically a different concept, if you're talking of singleton > classes. Python's metaclasses allows you to build object hierarchy's > where Klass.class != Class. > (You can do the same in ruby, with different approaches, usually, but > somewhat they seem cool) Is this used for anything else than starting with a BlankSlate? > one iteration unifies both filtering and transformation (I really think > we should have something like that in ruby :/ ) > Oh, and nowadays we have generator expressions, so we can even have lazy > generators done this way, while in ruby you have stuff like zip that > would end up as a memory hog (here you show generator.rb, but call/cc > performance is bad) Also note that Enumerable#zip can take a block. In that case it doesn't create the intermediate Array. I'm also pretty sure that we can do these chains without using Continuations. Maybe with nested blocks like this: class FilteredEnumerable def initialize(enumerable, &filter) @enumerable, @filter = enumerable, filter end def each(&block) @enumerable.each do |item| block.call(item) if @filter.call(item) end end end module Enumerable def filter(&block) FilteredEnumerable.new(self, &block) end end languages = %w{ruby perl python lisp smalltalk} languages.filter do |language| language.size != 6 end.each do |language| p language end But I think in that example I would use this anyway: languages.filter do |language| next if language.size == 6 p language end Maybe the above technique works better for more complex cases. Regards, Florian Gross