From: "Ara.T.Howard" Date: 2005-06-05T06:37:11+09:00 Subject: Re: internal iterators in ruby On Sun, 5 Jun 2005, Charles Hixson wrote: > Geert Fannes wrote: > >> So, if I understand well, the problem with iterating over different >> enumerables synchronously has to do with the absence of a #rewind and >> #next method for enumerables. The Generator class solves this using the >> slow #callcc method and allows one to step through the Enumerable#each >> method, element by element. Wouldn't it be better if the enumerable >> required a #rewind and #next method and constructs the #each method out >> of these instead of doing the reverse using #callcc? >> Greetings, >> Geert Fannes. >> >> >> You code works only for arrays, but it's quite efficient. >> >> This works for all Enumerable types, is less efficient - and it's part >> of >> the std lib: >> >> http://www.ruby-doc.org/stdlib/libdoc/generator/rdoc/classes/SyncEnumera >> tor.html >> >> Know your standard libs... :-) >> >> Kind regards >> >> robert >> > This is one of the reasons that I feel that mixins should be inheritable. > What you really want to do is define a descendant of Enumerable that > implements those methods. > > I suppose that what one could do is define a new mixin, say > "TwoWayEnumerable" that implements the standard ops of a doubly linked list > (getting most of them by requiring Enumerable) and use that. Since it would > include the definition of Enumerable, it could be used whenever Enumerable > was needed, but it could also be used in other instances, such as the one > that you are proposing. > > But I still feel that inheriting from SuperModules would be nicer > syntactically. this limits you to sharing the functionality of exactly one mixin. the current implementation allows sharing of code from many mixins. class TwoWayEnumerable include Enumerable include SomeMoreNiftyMethods include EvenMoreFunctionality end ruby's single inheritence would preclude this as a possibility - at least it would be precluded from doing in a nice way syntactically. cheers. -a -- =============================================================================== | email :: ara [dot] t [dot] howard [at] noaa [dot] gov | phone :: 303.497.6469 | My religion is very simple. My religion is kindness. | --Tenzin Gyatso ===============================================================================