Phoenix.pm: quoting constant hash keys survey
Scott Walters
scott at illogics.org
Fri Apr 16 20:30:41 CDT 2004
Hi folks,
I'm soliciting opinions - no experience with Perl beyond the basics are required
so this isn't for experts only. I want as many opinions as I can get.
It was recently proposed in Perl 6 that %foo{bar} would now always mean %foo{bar()}
rather than %foo{'bar'}. This is part of the general move away from barewords.
This also surprises some people as things like my $foo = shift; means shift(),
not 'shift', so Perl's generally tendencies are reversed in hash subscripts. This
is usually the right thing to do but requires programmers to be aware of it.
So %foo<<bar>> and a difficult to type UNICODE version with gulimets where the
<< and >> are each one character does the same thing as %foo{'bar'} -
So...
%foo{'bar'} is the same as %foo<<bar>>
and
%foo{bar} is the same as %foo{bar()}
The discussion became interesting when people complaiend that %foo<<bar>> really
doesn't save any characters and both are optimized towards the uncommon case
of allowing slices. In P6, slices happen when multiple keys are fed to a hash,
not when the $ is swapped for a % as in Perl 5. Hence all of these examples are
non-slice hash lookups.
Someone proposed that %foo`bar be offered to optimize the common case of
%foo<<bar>> where no slice is being taken and the subscript is a variable or
constant. So %foo`$bar would be valid as well, but that would probabaly
tend to be written as %foo{$bar} for clarity. So...
%foo{'bar'} is the same as %foo<<bar>> is the same as %foo`bar
and
%foo{bar} is the same as %foo{bar()}
Tick, `, was selected because it doesn't currently have any meaning in that
context - %foo `ls` isn't valid Perl. Other characters that also don't have an
operator state meaning were rejected for other reasons.
So, the survey question is, should this meaning of ` be or not be included
in Perl 6?
Pros:
* Mismatched bracket characters often generate typos and syntax errors - matching
bracketing characters is tedious
* 2 keystrokes plus variable and subcript names versus 5
* Caters to JavaScript programmers who are used to writing things like
document.forms.myform.submit(), bluring the distinction between hash subscripts
and method calls (in Perl 6, that might be %document`forms`myform.submit(), or
in Perl 5, $document{forms}{myform}->submit() )
* ` might generalize to quoting single words, making the removal of barewords
less painful
Cons:
* %foo`bar doesn't look like a hash subscript if you're used to %foo{'bar'}
* Could be used to write really terse code
* Ugly
* Perl 6 already has 2 ways to subscript hashes now, 3 is too many
* People who really want something like that can extend the language using Perl 6's
equivilent to source filters
Okey, everyone run and vote - yea or nay. Let's hear it. Even if your reasons are
unfounded, vote.
-scott
More information about the Phoenix-pm
mailing list