On 2010-12-12 18:03, Adam D. Ruppe wrote:
foobar wrote:
D basically re-writes foreach with opApply into the ruby version
which is why Ruby is *BETTER*

You missed the point: there is no "Ruby version". They are the
same thing.

foreach to me is a redundant obfuscation

How can it be redundant? It's got the same elements the same
number of times.


rofl.copter.each |lol|
     spam
end


foreach(lol; rofl.copter)
     spam


Same elements, just reordered.


I don't know about the each() method itself. I've never written
one, but I suspect it is virtually identical to opApply too.

It's pretty similar. Say I reimplement the "each" method of the Array class then it could look like this:

class Array
    def each
        i = 0

        while i < length
            yield self[i]
            i += 1
        end
    end
end

"yield" will call the block that is passed to the method call.

--
/Jacob Carlborg

Reply via email to