Why not Ruby -- and what else

I have just found the following from http://en.wikipedia.org/wiki/Iterator#Implicit_iterators =================================== Some object-oriented languages such as Perl, Python, C#, Ruby and later versions of Java and Delphi provide an intrinsic way of iterating through the elements of a container object without the introduction of an explicit iterator object. An actual iterator object may exist in reality, but if it does it is not exposed within the source code of the language. Implicit iterators are often manifested by a "foreach" statement (or equivalent), such as in the following Python example: for value in iterable: print value Or other times they may be created by the collection object itself, as in this Ruby example: iterable.each do |value| puts value end ================================== For any weird reason, Ruby's famous PLP (principle of least surprise) translates by me to PHC (principle of highest confusion). Like if adding colours, fonts, shapes, makes a better visual design. Still, instead of Python's version, my favorite language would say: (1) syntactic magic version traverse container with item console.write item or through container with item console.write item Which I find both more obvious and explicit. (2) OO version (see Io language for worthful source of inspiration) container.traverse(item, console.write item ) The latter case intends to semantically express the fact that 'traverse' (or 'through', or whatever) is a method that takes an item _name_ and a code block as parameters. Actually, if consistency really counts, it should read: container.traverse("item", console.write item ) or even container.traverse("item", "console.write item" ) Which is ugly, isn't it? The reason why I still prefere syntactic magic ;-) Or we could consider another possibility: (3) postfix version container traverse console write or container.traverse console.write that often simply gets rid of function parameter names -- usually. What happens to be on the data stack will be written out -- in this case: each item provided by traverse. Another view on the same thing: 'traverse' is a higher order function that takes 'console write' as parameter and feeds it with data to write out. Postfix notation is imo an endless source of elegant formulation -- as long as stack juggling can be avoided. Denis ------ la vita e estrany

On Wed, Apr 15, 2009, spir wrote:
I have just found the following from http://en.wikipedia.org/wiki/Iterator#Implicit_iterators
Please don't post free-form rambles here; although there are blue-sky ideas posted here, the focus should be on concrete proposals for changing Python. I don't even know what your point was, let alone any proposal. If you're just wanting to have a conversation about Python design philosophy, please use comp.lang.python. -- Aahz (aahz@pythoncraft.com) <*> http://www.pythoncraft.com/ Why is this newsgroup different from all other newsgroups?

On Wed, Apr 15, 2009, spir wrote:
I have just found the following from http://en.wikipedia.org/wiki/Iterator#Implicit_iterators
Please don't post free-form rambles here; although there are blue-sky ideas posted here, the focus should be on concrete proposals for changing Python. I don't even know what your point was, let alone any proposal. If you're just wanting to have a conversation about Python design philosophy, please use comp.lang.python. -- Aahz (aahz@pythoncraft.com) <*> http://www.pythoncraft.com/ Why is this newsgroup different from all other newsgroups?
participants (2)
-
Aahz
-
spir