On Thu, 11 Apr 2002, Piers Cawley wrote: > "Miko O'Sullivan" <[EMAIL PROTECTED]> writes: > > The current plans indicate that a subroutine's params should be defaulted > > like this: > > > > sub load_data ($filename ; $version / /= 1) {...} > > > > (The space between / and / is on purpose, my emailer has problems if > > they are together.) If that's the technique, how does the caller > > indicate that the second param is *supposed* to be undef? If I were > > to call a sub like this: > > > > load_data ($filename, undef); > > > > then I would expect that means that I am explicitly saying the > > second argument is supposed to be undef. However, if I call it like > > this: > > > > load_data ($filename); > > > > then I'm not sending the second param and it can be whatever the > > default is. Ergo, I propose that / /= and simply = are both allowed > > and mean slightly different things: > > > > # $version is 1 if the second param isn't sent at all > > sub load_data ($filename ; $version = 1) {...} > > > > # $version is 1 if the second param is undef > > sub load_data ($filename ; $version / /= 1) {...} > > > > (Yes, this is a repeat of an earlier suggestion. It was suggested I might > > repost reworded.) > > I think you're right that this is a valid distinction, I'm just not > sure if it's not a little too subtle and that the two different > notations won't cause confusion. I *think* that the //= case is going > to be the more common one, and one could always handle the first case > more explicitly by doing: > > sub load_data ($filename; $version) { > $version = 1 if @_.length < 2; > ... > } > > Yes, it is undoubtedly uglier, but I don't think it's a common enough > case that that worries me.
Indeed, and with the //= thing, you can let parameters in the middle default. The only other language that lets you do that is VB, and I actually kinda liked it. (Not insinuating that VB is actually a language or anything...) Luke