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

Re: Should we consider locked hashes a failed experiment?

Thread Previous | Thread Next
From:
David Nicol
Date:
February 2, 2017 14:57
Subject:
Re: Should we consider locked hashes a failed experiment?
Message ID:
CAFwScO_sDvaK7NXs1oYbh3Bw3hXMJngNefwVYjRKEB9w61MVzA@mail.gmail.com
 our lack of core support for true objects/structs. (Where
> accessing a non-existent member *should* throw an exception, but
> preferably a compile time one.)


# What? Fields smields.

{ package TrueObjectStruct;
sub new { bless [] }
my $counter = 0;
for qw/foo bar baz/ {
      my $i = $counter++;
    *{$_} = sub :lvalue {
            $_[0]->[$i]
   }
}};
1;
__END__

okay, it doesn't throw until runtime -- but isn't somebody working on
promoting methods to compile-time-existence-checking?

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