Adding deref op [Was: backticks]

2004-04-21 Thread Matthijs van Duin
On Tue, Apr 20, 2004 at 10:55:51AM -0700, Larry Wall wrote:
The flip side is that, since we won't use C` as an operator in Perl
6, you're free to use it to introduce any user-defined operators
you like, including a bare C`.  All is fair if you predeclare.
Most languages won't even give you that...
I just realized there's another operator that has no infix meaning yet, and 
so is free to use (and perhaps more visually pleasing):

%hash\key   (or  $foo\bar\baz\42 )

vaguely reminiscent of DOS/Win32 paths :-D

Just curious, when adding such an operator myself, would it be possible to 
make it work on both hashes and arrays, without making the op very slow?

--
Matthijs van Duin  --  May the Forth be with you!


Re: Adding deref op [Was: backticks]

2004-04-21 Thread Matthijs van Duin
On Wed, Apr 21, 2004 at 01:02:15PM -0600, Luke Palmer wrote:
   macro infix:\ ($cont, $key)
   is parsed(/$?key := (-?letter\w* | \d+)/)
   {
   if $key ~~ /^\d+$/ {
   ($cont).[$key];
   }
   else {
   ($cont).«$key»;
   }
   }
That does all the magic at compile time.
True, but what about  $x\$y ? :-)

(which I'd want to work for consistency reasons.. so you can write 
$foo\bar\$baz\42 instead of ugly mixing like $foo\foo{baz}\42 )

--
Matthijs van Duin  --  May the Forth be with you!


Re: Adding deref op [Was: backticks]

2004-04-21 Thread John Macdonald
On Wed, Apr 21, 2004 at 09:19:12PM +0200, Matthijs van Duin wrote:
 On Wed, Apr 21, 2004 at 01:02:15PM -0600, Luke Palmer wrote:
macro infix:\ ($cont, $key)
is parsed(/$?key := (-?letter\w* | \d+)/)
{
if $key ~~ /^\d+$/ {
($cont).[$key];
}
else {
($cont).«$key»;
}
}
 
 That does all the magic at compile time.
 
 True, but what about  $x\$y ? :-)

What about $x\n?  The backslash already has
meaning in strings, yet interpolating hashed
values is a common need.  There's a similar
problem inside a regex, where backslash would
be ambiguous.  The ambiguity can be resolved,
perhaps, but the confusion would make \ a poor
choice.

-- 


Re: Adding deref op [Was: backticks]

2004-04-21 Thread Matthijs van Duin
On Wed, Apr 21, 2004 at 03:37:23PM -0400, John Macdonald wrote:
What about $x\n?  The backslash already has meaning in strings
I use hash elements far more often outside than inside strings, so I could 
live with having to write $x«foo» for interpolated hash elements.

Anyway, you're missing the point of my question.  Since shorthand for hash 
elements has already been banned from the core by Larry, I'm now just 
exploring what is involved with adding it later on, independent of what 
actual syntax I'd use (a bashtick, backslash, or something else).

--
Matthijs van Duin  --  May the Forth be with you!