On Sat, Oct 26, 2002 at 11:24:23AM +0100, Nicholas Clark wrote:
> On Sat, Oct 26, 2002 at 01:59:46AM +0200, Paul Johnson wrote:
> > On Fri, Oct 25, 2002 at 06:28:28PM -0400, Miko O'Sullivan wrote:
> > > From: "Larry Wall" <[EMAIL PROTECTED]>
> > > > :      ?   - force to bool context
> > > > :      !   - force to bool context, negate
> > > > :      +   - force to numeric context
> > > > :      -   - force to numeric context, negate
> > > > :      ~   - force to string context
> > > >
> > > > We're obviously missing the "force to string context, negate" operator.
> > > :-)
> > > 
> > > Mr. Wall, may I be excused?  My brain is full.  Oh, I have to stick it out
> > > with everyone else? OK, um....
> > > 
> > > Just so I understand... why do we need "force to blah context" operators at
> > > all?  Are we planning on doing a lot of context forcing?  Isn't "a lot of
> 
> > The negate operators we have already:
> > 
> > perl -e '$x = "0"; print !$x'
> > perl -e '$x = "10.000"; print -$x'
> 
> Here is something that maybe you'd forgotten:
> 
> $ perl -lwe '$x = "Good"; print -$x'
> -Good
> $ perl -lwe '$x = "-Good"; print -$x'
> +Good
> $ perl -lwe '$x = -"Good"; print -$x'
> +Good
> $ perl -lwe '$x = "+Good"; print -$x'
> -Good
> 
> Unary plus is actually irrelevant:
> 
> $ perl -lwe '$x = +"Good"; print -$x'
> -Good

I hadn't actually forgotton - I even re-read "Symbolic Unary Operators"
in perlop, but I didn't want to wander too far off into strange Perl 5
territory.

Miko actually wrote at the end of his mesage:

] -Miko
] uh oh, I just forced myself into numeric context and negated myself

$ perl -lwe 'my $x = -Miko; print -$x'
+Miko
$ perl -lwe 'my $x = +Miko; print -$x'
-Miko
$ perl -Mstrict -lwe 'my $x = -Miko; print -$x'
+Miko
$ perl -Mstrict -lwe 'my $x = +Miko; print -$x'
Bareword "Miko" not allowed while "strict subs" in use at -e line 1.
Execution of -e aborted due to compilation errors.

I know why that is, at least technically, but didn't fancy trying to
explain why it should be like that from a language design point of view.

Although I'm sure someone here could do that ;-)

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net

Reply via email to