in reply to Dotted hash access

Isn't this problem supposed to be corrected in Perl6?

I'm not really a human, but I play one on earth. flash japh

Replies are listed 'Best First'.
Re^2: Dotted hash access
by TimToady (Parson) on Nov 25, 2004 at 20:57 UTC
    That depends on which part of the problem you're talking about. It would be easy to define a dialect of Perl 6 that allowed this, but there is as of yet no standard path notation other than
    %hash«Foo»«Bar»«Baz»
    If I were going to make a dialect, I'd probably throw in a
    use supersubscripts;
    which would let me write
    %hash«Foo/Bar/Baz»
    instead to mean the same thing. But it's not clear that something like that should be inflicted on everyone unless the syntax were less likely to be confusing to someone who really means
    %hash{'Foo/Bar/Baz'}
    to mean a single key with slashes in it. It would need a more distinctive prefix if we were to build it in, and unfortunately we're really low on bracket characters, even with the addition of «», which we've already found lots of uses for. (Some would say too many... :-)

    So the answer to your question is probably "no" for now...

Re^2: Dotted hash access
by Juerd (Abbot) on Nov 25, 2004 at 21:44 UTC

    Isn't this problem supposed to be corrected in Perl6?

    For several reasons, the dot cannot be used safely for hash access. I proposed backticks for this purpose, but it's not going to happen, because many find it too ugly (since when is that reason to not do something in Perl?), and the powers that be have decided. See also http://groups.google.com/groups?selm=20040414121848.GJ3645%40c4.convolution.nl;

    Still, I think it elegantly solves the problem.

    $cost = $h->{Locations}{$location}{Buildings}{$b}{cost};
    would be written as
    $cost = $h`Locations`$location`Buildings`$b`cost;

    I want this for two reasons:

    1. Typing { and } repeatedly is hard, at least for my hands
    2. Typing {'key'} or «key» is even harder
    Realise that
    $cost = $h->{Locations}{$location}{Buildings}{$b}{cost};
    will be
    $cost = $h{'Locations'}{$location}{'Buildings'}{$b}{'cost'};
    or
    $cost = $h«Locations»{$location}«Buildings»{$b}«cost»;
    in Perl 6.

    IMO, the OP has a good point. Hash access is nice, and the syntax is certainly doable, but it gets tedious for accessing an deep element in a HoHoHoH. And even though many things are made much easier by Perl 6, this specific thing is IMHO made much worse.

    (Please, let's not start another "write your own grammar" subthread.)

    Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }