As far as I understand, Julia interprets =
and in
synonymously in list comprehension. Also, some types, like numbers, are iterable where they are interpreted as singletons, so [x*x for x in 2]
gives 4
. This feels a bit too much overloaded for me, why not make in
assume that some array-like type is given and = T
be treated as in [T]
? So that e.g. [x*x for x in [2]]
and [x*x for x = 2]
both return 4
but [x*x for x in 2]
returns an error?
My personal history is that I had the hunch that Julia maybe treats = T
as in [T]
in list comprehension, so I tried it with a number and it worked, but not for the reason that I assumed, so later I had = CartesianIndex(i, j)
somewhere in my code and got an error because cartesian indices are not iterable. Took me some while to figure out what is going on.
Irrelevant of the potential pros and cons, the change would be huge and so you might want to read this post by Stefan: https://discourse.julialang.org/t/psa-julia-is-not-at-that-stage-of-development-anymore/44872
I don't think giving them different meanings is a good idea, especially because for i = ...
is also used in MatLab. I do think, it might make sense to differentiate the two in the AST at least, so macros could at least differentiate them, but that would probably have to be a 2.0 thing. It might also be more of a hassle than what it's actually worth though.
If anything I would just deprecate =
here.
Thanks for the comments, they make sense and I learned something. Sorry for not reading Stefan's post in beforehand.
Most helpful comment
If anything I would just deprecate
=
here.