From: Caleb Clausen Date: 2010-05-30T20:14:15+09:00 Subject: Re: Inject Loop Syntax On 5/29/10, Intransition wrote: > I wonder if any other languages have any sort of "multiplicative > operation" operator. I was thinking about this today b/c sometimes one > has to use a block where it would read better if it could be avoided. > For example: > > [:a, :b, :c].each do |x| > define_method("#{x}?") do > instance_variable_get("@#{x}") > end > end > > I completely made this up off the top of my head, so ignore what it > actually does. The point is rather it would be cool if the loop could > described without encasing the code, something like: > > define_method("#{x}?") do <-(x)[:a, :b, :c] > instance_variable_get("@#{x}") > end Maybe you want something like python's array comprehensions? This is one of the few areas where python really shines in comparison to ruby. define_method("#{x}?") instance_variable_get("@#{x}") end for x in [:a, :b, :c] The problem I see with this is that x is a local variable, but that fact won't be apparent to the parser/lexer until it gets to the end of the expression and sees the for keyword. Not sure how that could be solved in a way that's at all elegant.