Re: "Secret" operators

[email protected] ("Peter Haworth")
Newsgroups perl.fwp
Message-ID <[email protected]>
On Wed, 2 Feb 2005 16:20:05 +0200, Vladi Belperchinov-Shabanski wrote:
> On Wed, 2 Feb 2005 12:33:35 +1100 (EST)
> > IIRC, Ton's ~- invention allows you to eliminate the parens in:
> >
> >     $y = ($x-1)*4;
> >
> > by using instead:
> >
> >     $y = ~-$x*4;
> >
> > saving a whopping two strokes. This trick should work on any twos
> > complement machine -- and I'm not aware of any perl running on any
> > non twos complement machine.
>
> will not work if $x < 0

It does if you C<use integer>, but that's no good for golf, (unless
you need 6 decrements, of course).

Incidentally, -~$x will increment negative numbers, but fails on >=0
for the same reason.

-- 
	Peter Haworth	[email protected]
"Ah, you're only calling [perl threads] experimental because it's slow,
 broken in spots, and has problems with backwards compatibility. What kind
 of labelling is that? (And where does it leave Windows NT?)"
		-- Dan Sugalski
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.