Sure it can
Apologies for the screenshot, I just googled “i = 1, 2…” to find the first example.
Surely the above represents that i is 1, then it is 2, and so forth until k
, and is also clearly, and by far, the most natural aspect of the expression! So i
can be reassigned at will
For context, my first language was R (and there was a two year eternity before I learned another…), and I did not find myself using the <-
assignment operator even once. I found it extremely unnatural from the beginning, while repeatedly assigning the same variable did not seem unusual to me at all. So likely, this all amounts very strongly to a matter of taste.
2 Likes
No it cannot
This notation is, at least to me, wrong. i
is not equal to multiple values, it is in
. The best would have been:
i \in \left\[\!\left[1, k\right]\right]
See Interval (mathematics) - Wikipedia
For your screenshot: I just don’t get why someone would mixed up notations. 1 ... k
means nothing, while {1 ... k}
, although not perfect, would have been better and consistent with {p \in D [...]}
Yet, I agree with you. I learned R (not as my first language) and avoided <-
. In fact I think that @Tamas_Papp is right, <-
should be avoided and it should be clearly stated that =
is not the mathematical equality.
1 Like
I don’t think you can. Only at the toplevel.
FWIW, I have heard two justifications for <-
in R:
-
there is a version that goes the other way. Eg
> 3 -> a
> a
[1] 3
But very few people use this in the wild. I think it is just a confusing gimmick and makes code less readable.
-
Consistency with <<-
and its evil twin ->>
. This is not an issue for Julia as it has no equivalent, because it subscribed to a model of scope other than “kitchen sink”, a fact that we should really appreciate.
1 Like
I considered addressing this in advance, but opted against ultimately. Yes, you could say this should be written otherwise, but the point is it is perfectly clear and unambiguous. =
, like all other symbols, is merely notation, and just like its use in that equation is perfectly clear (everyone seems to read i = 1, ..., k
“correctly”), the assignment operator in code is also clear an unambiguous. a = 1; a = 2;
can have only one meaning.
I’m tempted to disagree because I’m pretty sure I did, but it’s been long enough that I’m not confident in that anymore…
I don’t know, I think we (or only I?) just naturally translate this notation into something that is correct. But it’s like {a real : a < s_i for i = [1,5]]
. Everything is “wrong” here and the fact that you get the point (e.g. by correcting the last ]
with }
or by understanding that i
is an integer) doesn’t make it right. That’s to say that I get that students can be frustrated by the “abuse of notation” that we use when programming. But @Tamas_Papp solved it to me: I should not try to teach the concept without =
but rather define this new use of the equality and stick with it.
Same as @tomerarnon, maybe I used <-
in R and concealed it deep in my memory.
@Impressium Sorry for the digression, I wanted to ask a quick question and that led to an interesting disagreement
Edit: for the context, I barely started teaching (no lectures, just exercises) so I am interested in tips on this kind of basic concepts, thus my initial question.
Maybe not that important but, you can use =
everywhere in R and the R documentation is subtly wrong (or just confusing). For example, system.time({a = rnorm(1e6)})
or system.time((a = rnorm(1e6)))
works and is the same as system.time(a <- rnorm(1e6))
. I think this has to do with brackets creating a subexpression and then =
is interpreted as an assignment rather than a syntactical token for named arguments inside function calls… the kind of “feature” that can create a lot of silent bugs…