Re: The sperm secret operator: is it new?

2012-03-16 Thread Philippe Bruhat (BooK)
On Thu, Mar 15, 2012 at 10:40:17AM +0100, Dmitry Karasik wrote:
> 
> > Does that mean I have a dirty mind?
> 
> At least not dirtier than the inventor of the =()= (unless that was you ;)

I think the first person using =()= (Randal?) is not the same as
the first person naming it in a Perl context. Both probably have been
invented independently, as goatse was a popular meme at some point, and
people collected references to it. It's not suprising that a minimalist
ascii-art version appeared. And that it looked like Perl code.

-- 
 Philippe Bruhat (BooK)

 The man who most obeys the king is the man who gets crowned.
(Moral from Groo The Wanderer #13 (Epic))


Re: The sperm secret operator: is it new?

2012-03-15 Thread Philippe Bruhat (BooK)
On Thu, Mar 15, 2012 at 03:45:47PM +0100, Dmitry Karasik wrote:
> >>> ~~<>
> >> Looks more like a "kite" operator to me.
> > Does that mean I have a dirty mind?
> 
> That means that there's no such thing as a four-squared sperm! 
> 

Not that =()= resembles much to a... Hrmpf.

See also http://en.wikipedia.org/wiki/Sperm.
The side view is four-squared enough for me.

The limitations of ASCII shouldn't limit our imaginations!

-- 
 Philippe Bruhat (BooK)

 Too many believe only in the belief.
(Moral from Groo The Wanderer #58 (Epic))


Re: The sperm secret operator: is it new?

2012-03-15 Thread Dmitry Karasik
>>> ~~<>
>> Looks more like a "kite" operator to me.
> Does that mean I have a dirty mind?

That means that there's no such thing as a four-squared sperm! 

(ps my previous answer apparently didn't pass to the list, this is a shorter 
version of it anyway :)

-- 
Sincerely,
Dmitry Karasik



Re: The sperm secret operator: is it new?

2012-03-15 Thread Dmitry Karasik

> >> While doing some tests/research on secret operators, I stumbled upon
 >> this >> one in my one-liners:
 >> >> ~~<>
 >> >> Obviously, this should be named "the sperm operator".
 >> Looks more like a "kite" operator to me.
> Does that mean I have a dirty mind?

At least not dirtier than the inventor of the =()= (unless that was you ;)
... anyway I think it'll be adopted better as "kite", and well also, where 
did you see a four-squared sperm? :) 

-- 
Sincerely,
Dmitry Karasik



Re: The sperm secret operator: is it new?

2012-03-15 Thread Daniel Cutter

I would think it means you live in an area where it's not very windy.

*Daniel Cutter*
s/\b[^a]/\u$&/g,s;$;,;,print for join$,,map{('acehjklnoprstu'
=~m(.)g,$")[/\d/?$_:hex]}q(4dbce078c32ae92a6e30152aff)=~m(.)g


Am 15.03.2012 09:22, schrieb Philippe Bruhat (BooK):

On Thu, Mar 15, 2012 at 06:25:49AM +0100, Dmitry Karasik wrote:

While doing some tests/research on secret operators, I stumbled upon this
one in my one-liners:

 ~~<>

Obviously, this should be named "the sperm operator".


Looks more like a "kite" operator to me.


Does that mean I have a dirty mind?



Re: The sperm secret operator: is it new?

2012-03-15 Thread Philippe Bruhat (BooK)
On Thu, Mar 15, 2012 at 06:25:49AM +0100, Dmitry Karasik wrote:
> >> 
> >> While doing some tests/research on secret operators, I stumbled upon this
> >> one in my one-liners:
> >> 
> >> ~~<>
> >> 
> >> Obviously, this should be named "the sperm operator". 
> 
> 
> Looks more like a "kite" operator to me.
> 

Does that mean I have a dirty mind?

-- 
 Philippe Bruhat (BooK)

 Law is the best deterrent to Justice.
(Moral from Groo The Wanderer #90 (Epic))


Re: The sperm secret operator: is it new?

2012-03-14 Thread Dmitry Karasik
>> Hi,
>> 
>> While doing some tests/research on secret operators, I stumbled upon this
>> one in my one-liners:
>> 
>> ~~<>
>> 
>> Obviously, this should be named "the sperm operator". 


Looks more like a "kite" operator to me.


-- 
Sincerely,
Dmitry Karasik



Re: The sperm secret operator: is it new?

2012-03-14 Thread Yitzchak Scott-Thoennes
On Wed, Mar 14, 2012 at 3:50 PM, Philippe Bruhat (BooK)
 wrote:
> Frankly, I think this could be considered a bug. Both the left-facing
> and right-facing versions of the inchworm on a stick should work on
> all integers in Perl. Complement two arithmetics demand it! Now, the
> question is, how long has this been broken in Perl? Forever?

I don't consider it a bug.  ~ has to either assume signed or unsigned.

You get a choice by whether you do it under the scope of use integer
(implicit: comma signed) or not.


Re: The sperm secret operator: is it new?

2012-03-14 Thread Philippe Bruhat (BooK)
On Wed, Mar 14, 2012 at 01:46:34PM -0700, Andrew Savige wrote:
> > [ ~~ vs. scalar ]
> 
> The ~~ secret operator is old hat, good ol' inchworm:
> 
>  http://www.catonmat.net/blog/secret-perl-operators/#inchworm
> 
> BooK's innovation is to add <> and <>+0 to the end of it.
> 
> BTW, in addition to inchworm-on-a-stick ~- to subtract one,
> I often use the converse -~ to add one (though only in Ruby
> and Python, not usually Perl). For example, -~1 produces 2
> in Ruby and Python, but -4,294,967,294 in Perl.
> 

It works in C too. I was doing some research on secret operators today,
and I discovered the effects of the other inchworm-on-a-stick, and the
fact that both operators are broken for half the integers in Perl.

~- only decrements integers greater than 0 in Perl.
-~ only increments integers lesser than 0 in Perl.

According to Abigail and rgs, it's probably because ~ must also handle
strings. Abigail and I looked at the source of pp_negate, and it seems
like it does the right thing, so ~ seems to be the culprit. (I see that
tzchak Scott-Thoennes has provided a thorough answer in another mail.)

Frankly, I think this could be considered a bug. Both the left-facing
and right-facing versions of the inchworm on a stick should work on
all integers in Perl. Complement two arithmetics demand it! Now, the
question is, how long has this been broken in Perl? Forever?

-- 
 Philippe Bruhat (BooK)

 The learned man makes a mistake but once... but the truly stupid keep
 practicing until they get it right.
(Moral from Groo The Wanderer #75 (Epic))


Re: The sperm secret operator: is it new?

2012-03-14 Thread Yitzchak Scott-Thoennes
On Wed, Mar 14, 2012 at 7:48 AM, John Douglas Porter
 wrote:
> So is that the Perl 6 smart match operator? or something else?

The latter.

> In any case... How does it work here?  It looks like it's functionally
> equivalent to scalar()... but why?

Perl's ~ is operand sensitive; if its operand has a numeric value
(either because it was assigned a number, the result of a numeric
operation,  or had been used in numeric context), it is a numeric
bitwise or (implicitly converting to UV, or under the scope of use
integer, IV, first); otherwise it is a string bitwise or.

For most inputs, in either case it can be repeated to reproduce the
original value and acts just like scalar().

Examples of exceptions:

# floating point

$x = 1.23; print ~~$x; # 1

# string used in numeric context

$x = "1.23"; print ~~$x if $x != 0; # 1

# integer out of range

use Config '%Config';

$x=2**(8*$Config{uvsize}); print ~~$x; # max uv

$x = -1; print ~~$x; # max uv

$x = 2**(8*$Config{uvsize}-1); use integer; print ~~$x; # min iv

$x = -2**(8*$Config{uvsize}-1)-1; use integer; print ~~$x; # min iv


Re: The sperm secret operator: is it new?

2012-03-14 Thread Andrew Savige
> [ ~~ vs. scalar ]

The ~~ secret operator is old hat, good ol' inchworm:

 http://www.catonmat.net/blog/secret-perl-operators/#inchworm

BooK's innovation is to add <> and <>+0 to the end of it.

BTW, in addition to inchworm-on-a-stick ~- to subtract one,
I often use the converse -~ to add one (though only in Ruby
and Python, not usually Perl). For example, -~1 produces 2

in Ruby and Python, but -4,294,967,294 in Perl.


/-\


Re: The sperm secret operator: is it new?

2012-03-14 Thread Sebastian Schmidt
On Wed, Mar 14, 2012 at 07:48:35AM -0700, John Douglas Porter wrote:
[ ~~ vs. scalar ]
> 
> So is that the Perl 6 smart match operator? or something else?
> In any case... How does it work here?  It looks like it's functionally
> equivalent to scalar()... but why?

It's twice bitwise not, and bitwise not enforces scalar context.
Think ~(~(foo)).


Re: The sperm secret operator: is it new?

2012-03-14 Thread John Douglas Porter

So is that the Perl 6 smart match operator? or something else?
In any case... How does it work here?  It looks like it's functionally
equivalent to scalar()... but why?
-- 
jdporter


--- On Wed, 3/14/12, Philippe Bruhat (BooK)  wrote:

> From: Philippe Bruhat (BooK) 
> Subject: Re: The sperm secret operator: is it new?
> To: fwp@perl.org
> Date: Wednesday, March 14, 2012, 8:29 AM
> On Wed, Mar 14, 2012 at 12:36:10PM
> +0100, Philippe Bruhat (BooK) wrote:
> > Hi,
> > 
> > While doing some tests/research on secret operators, I
> stumbled upon this
> > one in my one-liners:
> > 
> >     ~~<>
> > 
> > Obviously, this should be named "the sperm operator".
> It's only useful
> > in list context. Just like sperm cells work better when
> there are many
> > of them. ;-)
> > 
> 
> Example usage:
> 
>    # the first three lines constitute the
> header
>    @header = ( ~~<>, ~~<>,
> ~~<> );
> 
> -- 
>  Philippe Bruhat (BooK)
> 
>  The only way to get a better government is to get better
> voters.
>                
>                
>    (Moral from Groo The Wanderer #109
> (Epic))
>


Re: The sperm secret operator: is it new?

2012-03-14 Thread Philippe Bruhat (BooK)
On Wed, Mar 14, 2012 at 12:36:10PM +0100, Philippe Bruhat (BooK) wrote:
> Hi,
> 
> While doing some tests/research on secret operators, I stumbled upon this
> one in my one-liners:
> 
> ~~<>
> 
> Obviously, this should be named "the sperm operator". It's only useful
> in list context. Just like sperm cells work better when there are many
> of them. ;-)
> 

Example usage:

   # the first three lines constitute the header
   @header = ( ~~<>, ~~<>, ~~<> );

-- 
 Philippe Bruhat (BooK)

 The only way to get a better government is to get better voters.
   (Moral from Groo The Wanderer #109 (Epic))