Re: Perl allows you to change the definition of false to make it true. (And vice versa.)
by BrowserUk (Pope) on Dec 12, 2012 at 19:08 UTC
|
Cool! But there is only one possible response :)
BEWARE: This module is DANGEROUS!
...
ANYTHING might happen! Hell might break loose! :-)
YOU HAVE BEEN WARNED!
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
RIP Neil Armstrong
| [reply] |
|
| [reply] [d/l] |
|
| [reply] |
|
do &maybe if boolean($value)->isTrue;
Surely he meant:
do &maybe if boolean( true eq boolean($value)->isTrue() )->isTrue();
(:
| [reply] [d/l] [select] |
Re: Perl allows you to change the definition of false to make it true. (And vice versa.)
by LanX (Bishop) on Dec 12, 2012 at 22:50 UTC
|
And as usual it's far easier in Python! ;-)
>python
Python 2.5.2 (r252:60911, Jan 20 2010, 23:16:55)
[GCC 4.3.2] on linux2
>>> False, True = True, False
>>> False
True
>>> True
False
Python rules obfuscation!
| [reply] [d/l] |
|
>>> "foo"=="bar"
False
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
| [reply] [d/l] [select] |
|
So Python is easier to brake, but is incomplete in this attempt? ;-)
| [reply] |
Re: Perl allows you to change the definition of false to make it true. (And vice versa.)
by Anonymous Monk on Dec 12, 2012 at 23:01 UTC
|
| [reply] |
Re: Perl allows you to change the definition of false to make it true. (And vice versa.)
by bulk88 (Priest) on Dec 13, 2012 at 04:41 UTC
|
Blessing false (PL_sv_no) would also be impressive. | [reply] |
Re: Perl allows you to change the definition of false to make it true. (And vice versa.)
by LanX (Bishop) on Dec 13, 2012 at 22:48 UTC
|
Actually I can see useful applications for this.
When trying to convert (and not just interpret) other languages like LISP or JS to Perl one of the biggest problems are implicit typeconversions at edgecases.
(Thoroughly catching all those edgecases slows such conversions ridiculously down!)
For instance this way, one could try to patch booleans in a way that they stringify to "false" and "true" like in JS.
Thanks for showing! =)
| [reply] |
|
| [reply] |
|
>>> true
true
>>> "stringification: " + (1==1)
"stringification: true"
use v5.10.0;
use boolean;
say true;
say "stringification:" . (1==1);
output:
/usr/bin/perl -w /tmp/boolean.pl
1
stringification:1
but using dualvars could help.
UPDATE:
kind of
use Scalar::Util qw/dualvar/;
my $false = dualvar 0, "false";
my $true = dualvar 1, "true";
say $true;
say "stringification:" . $true;
say "numification: " . (0+$true);
say $false;
say "stringification: " . $false;
say "numification: " . (0+$false);
| [reply] [d/l] [select] |
Re: Perl allows you to change the definition of false to make it true. (And vice versa.)
by Anonymous Monk on Dec 14, 2012 at 14:26 UTC
|
This should please the comp.lang.c old timers:
use strict;
use warnings;
use 5.010;
BEGIN {
&Internals::SvREADONLY(\undef, 0);
${\undef} = "Demons are coming out of my nose!";
};
I wonder if you can redefine other read-only values?
I could not get the following to work.
BEGIN {
&Internals::SvREADONLY(\'blue', 0);
${\'blue'} = 'turtle';
&Internals::SvREADONLY(\5, 0);
${\5} = 5.000000000001;
};
(I have no idea why you would want to do this apart from JAPH or intentional sabotage) | [reply] [d/l] [select] |
|
| [reply] |
Re: Perl allows you to change the definition of false to make it true. (And vice versa.)
by Tux (Abbot) on Dec 13, 2012 at 13:47 UTC
|
See Juerd's talk "When undef isn't". When it doesn't show, disable CSS.
Enjoy, Have FUN! H.Merijn
| [reply] |
Re: Perl allows you to change the definition of false to make it true. (And vice versa.)
by Anonymous Monk on Dec 13, 2012 at 20:43 UTC
|
Whodathunkit that Perl would turn out to be a politician? ;-)
| [reply] |
Re: Perl allows you to change the definition of false to make it true. (And vice versa.)
by grondilu (Friar) on Dec 16, 2012 at 14:44 UTC
|
| [reply] |