From: Daniel Waite Date: 2008-04-18T08:58:04+09:00 Subject: Re: When are lambdas needed? Joel VanderWerf wrote: > If the latter, then one answer is: when you need the program state that > is encapsulated in a block to persist outside of the method in which it > is used. For example, this happens in event-based frameworks: a setup > method in a client class registers lambdas as event handlers; the > framework doesn't need to know the classes or methods of the client > class, hence loose coupling. As a bonus, these handlers can refer to > shared program state (local variables) in the setup method. That's probably the clearest illustration I've ever read of when to use a block. Thank you. I hope others chime in, too, as I couldn't imagine programming without the "implicit usage" of blocks (e.g. each, select, collect, etc.) but have never used them for the purpose Joel described. I just got "done" designing a delivery system, and although I'm happy with it, I wonder if it could be done with blocks. (I re-read that statement and it sounds stupid: 'done with blocks'. I'll simply trust you see the absurdity of the statement and understand what I was trying to say...) -- Posted via http://www.ruby-forum.com/.