in reply to Unifying namespaces of @name and $name to simplify dereferencing?
In perl4 you needed sigils on &subs, I think nobody is pining for that feature. I'd welcome the trend to continue to lexicals as well (let's call it perl7 ;-). Lexicals are good. More scoping means better structured code, opportunities for high-level optimizations. Simple variables need no symbolic bindings: compiler could optimize their allocation, etc.
Already there are experimental features: my $foo = sub vs my sub foo. That doesn't quite complete the circle since there's no implicit dereference ($foo() as $foo->()). But what if lexical subs were just sigil-less constant references? Naturally, subs in global scope ought to default to lexicals, unless marked as our.
References tend to encourage good practices (structured data, passing refs vs lists in/out of subs), and they can be easier to understand (array flattening). As it stands, mixing arrays and lists come with many nasty pitfalls. E.g. differences in slicing. E.g. an array-returning routine has a special case:
sub foo { # return @_ ? @_ : @{[7, 76543]}; return @_ ? @_ : (7, 76543); } say "as a list: ", join " ", foo(1, 2, 3); say "as int: ", int foo(1, 2, 3); say "as a list: ", join " ", foo(); say "as int: ", int foo();
I've been thinking the bare lexicals could be reference-anything variables, whereas sigils would place constraints. Sigils might also serve as prototypes in sub declaration. Ah yes, but this is starting to look like reinventing perl...
Where subs autovivify means autoloading or weak binding (to core library).my foo = either scalar or reference; foo[] foo() foo{} foo[](){}[]; # implicit -> and autovivify
Anyway. Thank you for your thoughts.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Unifying namespaces of @name and $name... (bare lexicals)
by LanX (Saint) on Mar 25, 2016 at 20:57 UTC | |
|
Re^2: Unifying namespaces of @name and $name... (bare lexicals)
by LanX (Saint) on Mar 25, 2016 at 18:23 UTC | |
by oiskuu (Hermit) on Mar 28, 2016 at 09:13 UTC |