Since this thread made it into this week's Official Perl6 Summary,
here goes a defense of C<it> as a shorthand for the thing that last
had C<defined> or C<exists> queried of it.

It (by which I mean C<it>, isn't this fun) would be a side-effect of
non-autovivifying queries.  It allows redundant descents into arbitrarily
complex data structures to be optimized out.

A new bareword is too heavy an invasion of this idea into the language:
a new LNV is preferable. C<use English> could alias $^d and $^e to
C<$DEFINED_TARGET> and C<$EXISTS_TARGET>, respectively.  Autoviv would be
deferred until ond of them gets assigned to.

Damian Conway wrote:
> 
> David wrote:
> 
>    >    defined $thing and return $thing
> 
> Why not use the existing mechanism? Namely:
> 
>         return $_ for grep{defined} $thing;

although meeting the specified criteria of looking $thing up
once, this is a confusing hack that might not save any cycles.
Setting up the C<for> construct and reassigning C<$_> might be
longer than referring to a defined-specific magic variable.

 
> which also scales rather nicely:
> 
>         return $_ for grep{defined} $thing, $otherthing, $somethingelse;

This does not help in the case of a long, unrolled routine which is to
return the first sensible parse of something.  Although with a
short-circuiting
grep this would work, and be a nice controlling abstraction too.


 
> As for the original problem of:
> 
>         1 until defined(getvalue()); return it;
> 
> You can already write:
> 
>         1 until defined($_=getvalue()); return $_;
> 
> which doesn't seem a huge extra burden.

I want the assignment done behind-the-scenes, rather
than by explicit programmer action.
 
I hereby revise my proposal from a bareword to a Line Noise Variable,
so that this interesting but rarely used feature, like other similar ones,
for instance $?.

Reply via email to