开发者

Why does `:=` work as an infix operator?

开发者 https://www.devze.com 2023-04-04 12:12 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消