Skip Menu |
 

This queue is for tickets about the Quantum-Superpositions CPAN distribution.

Report information
The Basics
Id: 52984
Status: open
Priority: 0/
Queue: Quantum-Superpositions

People
Owner: Nobody in particular
Requestors: ifomichev [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 2.02
Fixed in: (no value)



CC: rakudobug [...] perl.org
Subject: Using "any" and "all" with "defined"
Download (untitled) / with headers
text/plain 431b
Hello, I'm not sure if it is a bug or a forced misfeature, but the following code does not work as I'd expect: $ perl -MQuantum::Superpositions -le 'print defined all(undef, 0, 1);' 1 $ perl -MQuantum::Superpositions -le 'print defined any(undef, undef);' 1 BTW, Perl 6 (Rakudo "Seoul") does the same: $ perl6 -e 'say defined all(undef, 0, 1)' 1 $ perl6 -e 'say defined any(undef, undef)' 1 Could you please comment this issue?
Subject: Re: [rt.cpan.org #52984] Using "any" and "all" with "defined"
Date: Wed, 23 Dec 2009 15:41:23 +1100
To: bug-Quantum-Superpositions [...] rt.cpan.org
From: Damian Conway <damian [...] conway.org>
Download (untitled) / with headers
text/plain 834b
Hi Ivan, Show quoted text
> Hello, I'm not sure if it is a bug or a forced misfeature, but the > following code does not work as I'd expect: > > $ perl -MQuantum::Superpositions -le 'print defined all(undef, 0, 1);' > 1 > $ perl -MQuantum::Superpositions -le 'print defined any(undef, undef);' > 1
This is an unavoidable misfeature. Perl 5 does not allow us to overload the 'defined' builtin, so we're stuck with the default behaviour, which treats a superposition object like any other object (i.e. as being defined). :-( Show quoted text
> > BTW, Perl 6 (Rakudo "Seoul") does the same: > > $ perl6 -e 'say defined all(undef, 0, 1)' > 1 > $ perl6 -e 'say defined any(undef, undef)' > 1
Those are definitely bugs. Though Perl 6 changed recently and 'undef' no longer exists. You'd have to write: say defined all(Mu, 0, 1) say defined any(Mu, Mu) Damian
Download (untitled) / with headers
text/plain 339b
On Tue Dec 22 23:41:59 2009, damian@conway.org wrote: Show quoted text
> This is an unavoidable misfeature. Perl 5 does not allow us to
overload the Show quoted text
> 'defined' builtin, so we're stuck with the default behaviour, which treats > a superposition object like any other object (i.e. as being defined). :-(
Is there a chance, that we'll be allowed in 5.12? ;-)
Subject: Re: [rt.cpan.org #52984] Using "any" and "all" with "defined"
Date: Wed, 23 Dec 2009 18:58:49 +1100
To: bug-Quantum-Superpositions [...] rt.cpan.org
From: Damian Conway <damian [...] conway.org>
Download (untitled) / with headers
text/plain 593b
Show quoted text
>> Perl 5 does not allow us to overload the 'defined' builtin, so we're >> stuck with the default behaviour, which treats a superposition object >> like any other object (i.e. as being defined). :-(
Show quoted text
> Is there a chance, that we'll be allowed in 5.12? ;-)
Very little chance, I fear. defined() doesn't have a prototype that's expressible in Perl 5 itself, so there's no way to override it. It would require a significant change to the prototype syntax to allow the various argument types that defined() supports. Unfortunately, there's no sign that 5.12 will have any such additions. Damian
Download (untitled) / with headers
text/plain 503b
Damian, thank you for your comments. By the way, it is possible to provide a workaround for now, e. g. use Quantum::Superpositions; package Quantum::Superpositions::Disj; sub defined { foreach ($_[0]->eigenstates) { return 1 if defined; } return ''; } package Quantum::Superpositions::Conj; sub defined { foreach (@{$_[0]}) { return '' if !defined; } return 1; } package main; print all(undef, 0, 1)->defined, "\n"; print any(undef, undef)->defined, "\n";
Download (untitled) / with headers
text/plain 581b
On second thought, the algorithm should be a little bit more complex to properly process nested junctions, something like: use Quantum::Superpositions; package Quantum::Superpositions::Disj; sub defined { foreach ($_[0]->eigenstates) { return 1 if eval { $_->isa($_, 'Quantum::Superpositions') } ? $_->defined : defined; } return ''; } package Quantum::Superpositions::Conj; sub defined { foreach (@{$_[0]}) { return '' if eval { $_->isa($_, 'Quantum::Superpositions') } ? !$_->defined : !defined; } return 1; }
Download (untitled) / with headers
text/plain 274b
On Wed Dec 23 12:52:55 2009, IFOMICHEV wrote: Show quoted text
> return 1 if eval { $_->isa($_, 'Quantum::Superpositions') } > ? $_->defined : defined;
Sorry, a bug. return 1 if eval { $_->isa('Quantum::Superpositions') } ? $_->defined : defined;


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.