develooper Front page | perl.perl5.porters | Postings from February 2021

Re: Blessed objects are `isa` their reftype

Thread Previous | Thread Next
From:
L A Walsh
Date:
February 17, 2021 06:19
Subject:
Re: Blessed objects are `isa` their reftype
Message ID:
602CB4EF.10009@tlinx.org
On 2021/02/16 14:57, David Christensen wrote:
>>    3.TRUE
>>
>> The one numbered 3 is surprising.
>>     
I thought so too until I did the same in perl5.16.3:
Array, is a user-class that defines array operations on its members.
Data::Vars is a hash-based 'struct' type class.
---
#!/usr/bin/perl
use strict; use warnings;
use FindBin qw($Bin); $FindBin::Bin =~ s{/bin/lib/?$}{/bin};
use lib ($FindBin::Bin . "/lib", $ENV{HOME} . "/bin/lib");
################################################################################
{ package ArClass; use warnings; use strict; use mem;
  use parent 'Array';
1}
################################################################################
{ package HshClass; use warnings; use strict; use mem;
  use Data::Vars [qw(one two three)], {qw(one 1 two 2 three 3) };
1}
################################################################################
package main;
use P; use Types::Core; use Array;

my $aref=ArClass->new([11,22,33,44]);

my $popval=pop $aref; P "popval=%s", $popval;

my $shiftval = shift $aref; P "shiftval=%s", $shiftval;

P "isa class aref an ARRAY?=%s", $aref->isa('ARRAY') ? "true": "false";
P "isa class aref an Array?=%s", $aref->isa('Array') ? "true": "false";

my $href=HshClass->new();
P "isa class href an ARRAY?=%s", $href->isa('ARRAY') ? "true": "false";
P "isa class href an Array?=%s", $href->isa('Array') ? "true": "false";
P "isa class href a HASH?=%s", $href->isa('HASH') ? "true": "false";
---
>  /tmp/Arref.pl
popval=44
shiftval=11
isa class aref an ARRAY?=true
isa class aref an Array?=true
isa class href an ARRAY?=false
isa class href an Array?=false
isa class href a HASH?=true

So why introducing another new keyword when it's already in
the core library?




> 2.TRUE
>
> Where is the specification for 'isa'?  I do not see 'isa' in the 
> documentation for 'experimental':
>
>      https://perldoc.perl.org/experimental
>
>
> David
>   

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About