From: gabriele renzi Date: 2004-10-21T20:14:19+09:00 Subject: Re: Python vs. Ruby (Re: A concise description of Ruby?) Florian Gross ha scritto: disclaimer: I think all this things can be done in ruby via different approaches, just trying to show the one in the P-language :) >> (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. well, the only things I recall ATM are: foo= module.module.object.foo people.sort(key=person.get_id) the descriptors tricks such as c.meth = function.__get__(c) staticmethod/classmethod and the strange things that can be done with function attributes (think of __doc__, just to name one). I'm not a good enough pythoneer (nor rubyist, FTM ) to really understand all of this :) >> > zope iirc, and shows how __mro__ makes it simple to linearize the >> hierarchy> > > > __mro__? the attribute that specifies how to search in ancestors for an attribute (Method Resolution Order, oh, the love for acronyms ;). There is a paper about the default behaviour: http://www.sourcekeg.co.uk/www.python.org/2.3/mro.html but you can ovverride it by yourself if you fell that it is useful >> 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? well, it seem so :) For example, you can build singleton classes with class A(object): __metaclass__=SingletonMeta or you can build a class hierarchy where you can't modify objects' attributes, or define an Interface metaclass whose' instances are interfaces that behave in a java-like fashion. The gnosis.magic package has a lot of cool metaclass usages. In ruby we mostly do this via mixins. I can't tell you if there are things doable with oneapproach that are not possible with the other, but I guess no. Pythoneers use to say that everything doable with metaclasses was possible withouth them, but now it is more simple. >> 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. is this really done inline? I got the feeling it would build the array anyway. Nice to hear the I'm wrong :) > I'm also pretty sure that we can do these chains without using > Continuations. sure, and in fact I advocate having someting like that builtin. I talked about the callcc thing just to handle lazy sequences in the general case.