Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

syntax

r

Why does the following work in R?

> `:=` <- function(x, y) x + y
> 1 := 2
[1] 3

My understanding was that % was required for user-defined infix operators. Are there other (possibly easier to type) options available?

like image 237
pete Avatar asked Sep 14 '11 00:09

pete


People also ask

What is operator in infix?

infix operator (plural infix operators) (computing) an operator that is placed in between the operands like it is commonly used in arithmetical and logical formulae and statements. The plus sign in "2 + 2" is placed as an infix operator in arithmetic.

What is the use of infix?

Infix notation is the notation commonly used in arithmetical and logical formulae and statements. It is characterized by the placement of operators between operands—"infixed operators"—such as the plus sign in 2 + 2.

What is an infix operator in R?

- Infix operators are a fancy name for operator symbols that go between two variables. Think of them like plus signs or a multiplication sign or division sign. So you can add three plus four, like this, three plus four. And in this case the plus is an infix operator.

What does infix mean in Python?

Infix operators are used in between two operands, so simple arithmetic operations such as 1 + 2 would be an infix expression where + is the infix operand. Prefix and postfix operators are either applied before or after a single operand.


1 Answers

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.

like image 156
kohske Avatar answered Oct 26 '22 23:10

kohske