I don't have time to RFC this now, as I'm leaving soon for several days.
So here's a brain dump.

Camel-3 shows some interesting hints of what's been proposed for my
declarations:

   my type $var :attribute = $value;

And we all know that you can use my to declare a group of variables:

   my($x, $y, $z);

Here's the issues:

   1. How do the two jive together?
  
   2. Should it be possible to assign attributes to
      individiual elements of hashes/arrays? (yes)

   3. With types, should multiple types be applicable
      as "candidate types" for that value?

Here's a shot at it. Please, rip it apart and put it back together. When
I get back I'll RFC the remains (if there are any). ;-)

1. Getting everything to work together

Excuse me if I trod over well-worn p5p ground, but it appears to me that
you should be able to group things in different ways to avoid needless
redundancy:

   my int ($x, $y, $z);
   my int ($x :64bit, $y :32bit, $z);

Seems most logical that:

   A) The type will be the same across variables; this is common
      usage in other languages because it makes sense.

   B) The attributes will be different for different variables.

Nonetheless, it seems we might want the DWIMmishness available by
supporting these:

   my int ($x, $y, $z) :64bit;         # all are 64-bit
   my int ($x, $y, $z :unsign) :64bit  # plus $z is unsigned

   my int ($x, $y), char $z;               # mix classes
   my int ($x, $y) :64bit, char $z :long;  # and attrs

And, of course, the ultimate spaghetti:

   my (int ($x :unsign, $y) :big, char $z :long) :64bit;

Meaning is left as an exercise for the reader. :-)

2. Assigning attributes to individual elements of hashes/arrays

This is potentially very useful. ":laccess", ":raccess", ":public",
":private", and others spring to mind as potential candidates for this.
Any reason we shouldn't extend this:

   my int @a :64bit;       # makes each element a 64-bit int
   my string %h :long;     # each key/val is long string

To declaring attributes on individual elements:

   $a[0] :32bit  =   get_val;        # 32-bit
   $r->{name} :private = "Nate";     # privatize single value
   $s->{VAL} :laccess('data') = "";  # lvalue autoaccessor

However, a problem then arises how to assign types to singular elements:

   my int $a[0] :64bit;     # just makes that single element
                            # a lexically-scoped 64-bit int?

   my string $h{name} = ""; # cast $h{name} to string, rescope %h?

Currently, lexical scope has no meaning for individual elements of
hashes and arrays. However, assigning attributes and even types to
individual elements seems useful. There's two ways around this that I
see:

   A) On my'ing of an individual hash/array element, the
      entire hash/array is rescoped to the nearest block.

   B) Just that individual element is rescoped, similar
      to what happens when you do this:

          my $x = 5;
          {
             my $x = 10;
          }

Input? 

3. Assigning multiple "candidate types" for a variable

It seems potentially useful to be able to say:

   my Dog, Cat $fluffy;

As a way to say "$fluffy can be either a Dog or a Cat". Since variables
are prefixed, anything comma-separated up to the variable is an
alternate class for that variable:

   my double, float ($x, $y) :64bit;
   my int, char ($a, $b), float, double $c :big;

However, we might not want this at all. I'm just throwing it out there.

I likely will not reply to this thread for a good while, so please don't
email stuff phrased directly to me; this is intended to spawn a general
discussion on this topic.

-Nate

Reply via email to