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:

  $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
numeric(7) (if the numeric() counterpart to scalar() exists).  +(7) could
still be the length of a list.

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?

~ John Williams


Reply via email to