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".
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)
This "typing" references wouldn't not only facilitate syntax (by restricting the name space) but also add a lot of compile time checking.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
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!
²) emacs already supports different styles ("cperl-...-faces") for arrays, hashes and barewords
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |