From: Chad Perrin Date: 2007-06-01T03:49:14+09:00 Subject: Re: Introducing the "it" keyword On Thu, May 31, 2007 at 09:49:49PM +0900, Brian Candler wrote: > > (1) > > with(v+1, x+2) { |a, b| > return a if a+b < 10 > } I think I like this one the most. > > (2) > > a = v+1 # or: a, b = v+1, x+2 > b = x+2 # > return a if a+b < 10 > > (3) > > local { > a = v+1 # or: a, b = v+1, x+2 > b = x+2 # > return a if a+b < 10 > } > > All these can be implemented without any language changes. . . . and I like that about all three of them. > > Now, if you could assign default parameters in blocks, you'd have another > option: > > (4) > > let { |a=v+1, b=x+2| > return a if a+b < 10 > } I understand what you're trying to accomplish here, and I find it an appealing idea as well -- but I think that diverges enough from standard Ruby syntax style that it would make things less readable. If you really want to use a let statement like that in Ruby, I think I'd prefer something more like creating a new block construct using let..in..end: let a=v+1, b=x+2 in return a if a + b < 10 end > > Having default values for block arguments would be a boon for other reasons, > including being able to rationalise some of the differences between the > various flavours of blocks, procs and methods. > > The main difficultly seems to be the ambiguity of '|' as an operator or the > end of a parameter list. Notice that a "let block" would avoid that problem nicely. The one line version might look something like this: let a=v+1, b=x+2 { return a if a + b < 10 } I also think it has a cleaner look in general than trying to cram the assignments between pipes at the beginning of the block. The way parameters are specified in do..end blocks works great for that, but once you start performing explicit assignments I don't think it works as well. Of course . . . all that aside, I'm not sure I want Ruby to be an OCaml with dynamic typing, either. I think connecting with() to a standard block works quite well enough, and doesn't threaten to turn Ruby into a different language entirely. -- CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ] McCloctnick the Lucid: "The first rule of magic is simple. Don't waste your time waving your hands and hopping when a rock or a club will do."