develooper Front page | perl.perl6.users | Postings from September 2018

Re: .kv ?

Thread Previous | Thread Next
From:
ToddAndMargo
Date:
September 14, 2018 21:55
Subject:
Re: .kv ?
Message ID:
49ef2bf7-6235-888c-ad19-82736e430c25@zoho.com
On 09/14/2018 09:26 AM, Brad Gilbert wrote:
> You can read https://en.wikipedia.org/wiki/Option_type for more information
> 
> Tell me if you find any of the Perl 6 section confusing.
> https://en.wikipedia.org/wiki/Option_type#Perl_6
> 

Hi Brad,

I had to read to top over very slowly.  Part of the issue was
that I was not taught to read correctly.  (I was taught
"Look See", instead of "Phonics").  I kept seeing other words,
other than "nullable" and "non-nullable".  Eventually, I forced
myself to use phonics and the words made sense.  This is not the
authors problem, but mine alone.

      "There are as many null values as there are types, that
      is because every type is its own null. So all types are
      also their own option type."

Well stated.  Chuckle, in Modula2 a null is always 0H0000.

      'To opt into a non-nullable version of a type add the :D
      "smiley" to it."

This is confusing.  And I don't think correct, but I could be wrong.
Curt stated it a lot better:

       If I say "my Int $x",
       $x is now an Int, but an undefined Int.

       If I say "my Int $x = 42",
       $x is an Int, but set to a defined value, 42.

":D" means that the variable is "defined".  "non-nullable" is
a confusing way to state it.


       It is also possible to opt into a type that is only
       ever a nullable using the :U "smiley".

Curt's description is explains this perfectly. "is only
ever a nullable" is confusing.  ":U" means that the
variable has not got anything assigned to it yet.

To me ":D" means that the variable has something assigned to
and ":U" means that the variable has yet to have anything
assigned to it.

If I were to rewrite this, I'd reverse D and U as that
is the way they evolve.  All variables start out as :U.

      To designate a variable that does not have a value assigned
      to it yet and is still in the null state, use the :U designation.

      To designate a variable that must have a value assigned
      to it (not be in the null state), use the :D designation

The examples are excellent.

Coming from Modula2 and Pasca, one of the issues I had to content
with when I picked started coding in Perl 5 was that in Modula2
a variable is just a spot in memory with a designated length.
A new variable contains whatever junk was in that memory location
when you started your program.  You very quickly learn to pre-salt
all your variables or you get caught in uninitialized variable hell.

In Perl, variables are structures.  There is a bunch of house keeping
involved.  The "my" declaration triggers this house keeping including
where it is and all the rules to access it.  The variable is pre-salted"
(null) very much so.  Perl is a ton easier to program in than Modula2.

Chuckle, the Perl 5 guy never did forgive me for calling Reference
Pointers "pointers".  I constantly had to remind them
that there were different kinds of pointers than those found
in "C", which only points to a spot in memory.  Perl's pointers
point to the variables structure or "reference" and all the
associated rules.

HTH,
-T

They also got huffy with me calling hashes "associative arrays",
which they are.  When I quoted them Larry's reasoning on the
subject (hash is easier to write), they shut up.  But I
could tell it still rankled.

I don't know why they were so huffy.  "Associative Array"
help me wrap my mind around what exactly my favorite variable
was.

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About