On Mon, Jul 07, 2008 at 11:43:56PM -0500, Patrick R. Michaud wrote:
: On Mon, Jul 07, 2008 at 08:18:36PM -0700, Larry Wall wrote:
: > On Mon, Jul 07, 2008 at 07:16:05PM -0700, Patrick R. Michaud via RT wrote:
: > : Note however that TimToady on #perl6 speculated [1] that an empty return
: > : should return the Object prototype.  I'm not sure the answer was
: > : resolved completely in that thread, however, so we'll go with returning
: > : 'undef' for now and wait for a more definitive answer before closing
: > : this ticket.
: > 
: > A C<return> just returns its argument list as a Capture, so it's
: > probably just returning the "null" Capture, presumably with Object
: > (undef) in the scalar slot and an empty list in the list slot and
: > an empty hash in the hash slot.  
: 
: By "(undef)" here did you mean simply that it's an undefined
: Object (prototype), or that the C<undef> function now returns
: Object instead of Failure (S02:872)?

Hmm, well, on further reflections, it should in all likelihood be
neither of those.  I can argue that it should be a special failure type
to try to get an item from a null list: "Attempt to pull a rabbit out
of an empty hat" or some such.  :)

I can also argue that a null list in item context simply promotes to
an empty array just as a list of 2 or more elements does.  Given that
"return;" is not the same as "fail;", that's probably the right thing to
do.

It does treat single-item lists as special, but note that .[0] is
a no-op on a non-array.  And it's really the .[0] operation that
translates to the pull-a-rabbit-out-of-an-empty-hat failure if you
hand it a null list.  Well, it's probably really "Subscript out of
range"...

Which argues that bare return should be treated as returning a list
that happens to be empty (via the Capture that return always returns
to keep the return value contextually lazy).

So

    $x = nothing();             # = []
    @x = nothing();             # = ()
    %x = nothing();             # = ()
    if nothing() {...}          # always false
    $x = nothing()[0]           # "Subscript out of range" failure

In other words, I think I'd like to not encourage people to use bare
return to indicate failure.

Larry

Reply via email to