From: Shouichi KAMIYA Date: 2012-02-27T11:44:11+09:00 Subject: [ruby-core:42966] [ruby-trunk - Feature #6073] Proposal of extending syntax of for loop Issue #6073 has been updated by Shouichi KAMIYA. Hi, Shugo Maeda wrote: > I think it's good to support both each and map/flat_map. > It may be possible to use yield instead of do/;/newline when using map/flat_map. > > # use each > for i in obj > ... > end > > # use map; yield is not a block call > for i in obj yield > end > > # use each; yield is a block call > for i in obj > yield i > end > for i in obj do yield i end > for i in obj; yield i end > > It might be too confusing, though. Though supporting both each and map/flat_map makes code simpler but, I'm not completely sure if it's a good idea. I think we've got to get more people involved and discuss. About the syntax, I don't come up with better syntax right now. ---------------------------------------- Feature #6073: Proposal of extending syntax of for loop https://bugs.ruby-lang.org/issues/6073 Author: Shouichi KAMIYA Status: Open Priority: Normal Assignee: Category: Target version: Hi, I propose to extend syntax of for loop which allows us to write multiple loop with guard easily. This extension is inspired by Scala. Here is a example for i in 1..4 when i % 2 == 0 j in 5..8 when j % 4 == 0 puts "#{i}, #{j}" end Above code is same as following code. for i in 1..4 if i % 2 == 0 for j in 5..8 if j % 4 == 0 puts "#{i}, #{j}" end end end end I already implemented this syntax and attached a patch. What do you think about this syntax guys? Thank you, Shouichi -- http://bugs.ruby-lang.org/