On Thu, Mar 21, 2013 at 12:58:01PM -0500, Patrick R. Michaud wrote:
> I don't quite follow the unease from this example, but that's
> probably because of the way that Perl 6 thinks of "undefined"
> being different from Perl 5's "undef" and "defined". 
> 
> In particular:
> 
> > ...
> > sub array {
> >     my $what = shift;
> >     my $array = [];
> >     return $array if $what eq 'undef';
> 
> Perl 6 wouldn't treat C< my $array = []; >  as having
> any sort of "undefined" result -- it's absolutely
> a defined Array (albeit empty).  In Perl 6, the way
> one would obtain an undefined array is with something
> like
> 
>     my $array = Array;
> 
> or
> 
>     my @array;    # rakudo currently gets this wrong,
>                   # which is part of what brought up
>                   # the discussion on #perl6  :-)
> 
> Or, put another way, in Perl 6 an undefined array
> is denoted by its type object (just like most other
> undefined values such as Int, Str, etc.).

Aha. The reason I was using [] was because in Perl 5 this really ends up
grovelling at the implementation level, and I know how lexicals cheat (and
get re-used), so I wanted to be sure to get a new array every time.

Of course, I wasn't thinking hard enough - the reference that escapes the
subroutine means that re-use is not possible, so I can write it as:


sub array {
    my $what = shift;
    my @array;
    return \@array if $what eq 'undef';
    push @array, "data";
    pop @array if $what eq 'empty';
    return \@array;
}

> Hope I've not just confused things even further.

No, you haven't


My unease comes, I think, from a Perl 5 perspective. undef/defined on an
array is dealing with something associated with the container, and an
implementation detail at that. undef/defined on a scalar is dealing with
something associated with the value.


If, as I think you are saying, Perl 6 has a much clearer idea of what is
value and what is container, and defined has a clearer idea of what it is
interacting with, then it's not going to get confusing for Perl 6.

Nicholas Clark

Reply via email to