develooper Front page | perl.perl6.language | Postings from May 2005

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

Thread Next
From:
Ingo Blechschmidt
Date:
May 19, 2005 13:44
Subject:
How do I... create a new meta operator?
Message ID:
d6itkh$5nt$1@sea.gmane.org
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!                    | 


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About