Excuse exclamation marks abound, but this message is all about a set of new
secret operators I thought of, all based on the exclamation sign. The boolean
negation is not really often used, but when is, the brevity of "!" cannot be
overestimated.
Anyway, here's a set of conditional decrement/increment operators:
$x +=!! $y is same as $x++ if $y;
$x -=!! $y -- $x-- if $y;
$x +=! $y -- $x++ unless $y;
$x -=! $y -- $x-- unless $y;
and for the completeness sake,
$x *=!! $y -- $x = 0 unless $y ,
$x *=! $y -- $x = 0 if $y;
This bunch, I think, can be appropriately named "screwdriver operators":
-=! and -=!! - flathead
+=! and +=!! - phillips
*=! and *=!! - torx
I don't know what name fits best to distinguish between ! and !! versions
though.
But that's not all. There's also a binary form for the increment and decrement:
$x +!!+ $y -- $x + ( $y ? 1 : 0);
$x -!!- $y -- $x - ( $y ? 1 : 0);
$x +!+ $y -- $x + ( $y ? 0 : 1);
$x -!- $y -- $x - ( $y ? 0 : 1);
These actually are not completely useless. Consider the often-used calculation
of how many buckets are required for a number of items, with max items per
bucket. The usual form is
$n = int( $items / $max) + (( $items % $max) ? 1 : 0);
whereas
$n = int( $items / $max) +!!+ $items % $max;
is both more short and elegant :) Again, I don't know how to name these four.
And finally, we come to the useless ones, which I found funny but unfortunately
completely impractical. Here's a not-or (NOR) boolean operator that only
reliably operates on 0s and 1s as arguments (actually on a bit more than that,
but it's not that interesting):
0 !~! 0 = 1
0 !~! 1 = 0
1 !~! 0 = 0
1 !~! 1 = 0
This one I named the Tesla operator, because it somehow resembles two
electrodes with a spark between them. And finally, for the pure fun of it -
two boolean constants,
!() -- true
!%! -- false
These two deserve to be named the Mongolian constants, because !%!
really resembles that soyombo thingy on the mongolian national flag
( http://upload.wikimedia.org/wikipedia/commons/thumb/4/4c/Flag_of_Mongolia.svg/125px-Flag_of_Mongolia.svg.png ).
I was even tempted to say Mongolian Tao constants, because the thingy actually
contains the yin-yang sign, which can be also thought as a graphical representation of
a non-boolean, yet definitely binary logic :)
--
Sincerely,
Dmitry Karasik
DK> $x +=!! $y is same as $x++ if $y;
DK> $x -=!! $y -- $x-- if $y;
DK> $x +=! $y -- $x++ unless $y;
DK> $x -=! $y -- $x-- unless $y;
DK> $n = int( $items / $max) + (( $items % $max) ? 1 : 0);
DK> $n = int( $items / $max) +!!+ $items % $max;
DK> 0 !~! 0 = 1
DK> 0 !~! 1 = 0
DK> 1 !~! 0 = 0
DK> 1 !~! 1 = 0
DK> !() -- true
DK> !%! -- false
DK> These two deserve to be named the Mongolian constants, because !%!
DK> really resembles that soyombo thingy on the mongolian national flag
DK> ( http://upload.wikimedia.org/wikipedia/commons/thumb/4/4c/Flag_of_Mongolia.svg/125px-Flag_of_Mongolia.svg.png ).
DK> I was even tempted to say Mongolian Tao constants, because the thingy actually
DK> contains the yin-yang sign, which can be also thought as a graphical representation of
DK> a non-boolean, yet definitely binary logic :)
you, sir, have altogether too much free time!! would you like to stop
wasting your life and help improve some cpan modules of mine? :)
uri
--
Uri Guttman ------ u...@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
Uri, what list do you think this is? The phrase "wasting your life" is
not allowed here, unless you can work it into a JAPH or something.
--
Keith C. Ivey <ke...@iveys.org>
Washington, DC
Uri> you, sir, have altogether too much free time!! would you like to stop
Uri> wasting your life and help improve some cpan modules of mine? :)
will I get permission to pepper them with obfuscations and
secret operators to my heart's content? :)
--
Sincerely,
Dmitry Karasik
DK> Hi Uri!
Uri> you, sir, have altogether too much free time!! would you like to stop
Uri> wasting your life and help improve some cpan modules of mine? :)
DK> will I get permission to pepper them with obfuscations and
DK> secret operators to my heart's content? :)
this is code for cpan. your requests are requirements for top quality
cpan code!
> >>>>> "DK" == Dmitry Karasik <dmi...@karasik.eu.org> writes:
>
> DK> Hi Uri!
> Uri> you, sir, have altogether too much free time!! would you like to stop
> Uri> wasting your life and help improve some cpan modules of mine? :)
>
> DK> will I get permission to pepper them with obfuscations and
> DK> secret operators to my heart's content? :)
>
> this is code for cpan. your requests are requirements for top quality
> cpan code!
To (mis)quote Fred Allen --
"CPAN is a medium because anything well done is rare."
:-P
0--gg-
--
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s,/,($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e,e && print}