Hacker News new | past | comments | ask | show | jobs | submit login

Even better than that, if you create a new infix operator:

    sub infix:<OP> ( $a, $b ) {…}
You get `OP=` for free:

    $x OP= $y; # $x = $x OP $y
That is because `=` is actually a meta operator. (It takes an infix operator as a sort-of argument.)

    $x [OP]= $y; # more explicit that `OP` is an argument to `=`
---

You could also just use a regular subroutine as if it was an infix operator:

    sub foo ( $a, $b ) {…}

    $x [&foo] $y; # foo( $x, $y )
So you can also use it with the `=` meta operator:

    $x [&foo]= $y; # $x = foo( $x, $y )



Some people demonize languages for adding syntactic suggar, but I think this is what can make them really great. It raises the language (perl6 in this case) to a meta programming level. In a similiar way people refer to LISP as a meta programming language (while there the "meta" stems from the powerful macro language which again is LISP). I love that.




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: