Re: RFC 218 (v1) C<my Dog $spot> is just an assertion
[email protected] (Piers Cawley) 14 Sep 2000 13:51:54 +0100
| Newsgroups | perl.perl6.language.objects,perl.perl6.announce.rfc |
|---|---|
| Message-ID | <[email protected]> |
Perl6 RFC Librarian <[email protected]> writes: > This and other RFCs are available on the web at > http://dev.perl.org/rfc/ > > =head1 TITLE > > C<my Dog $spot> is just an assertion > > =head1 VERSION > > Maintainer: Piers Cawley <[email protected]> > Date: 13th September 2000 > Mailing List: [email protected] > Number: 218 > Version: 1 > Status: Developing > > =head1 ABSTRACT > > The behaviour of the <my Dog $spot> syntax should simply be an > assertion of the invariant: > > (!defined($spot) || (ref($spot) && $spot->isa('Dog))) > > =head1 DESCRIPTION > > The syntax > > my Dog $spot = Dog->new(); > > currently carries little weight with Perl, often failing to do what > one expects: > > $ perl -wle 'my Dog::$spot; print "ok"' > No such class Dog at -e line 1, near "my Dog" > Execution of -e aborted due to compilation errors. > $ perl -wle 'sub Dog::new; my Dog $spot; print "ok"' > ok > $ perl -wle 'sub Dog::new; my Dog $spot = 1' > ok > > The first example is obvious, as is the second. The third one is > I<weird>. Actually, it's *very* weird given that there's no code to print 'ok'. Which is bad. $ perl -wle 'sub Dog::new; my Dog $spot = 1; print "ok"' That's better. -- Piers