On 09/13/2018 12:29 PM, Elizabeth Mattijsen wrote:
On 13 Sep 2018, at 20:47, ToddAndMargo <toddandma...@zoho.com> wrote:
On 09/12/2018 10:09 AM, Larry Wall wrote:
Basically, ignore any advice to treat Nil as a normal value, because
it really is intended to represent the *absence* of a value as much as
possible.  It's a bit like the way solid-state electronics treats "holes"
as if they were real particles, and gets away with it much of the time.
But not all the time, because the hole isn't real; it's the collective
behavior of everything around a thing that's missing.
So while you can test explicitly for Nil if you try hard enough, it's
better not to try at all, because lots of places internally are using
that Nil to select some kind of default behavior that might or might
not look like Nil afterwards.
It was probably a mistake to put Nil into the type hierarchy underneath
the Any type in the first place.  It's more of a concept type like
Junction, so probably belongs outside of Any, which sits the top of the
"normal" object hierarchy.
These types are deeply magical.  Whenever you find yourself trying to
use Nil or Junction as a normal value, you have to ask yourself whether
you're just Mickey Mouse falling into the Sorcerer's Apprentice trap.
Unless you're a wizard, with Nil and Junction it's better to cargo cult
a few common usages and stay the heck away the rest of the time.
Larry

Hi Larry,

Beautiful description!  Almost magical!  :-)

I will stick with .defined that you suggested in another
thread.

Another way to deal with Nil is to use “with”, especially if you don’t need to 
do anything if the value is Nil:

with “foo”.index(“o”) -> $index {
     say “Found at index $index”;
}

Documentation: 
https://docs.perl6.org/language/control#index-entry-control_flow_with_orwith_without-with%2C_orwith%2C_without


Where I typically have to deal with Nil's is when I
am looping through something I read back from a system
call.  I never thought much of it when I was using bash,
but when you see the raw stuff ...

Not a Nil, but things read back and looped with split
can be interesting too.

$ p6 'my $x="\na\nb\nc\n"; for ( split "\n", $x ) -> $i {print "<$i>\n"};'
<>
<a>
<b>
<c>
<>

with beginning and ending new lines.

Reply via email to