# Why is \`=\` no function

**URL:** <https://discourse.julialang.org/t/why-is-no-function/47304>\
**Category:** Internals & Design\
**Tags:** question\
**Created:** [September 26, 2020, 10:03am UTC](https://discourse.julialang.org/t/why-is-no-function/47304 "2020-09-26T10:03:09Z")\
**Posts on this page:** 7\
**Page:** 2

<div class="post-metadata">

**Author:** ![tomerarnon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomerarnon/32/3170_2.png) [@tomerarnon](https://discourse.julialang.org/u/tomerarnon)\
**Post date:** [September 28, 2020, 11:58am UTC](https://discourse.julialang.org/t/why-is-no-function/47304/22 "2020-09-28T11:58:39Z")

</div>

Sure it can 😅  
Apologies for the screenshot, I just googled “i = 1, 2…” to find the first example.

 ![Screen Shot 2020-09-28 at 2.52.24 PM](https://global.discourse-cdn.com/julialang/original/3X/2/9/2900b1d59d60e98d5a546acf4608f867f73d7f3a.png)

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.

---

<div class="post-metadata">

**Author:** ![remi-garcia](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/remi-garcia/32/7125_2.png) [@remi-garcia](https://discourse.julialang.org/u/remi-garcia)\
**Post date:** [September 28, 2020, 12:07pm UTC](https://discourse.julialang.org/t/why-is-no-function/47304/23 "2020-09-28T12:07:38Z")

</div>

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:

```tex
i \in \left\[\!\left[1, k\right]\right]

```

See [Interval (mathematics) - Wikipedia](https://en.wikipedia.org/wiki/Interval_(mathematics)#Integer_intervals)

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.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [September 28, 2020, 12:15pm UTC](https://discourse.julialang.org/t/why-is-no-function/47304/24 "2020-09-28T12:15:19Z")

</div>

> [@remi-garcia](#):
>
> I learned R (not as my first language) and avoided `<-` .

I don’t think you can. Only at the toplevel.

FWIW, I have heard two justifications for `<-` in R:

1. there is a version that _goes the other way_. Eg

2. 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.

---

<div class="post-metadata">

**Author:** ![tomerarnon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomerarnon/32/3170_2.png) [@tomerarnon](https://discourse.julialang.org/u/tomerarnon)\
**Post date:** [September 28, 2020, 12:34pm UTC](https://discourse.julialang.org/t/why-is-no-function/47304/25 "2020-09-28T12:34:06Z")

</div>

> [@remi-garcia](#):
>
> This notation is, at least to me, wrong.

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.

> [@Tamas\_Papp](#):
>
> I don’t think you can. Only at the toplevel.

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…

---

<div class="post-metadata">

**Author:** ![remi-garcia](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/remi-garcia/32/7125_2.png) [@remi-garcia](https://discourse.julialang.org/u/remi-garcia)\
**Post date:** [September 28, 2020, 12:50pm UTC](https://discourse.julialang.org/t/why-is-no-function/47304/26 "2020-09-28T12:50:32Z")

</div>

> [@tomerarnon](#):
>
> the point is it is perfectly clear and unambiguous

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.

> [@tomerarnon](#):
>
> > [@Tamas\_Papp](#):
> >
> > I don’t think you can. Only at the toplevel.
> 
> 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…

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.

---

<div class="post-metadata">

**Author:** ![AleMorales](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alemorales/32/48720_2.png) [@AleMorales](https://discourse.julialang.org/u/AleMorales)\
**Post date:** [October 20, 2020, 8:02am UTC](https://discourse.julialang.org/t/why-is-no-function/47304/27 "2020-10-20T08:02:42Z")

</div>

> [@Tamas\_Papp](#):
>
> I don’t think you can. Only at the toplevel.

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…

---

<div class="post-metadata">

**Author:** ![sashmit](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sashmit/32/18791_2.png) [@sashmit](https://discourse.julialang.org/u/sashmit)\
**Post date:** [October 20, 2020, 8:08pm UTC](https://discourse.julialang.org/t/why-is-no-function/47304/28 "2020-10-20T20:08:31Z")

</div>

(post deleted by author)

[Previous page](https://discourse.julialang.org/t/why-is-no-function/47304.md?page=1)
