Xiao Yafeng wrote:
> Off the top of one's head, since there is no particular difference between
> an operator and a function, can I see a function as a operator:
> 
> (1, 2, 3, 4) >>elems<<(2, 3, 4, 5)          #(2, 2, 2, 2)
> (1, 2, 3, 4) >>shift<<(2, 3, 4, 5)          #(2, 3, 4, 5)

But remember that operators come with an associativity:

$a / $b / $c == ($a / $b) / $c # left associative
$a ** $b ** $c == $a ** ($b ** $c) # right associative

When you make a function into an operator, you need a good syntax for
defining the associativity of the new pseudo-operator.

Also note that shift(1, 2) doesn't work, because it gets a list, not an
array, and lists are immutable.

> Moreover, can I see a subroutine as a operator:
> 
> (1, 2, 3, 4) >>{$a>$b??$a!!$b}<<(2, 3, 4, 5)        #(2, 3, 4, 5)

Every operator is accessible  as a function (or a macro) already, for
example the operator in 2 + 3 is known as &infix:<+>.

The ternary is a rather ugly case, I guess it's called &infix:<??
!!>($condition, $true, $false), and it's short-circuiting, so it must be
a macro rather than normal function.

Cheers,
Moritz



-- 
Moritz Lenz
http://perlgeek.de/ |  http://perl-6.de/ | http://sudokugarden.de/

Reply via email to