On Sat, Sep 21, 2002 at 11:36:49AM -0600, John Williams wrote: > On Sat, 21 Sep 2002, Jonathan Scott Duff wrote: > > > I can't tell whether (7).length is asking for the length > > > of 7 or the length of a list, but I would be badly surprised if > > > (3+4).pow(2) returned 1 instead of 49. > > > > So, you expect 7.pow(2) to work? I'd expect it to be an error (this > > isn't python after all). > > Larry said in Apocalypse 2 that things should act like objects if we ask > them to, but I suppose the details will wait until Apocalypse 10-12. > Maybe 7.operator:**(2) would be more correct. > > Anyway, (7) or (3+4) should yield a number, not a list, because otherwise > every math expression will break. Consider:
People keep saying that and I think "tyranny of the OR" (See "Built to Last" by James Collins and Jerry Porras) Why can't perl be smart enough to figure out what we mean? Something along these lines: (7) # list context (3+4) # numeric context (there's a numeric operator in there) (3+4,5) # list context (comma trumps the numeric op) Okay, I admit it mayn't be the best idea in the world, but I'm following this line of discussion in case it leads anywhere interesting. And if nothing else, I'm giving real good reasons for why *not* to do this :-) Oh, and if they want "(3+4)" in list context, they can be explicit "list(3+4)" This strikes me as an edge case far on the fringe of what people normally do though. > $a = (7); $b = ( $x + $y ); > > Both () are in scalar context, not list or numeric. You can easily make > it a list with (7,) or [7] but you could only make it a number with (7,) is an abomination. It's one of python's misfeatures that annoys me the most. > numeric(7) (if the numeric() counterpart to scalar() exists). It seems to me that numeric() would only be useful on one element lists (indeed, most of this discussion only applies to one element lists). If that's the case, it's real easy for me to tell the programmer "Don't do that" if they're putting parens around their single element lists. > +(7) could still be the length of a list. If we keep () as synonym to [], then that's what I'd expect it to be. > Of course there are non-numeric contexts too, such as ("a"). Would it > be fair to say that parenthesis should not alter the context when used > in expressions? Looks like a single element list from where I sit right now i-) -Scott -- Jonathan Scott Duff [EMAIL PROTECTED]