From: Mike Gold Date: 2008-10-02T03:43:57+09:00 Subject: Re: ruby1.9 block scope Daniel DeLorme wrote: > Mike Gold wrote: >> Yukihiro Matsumoto wrote: >>> Yes, but >>> >>> * Class.new and define_method is a rather rare examples, of which >>> non-block counterpart introduce new scopes. >> >> But it's not a rare example for me. It's a great solution to an >> otherwise tangled problem. When I have more time I can post some code >> if my example is not convincing. > > Yes, I would love to see some non-contrived example code. I don't use > define_method very often and I have hardly ever used Class.new, > certainly not with several levels of nested blocks. The common case for > which I *would* like to use this suggested featured is something like > this: Because you've hardly ever used Class.new, and therefore are probably not familiar with run-time generated classes which present a given binding as different views to external onlookers, then you won't appreciate what I have to say. To you everything is blub, and you wonder why non-blub things are necessary. It's a paradox, that you need to understand before you can understand. See http://www.paulgraham.com/avg.html The strategy I've described comes from Lisp. And it's awesome. In fact I think my example does suffice. You just need to imagine it being using on a slightly larger scale. As I said previously in this thread, "it would be convoluted to create all new scopes each with instance variables pointing back to the places I just came from. The code would be Java-like: reams of scaffolding which serve no end except to compensate for a missing language feature." Do you have a response to that? Please don't repeat your argument yet again; instead, try to understand what I've said. > 1 collection.each do |element| > 2 changed = true if element.change > 3 end > 4 do_something if changed > > Are you really saying that upon reading line 4 you have to backtrack to > line 2 in order to understand this code? Yes, I backtracked just now, before I read your last sentence above. I checked to be sure that 'changed' means a local variable. I have to do this with every variable in arbitrarily long scopes. You are thinking in terms of small examples, but I am thinking about large ones. > Far from a monster of O(n^2) complexity, It is O(n^2) complex because it requires a backtrack for each case. I like to be certain what code does. I will always backtrack in order to be certain. > this is the kind of code that > most programmers would expect to work. Except it doesn't, and if I have > to hazard a guess I would say that 90% of ruby newbies have run into > that gotcha. You did not address my counterpoint to your argument here. You just repeated your argument. -- Posted via http://www.ruby-forum.com/.