Hi

Hmm ... you are bringing some new aspects in, like mixing old and new syntax, instead of switching it globally for the whole file with a use feature right after use strict .

I didn't think to have a block scoped switching of syntax, don't think this would be wise.

(and I'm no expert of Perl6 variable syntax, I only know that plenty of stuff must change as a consequence)

Then it obvious now that @a and $a=\@a can't be automatically combined without braking some "traditions".

(see also here )

I think the latter is what people rather accept.

Now if mixing with old code is the goal, I'd suggest a new declaration syntax for typed references by adding parens (additionally to untyped scalars)

my $arr[] = [42,43,44]; # "typed" array ref #--- effects print $arr[0]; # => 42 (same as $arr->[0]) print $arr; # => ARRAY(0x8f4c214) print "@arr"; # => "42 43 44" (same as "@$arr") print "@arr[0,2]"; # => "41 43" (slice) #--- caught Errors (compile time): my @arr; ## @arr masks earlier declaration in same scop +e my $arr; ## $arr masks earlier declaration in same scop +e my $arr{} ## $arr{} masks earlier declaration in same sc +ope
This "typing" references wouldn't not only facilitate syntax (by restricting the name space) but also add a lot of compile time checking.

for instance the following is only a run time error at the moment which could be avoided otherwise at compile time.¹

my $a_ref = [1,2,3]; # old style $a_ref->{x}; ## Not a HASH reference (run time)

Furthermore did I follow Damian's naming convention here to mark a reference with a trailing _ref , to clearly indicate references to avoid typos, (albeit his convention doesn't distinguish types, that's why I personally prepend a_ to identifiers of arefs)

BUT if we had such typed references we could delegate this marking (which is a poor man's form of typing! ) to the syntax highlighting of the IDE after declaration in a scope and lazily avoid adding all those markers.²

Nota bene, the old syntax of my ($scalar, @array) wouldn't be effected and could be easily mixed

The my ($arr[], $hash{}, $code() ) syntax is of course debatable... am open for better ideas.

What do you think?

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

footnotes
¹) and compile time means almost immidiately for users of "flymake-mode" in emacs or komodo.

²) emacs already supports different styles ("cperl-...-faces") for arrays, hashes and barewords

UPDATE

the difference to the original suggestion is that it doesn't facilitate/change the use of the classical @a=(1,2,3) or $a=[1,2,3] but blends in with new syntax. (in other words easier for Perl cracks but less comfortable for beginners)

Since $scalars are all purpose variables it might be acceptable to still insist that references of untyped scalars are followed by a deref -> operator (?)

Cause if a $var could hold any reference, then the extra typing of -> could make this obvious like in $var->{x} vs $var->[1]


In reply to Re^4: Unifying namespaces of @name and $name to simplify dereferencing? (declaration of typed references) by LanX
in thread Unifying namespaces of @name and $name to simplify dereferencing? by LanX

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.