Why does `:=` work as an infix operator?
Why does the following work in R?
> `:=` <- function(x, y) x + y
> 1 := 2
[1] 3
My understanding was that %
was required for user开发者_如何学Python-defined infix operators. Are there other (possibly easier to type) options available?
This is because :=
is, like <-
or <<-
, defined as LEFT_ASSIGN
for the parser of R.
See http://svn.r-project.org/R/trunk/src/main/gram.y
This means that :=
is a special case and you may as well not expect that any other options are available.
精彩评论