Re: How do I... create a new meta operator?

2005-05-20 Thread TSa (Thomas Sandlaß)
HaloO Luke,
you wrote:
I wonder how we specify meta
operators that only work on comparators, or only on assignment forms,
or etc. etc. etc.
Well, Perl6 has got first class Code types, hasn't it?
So it's a matter of defining a type hierarchy among the
operators and then you can dispatch on them with MMD or
restrict applicable types for non-invocant params.
Ingo's &infix_circumfix_meta_operator:{'->', '<-'}:(Code,Any,Any:)
could then easily be specialized like
 &infix_circumfix_meta_operator:{'->', '<-'}
  :(Comparator of ::T, T does Compare[T], T does Compare[T] :)
or less specific, of course.
The above said, I hope that the degree to which meta ops are
macro/compiler supported versus how much they lean onto the
type system is favoring the type system. The typical Perl < 6
programmer seems for historical reasons more inclined to think
about this language feature more in terms of combinations of
eval, join and split. E.g. could the macro assistence for »« and []
be restricted to parse their inside as an operator name so that
the programmer doesn't have to use their long name? Or is something
more complicated needed? And if yes, then why?
Regards,
--
TSa (Thomas Sandlaß)


Re: How do I... create a new meta operator?

2005-05-19 Thread Luke Palmer
On 5/19/05, Ingo Blechschmidt <[EMAIL PROTECTED]> wrote:
> Hi,
> 
> quoting A12:
> > infix_postfix_meta_operator:<=> $x += 2;
> > postfix_prefix_meta_operator:{'»'} @array »++
> > prefix_postfix_meta_operator:{'«'} -« @magnitudes
> > infix_circumfix_meta_operator:{'»','«'}   @a »+« @b
> 
> so will the following work?
> 
>   # Silly example
>   sub infix_circumfix_meta_operator:{'->', '<-'} (
> Code &op,
> $left, $right,
>   ) {
> op $left + 1, $right + 1;
>   }
> 
>   say 2 ->+<- 3;  # 7
>   say 2 ->*<- 3;  # 12

That looks approximately right.  I wonder how we specify meta
operators that only work on comparators, or only on assignment forms,
or etc. etc. etc.

Luke


How do I... create a new meta operator?

2005-05-19 Thread Ingo Blechschmidt
Hi,

quoting A12:
> infix_postfix_meta_operator:<=> $x += 2;
> postfix_prefix_meta_operator:{'Â'} @array Â++
> prefix_postfix_meta_operator:{'Â'} -Â @magnitudes
> infix_circumfix_meta_operator:{'Â','Â'}   @a Â+Â @b

so will the following work?

  # Silly example
  sub infix_circumfix_meta_operator:{'->', '<-'} (
Code &op,
$left, $right,
  ) {
op $left + 1, $right + 1;
  }

  say 2 ->+<- 3;  # 7
  say 2 ->*<- 3;  # 12


--Ingo

-- 
Linux, the choice of a GNU | Time sharing - the use of many people by
generation on a dual AMD   | the computer.  
Athlon!|