RE: Autovivification

[email protected] ("Erik Steven Harrison")
Newsgroups perl.perl6.documentation
Organization Angelfire (http://email.angelfire.mailcity.lycos.com:80)
Message-ID <[email protected]>
 
--

On Sat, 9 Nov 2002 23:22:45   
 Brent Dax wrote:
>Michael Lazzaro:
># Brent Dax wrote:
># > 
># > I was writing up some docs (in a perldoc-like style--we can always 
># > change the form later, but the content is important), and started 
># > working on documenting references.  I ended up with this bit:
># 
># I imagine (if there are no objections) that the general 
># perldoc writing style (booklike, informal) is probably 
># exactly what we want, yes?  We'll just break it up into 
># *much* smaller individual sections, so that only one concept 
># is being taught at a time.  Probably.
>
>OK.  I'm trying to do that in the stuff I'm writing.
>
># > =head3 Autovivification
># >     @{%anagrams{$key}}.push $word;
># >     $undefined_var[$idx]=$scalar;
># 
># Hmm, not a clue.  I could argue that one both ways.  Perhaps (thinking
># aloud) they only autovivify if you've explicitly called out 
># the exact type they store, but otherwise generate an 
># exception?  (Because it seems like the behavior would be 
># _very_ handy if you wanted it, and a real pain in the $#@ 
># when you invoked it unintentionally.)
># 
># So maybe if you previously declared them like this:
># 
>#    my \Array %anagrams;
>#    my \Array $undefined_var;
>
>I think that, if Perl can determine the type with virtually no
>ambiguity, it should autovivify. 

Actually, this behavior has already (mostly) been decided over in P6 
language. It was decided (and I agree) that the Perl 5 behavior of 
autovivifying references to the basic data types is the incorrect 
behavior, leading to a lot of bugs when dealing wityh complex data 
structures. So no autovifiying an untyped $undefined_var[$foo]

However, a question unanswered is whether or not this behavior is 
inappropriate when the data structure had been appropriately typed.

-Erik

 In this case, since we know they
>wanted an array (they used the @ explicitly), we'll autovivify an array.
>(I say "virtually no" because one could make the argument that you don't
>know if we wanted a standard array or a typed one.)
>
>--Brent Dax <[email protected]>
>@roles=map {"Parrot $_"} qw(embedding regexen Configure)
>
>Wire telegraph is a kind of a very, very long cat. You pull his tail in
>New York and his head is meowing in Los Angeles. And radio operates
>exactly the same way. The only difference is that there is no cat.
>    --Albert Einstein (explaining radio)
>
>


____________________________________________________________
Get 25MB of email storage with Lycos Mail Plus!
Sign up today -- http://www.mail.lycos.com/brandPage.shtml?pageId=plus
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.