colon-equals

Why is := allowed as an infix operator?

不问归期 提交于 2019-11-28 00:40:32
I have come across the popular data.table package and one thing in particular intrigued me. It has an in-place assignment operator := This is not defined in base R. In fact if you didn't load the data.table package, it would have raised an error if you had tried to used it (e.g., a := 2 ) with the message: Error: could not find function ":=" Also, why does := work? Why does R let you define := as infix operator while every other infix function has to be surrounded by %% , e.g. `:=` <- function(a, b) { paste(a,b) } "abc" := "def" Clearly it's not meant to be an alternative syntax to %function

no new variables on left side of :=

假如想象 提交于 2019-11-27 19:56:50
What's happening here? package main import "fmt" func main() { myArray :=[...]int{12,14,26} ; fmt.Println(myArray) myArray :=[...]int{11,12,14} //error pointing on this line fmt.Println(myArray) ; } It throws an error that says no new variables on left side of := What I was doing was re-assigning values to an already declared variable. Yogendra Singh Remove the colon : from the second statement as you are assigning a new value to existing variable. myArray = [...]int{11,12,14} colon : is used when you perform the short declaration and assignment for the first time as you are doing in your

What does “:=” do?

痴心易碎 提交于 2019-11-27 17:45:57
I've seen := used in several code samples, but never with an accompanying explanation. It's not exactly possible to google its use without knowing the proper name for it. What does it do? http://en.wikipedia.org/wiki/Equals_sign#In_computer_programming In computer programming languages, the equals sign typically denotes either a boolean operator to test equality of values (e.g. as in Pascal or Eiffel), which is consistent with the symbol's usage in mathematics, or an assignment operator (e.g. as in C-like languages). Languages making the former choice often use a colon-equals (:=) or ≔ to

no new variables on left side of :=

大憨熊 提交于 2019-11-27 11:24:08
问题 What's happening here? package main import "fmt" func main() { myArray :=[...]int{12,14,26} ; fmt.Println(myArray) myArray :=[...]int{11,12,14} //error pointing on this line fmt.Println(myArray) ; } It throws an error that says no new variables on left side of := What I was doing was re-assigning values to an already declared variable. 回答1: Remove the colon : from the second statement as you are assigning a new value to existing variable. myArray = [...]int{11,12,14} colon : is used when you

What does mean the colon with equal sign “:=”

限于喜欢 提交于 2019-11-27 08:08:43
问题 If foud this code: ActiveCell.Offset(-5, -1).Range("A1:E1").Cut Destination:=ActiveCell.Range( _ "A1:E1") I can't find any reference about ":=". What does it mean? 回答1: := is used with named arguments. In this case, Destination is the name of an argument to the Cut method, and the other side is its value. See https://docs.microsoft.com/en-us/office/vba/language/concepts/getting-started/understanding-named-arguments-and-optional-arguments for an example. 来源: https://stackoverflow.com/questions

Why has data.table defined := rather than overloading <-?

让人想犯罪 __ 提交于 2019-11-27 07:04:21
data.table has introduced the := operator. Why not overload <-? I don't think there is any technical reason this should be necessary, for the following reason: := is only used inside [...] so it is always quoted. [...] goes through the expression tree to see if := is in it. That means it's not really acting as an operator and it's not really overloaded; so they could have picked pretty much any operator they wanted. I guess maybe it looked better? Or less confusing because it's clearly not <- ? (Note that if := were used outside of [...] it could not be <- , because you can't actually overload

Why is := allowed as an infix operator?

☆樱花仙子☆ 提交于 2019-11-27 04:45:01
问题 I have come across the popular data.table package and one thing in particular intrigued me. It has an in-place assignment operator := This is not defined in base R. In fact if you didn't load the data.table package, it would have raised an error if you had tried to used it (e.g., a := 2 ) with the message: Error: could not find function ":=" Also, why does := work? Why does R let you define := as infix operator while every other infix function has to be surrounded by %% , e.g. `:=` <-

What does “:=” do?

Deadly 提交于 2019-11-26 19:06:55
问题 I've seen := used in several code samples, but never with an accompanying explanation. It's not exactly possible to google its use without knowing the proper name for it. What does it do? 回答1: http://en.wikipedia.org/wiki/Equals_sign#In_computer_programming In computer programming languages, the equals sign typically denotes either a boolean operator to test equality of values (e.g. as in Pascal or Eiffel), which is consistent with the symbol's usage in mathematics, or an assignment operator

When should I use the := operator in data.table?

旧时模样 提交于 2019-11-26 15:44:36
data.table objects now have a := operator. What makes this operator different from all other assignment operators? Also, what are its uses, how much faster is it, and when should it be avoided? Here is an example showing 10 minutes reduced to 1 second (from NEWS on homepage ). It's like subassigning to a data.frame but doesn't copy the entire table each time. m = matrix(1,nrow=100000,ncol=100) DF = as.data.frame(m) DT = as.data.table(m) system.time(for (i in 1:1000) DF[i,1] <- i) user system elapsed 287.062 302.627 591.984 system.time(for (i in 1:1000) DT[i,V1:=i]) user system elapsed 1.148 0

Why has data.table defined := rather than overloading <-?

点点圈 提交于 2019-11-26 13:01:21
问题 data.table has introduced the := operator. Why not overload <-? 回答1: I don't think there is any technical reason this should be necessary, for the following reason: := is only used inside [...] so it is always quoted. [...] goes through the expression tree to see if := is in it. That means it's not really acting as an operator and it's not really overloaded; so they could have picked pretty much any operator they wanted. I guess maybe it looked better? Or less confusing because it's clearly