Mark J. Reed wrote:
Jonathan Lang wrote:
> Good examples.  Now could you provide some to explain to me why it's
> important to distinguish between '$', '@', '%', and '&'?  I ask
> because I've seen a lot of object-based code that has said stuff like
> '$container{$key}';

Well, $container{$key} is how you access elements of %container in
Perl5; in Perl6 that's %container{$key}.  But in object-based P5 code,
you'd be much more likely to see $container->{$key}, where $container
contains a reference to a hash.

True; but not at all what I was referring to.

I believe in P6 you could write that
either as $container.{$key}, $container{$key} (where the . is implied
since $container{$key} can't refer to %container anymore),  or
%$container{$key}.

_This_ is closer to what I'm referring to.  As I understand it, Hash
is a role that provides (among other things) postcircumfix:<{ }>.  So
any object that does Hash should be able to call the above method.
And unless I've missed something, there's nothing in perl 6 that
insists that an object that does Hash must be assigned to a variable
that uses the '%' sigil; the '$' sigil seems to work equally well.
i.e., I've seen code to the effect of:

 class Foo does Hash { ... }
 my $obj is Foo;
 $obj<key> = 5;
 say $obj<key>;

In short, it appears that there's nothing keeping you from assigning
hash-like or list-like objects to scalar variables.

And this is without bringing references into the picture.

You aren't the only person who feels this way; there was a proposal
back in the RFC process to remove sigils in favor of "everything is a
scalar, dereference as needed".  I was in that camp myself.  But Larry
rejected that proposal, defending the utility of sigils, and I have
been swayed by the arguments, which I'm not going to repeat because I
can't say it as well, but I do advise you to go read - it was either
Apoc1 or Apoc2, I think.

I have never been in that camp.  In fact, I tend to see the points I
raise above as a bug, not a feature.

Perhaps the relationship between sigils and roles will be addressed in
the as-yet unwritten S14 (or whichever spec is supposed to address
tied variables)?

--
Jonathan "Dataweaver" Lang

Reply via email to