From: "Mauricio Fernández" Date: 2002-10-04T17:28:48+09:00 Subject: Re: Specifying local and external block parameters (that old chestnut) On Fri, Oct 04, 2002 at 04:44:17PM +0900, Gavin Sinclair wrote: > From: "Mauricio Fern�ndez" > > > > > Thus, if 'a' and 'c' are regular parameters and 'b' is an external > variable, > > > then one could write > > > > > > collection.each do |a,:b,c| > > > ... > > > end > > > > I hereby claim authorship of any syntax derived from the use of > > the ':' prefix to indicate the scope of block parameters, based on > > [ruby-talk:52401]. All rights reserved. > > > > :-) > > Fair enough. Your royalty cheque is in the mail. Great! The first time in my life I do earn my very own money! Hehe. > > > or > > > > > > collection.each do |a,b,c| > > > external b > > > ... > > > end > > > > > > I'm not sure which of the above I prefer. One should optimize for the > common > > > case. > > > > I'd head towards ':'. Reason: less typing. > > Plus we're used to having '@' and '@@' to indicate scope (kinda), so it > > just makes sense for me. > > Exactly. > > > Local params would surely be more common, but marking them with ':' > > instead of the external ones has the additional advantage of not > > breaking any code out there. > > I disagree. Marking the external ones rather than internal ones is SO much > more sensible. Seeing a.each do |:x| everywhere is too ugly. Changes have > been made that break code before. How much code would it really break anyway? I do agree with you, really. I makes more sense to mark external. As I'm quite new to Ruby I thought backwards-incompatible changes would be avoided like plague; but if that's not much of a concern then it'd definitively be better to use ':' for locals. > > The transition could be made very easy if > > the current scoping rules are mixed with ':' for a while. > > > > So in > > blabla.aaaa do |a,:b| > > > > end > > > > a is local if there's no variable named 'a' previously defined, > > otherwise external > > This sort of confusion is exactly what we want to get away from. During the transition a warning could be issued so ':' is added where needed. > > b is local even if there's already 'b' in the external scope > > > > bottom line: nothing breaks, ':' forces local > > > > Ruby can issue a warning iff there was no 'a' variable before, as this > > code would break once the old scoping rules are thrown away and only the > > presence or absence of ':' is significant. -- _ _ | |__ __ _| |_ ___ _ __ ___ __ _ _ __ | '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ | |_) | (_| | |_\__ \ | | | | | (_| | | | | |_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_| Running Debian GNU/Linux Sid (unstable) batsman dot geo at yahoo dot com Because I don't need to worry about finances I can ignore Microsoft and take over the (computing) world from the grassroots. -- Linus Torvalds