I come from R where you can define methods for assignment e.g.
`[<-.classname` <- function(x, i, j, value) {
# some code
}
later on you can use it like this
class(some_var) <- "classname"
some_var[some_num] <- new_value
will call the [<-.classname function. I wonder if Julia’s [ is also defined in such a way?
Consider the following example in Julia
using DataFrames
df = DataFrame([[1],[2]])
df[:x3] = df[:x1] + df[:x2]
How does Julia know that df[:x3] means create a new column? I tried to look at at DataFrames.jl’s source code but can only find that DataFrame is defined as <: AbstractDataFrame, so it’s not clear how to define my own [= function so that if I define a type NewType and newtype is of NewType, then can I define the below like I can in R
newtype[some_thing] = some_value