【发布时间】:2017-12-08 23:20:01
【问题描述】:
我对@987654321@ 的性质感到困惑,我无法像使用其他运算符那样得到它的定义,而且它的行为也不像<-。见下文:
print(`<-`) # .Primitive("<-")
print(`->`) # Error in print(`->`) : object '->' not found
此外,我无法劫持它,但如果我尝试,R 不会触发任何错误:
`->` = `+` # attempting to hijack `->`, no error
print(`->`) # function (e1, e2) .Primitive("+"), seems like it worked
1 -> 3 # Error in 3 <- 1 : invalid (do_set) left-hand side to assignment
1 -> test1
print(test1) # 1, hijacking failed
`->`(1,3) # 4, this works
使用<-(或我尝试过的任何其他运算符),我可以做到:
`<-` = `+`
print(`<-`)
1 <- 3 # 4
1 <- test2 # Error: object 'test2' not found
rm(list=ls()) # back to sanity
那么发生了什么?
【问题讨论】:
标签: r operators assignment-operator