# Aliases for \`=\` and \`==\`

**URL:** <https://discourse.julialang.org/t/aliases-for-and/60004>\
**Category:** Internals & Design\
**Tags:** proposal\
**Created:** [April 25, 2021, 9:35pm UTC](https://discourse.julialang.org/t/aliases-for-and/60004 "2021-04-25T21:35:44Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![ParadaCarleton](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paradacarleton/32/20005_2.png) [@ParadaCarleton](https://discourse.julialang.org/u/ParadaCarleton)\
**Post date:** [April 25, 2021, 9:35pm UTC](https://discourse.julialang.org/t/aliases-for-and/60004/1 "2021-04-25T21:35:44Z")

</div>

I think it makes sense to set `:=` and `=?` as aliases for `=` and `==` respectively. The first one helps those coming from Python or Pascal, where `:=` is valid syntax, and can also improve the readability of code. `=?` strikes me as more intuitive and readable than `==`. I think it still makes sense to keep `=` and `==` for those coming from more traditional languages, though.

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [April 25, 2021, 10:11pm UTC](https://discourse.julialang.org/t/aliases-for-and/60004/2 "2021-04-25T22:11:05Z")

</div>

> [@ParadaCarleton](#):
>
> Python or similar languages, where `:=` is valid syntax

Is it? Seems to me pretty much the same as in Julia:

```python
Python 3.8.3 (default, May 19 2020, 18:47:26) 
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> x = 1
>>> x
1
>>> x := 1
  File "<stdin>", line 1
    x := 1
      ^
SyntaxError: invalid syntax
>>> 1 =? 2
  File "<stdin>", line 1
    1 =? 2
       ^
SyntaxError: invalid syntax
>>> x == 1
True
>>> 

```

---

<div class="post-metadata">

**Author:** ![Satvik](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/satvik/32/20486_2.png) [@Satvik](https://discourse.julialang.org/u/Satvik)\
**Post date:** [April 25, 2021, 10:17pm UTC](https://discourse.julialang.org/t/aliases-for-and/60004/3 "2021-04-25T22:17:51Z")

</div>

`:=` means something pretty different from `=` in Python (3.8 and higher): [PEP 572 – Assignment Expressions | peps.python.org](https://www.python.org/dev/peps/pep-0572/#syntax-and-semantics). I think it would be pretty confusing to make it an alias of `=`

---

<div class="post-metadata">

**Author:** ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)\
**Post date:** [April 25, 2021, 10:35pm UTC](https://discourse.julialang.org/t/aliases-for-and/60004/4 "2021-04-25T22:35:39Z")

</div>

Stefan once suggested an idea that I’m a fan of, of letting `a := b` be similar to

```julia
var"#tmp#1231#" = b
a::typeof(var"#tmp#1231#") = var"#tmp#1231#" 

```

That is, we could use this syntax for making type stable declarations.

One the one hand, this syntax is strictly limiting – it doesn’t let you do anything you couldn’t do before, instead simply taking possibilities away.  
On the other hand, most of us (myself included) have spent a lot of time hunting for type instabilities, particularly when using lots of closures, so a convenient syntax for this could be a time saver.

My point here though is that if we add new syntax, it should have definite advantages.

---

<div class="post-metadata">

**Author:** ![ParadaCarleton](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paradacarleton/32/20005_2.png) [@ParadaCarleton](https://discourse.julialang.org/u/ParadaCarleton)\
**Post date:** [April 26, 2021, 12:14am UTC](https://discourse.julialang.org/t/aliases-for-and/60004/5 "2021-04-26T00:14:09Z")

</div>

It does mean something different in Python, where `=` has no return value; there, `:=` combines assignment and returns the right-hand side.

```julia
(x:=2)**2
Out[1]: 4

x
Out[2]: 2

(x=2)**2
  File "<ipython-input-3-25b7a63e2328>", line 1
    (x=2)**2
      ^
SyntaxError: invalid syntax

```

In Julia, `=` means the same thing as `:=` does in Python:

```julia
julia> (x=2)^2
4

julia> x
2

```

`=` behaves like `:=` does in Python, so making `:=` an alias of `=` will result in the same behavior for `:=` in both Julia and Python. The only difference I’m aware of here is that `:=` would not throw an error when used outside of a function or expression, but that shouldn’t cause any problems for someone coming in from Python (although it could theoretically cause trouble when going in the opposite direction, which strikes me as a sensible argument against).

---

<div class="post-metadata">

**Author:** ![ParadaCarleton](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paradacarleton/32/20005_2.png) [@ParadaCarleton](https://discourse.julialang.org/u/ParadaCarleton)\
**Post date:** [April 26, 2021, 12:28am UTC](https://discourse.julialang.org/t/aliases-for-and/60004/6 "2021-04-26T00:28:11Z")

</div>

This seems like it could cause some potential confusion with languages like Pascal or Python where `:=` does not imply type stability; I’d suggest a keyword like `stable` or similar (e.g. `stable x = 2.0`) to avoid this confusion.

Both suggested aliases do have a significant advantage, namely improving readability of code by clearly distinguishing assignment from evaluation.

---

<div class="post-metadata">

**Author:** ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)\
**Post date:** [April 26, 2021, 12:39am UTC](https://discourse.julialang.org/t/aliases-for-and/60004/7 "2021-04-26T00:39:23Z")

</div>

That example is only worth it if it’s very succinct syntax, otherwise

```julia
macro stable(ex)
    Meta.isexpr(ex, :(=), 2) || throw(ArgumentError("`@stable` macro requires assignment."))
    quote
        tmp = $(esc(ex.args[2]))
        $(esc(ex.args[1]))::typeof(tmp) = tmp
    end
end

```

is easy enough to write.

I’d prefer not having syntax that (a) has no advantage over what someone can do in a library/with their own code (e.g. `@stable` vs `stable`), or is useless like `:=` being an alias to `=`.

---

<div class="post-metadata">

**Author:** ![jzr](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jzr](https://discourse.julialang.org/u/jzr)\
**Post date:** [April 26, 2021, 1:07am UTC](https://discourse.julialang.org/t/aliases-for-and/60004/8 "2021-04-26T01:07:42Z")

</div>

> **[Why Does "=" Mean Assignment?](https://www.hillelwayne.com/equals-as-assignment/)**
>
> Take the following code:
> a = 1 a = a + 1 print(a) A common FP critique of imperative programming goes like this: “How can a = a + 1? That’s like saying 1 = 2. Mutable assignment makes no sense.” This is a notation mismatch: “equals” should mean...

---

<div class="post-metadata">

**Author:** ![ParadaCarleton](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paradacarleton/32/20005_2.png) [@ParadaCarleton](https://discourse.julialang.org/u/ParadaCarleton)\
**Post date:** [April 26, 2021, 2:53am UTC](https://discourse.julialang.org/t/aliases-for-and/60004/9 "2021-04-26T02:53:07Z")

</div>

Saying `:=` is useless because you have `=` already feels like saying `x ⋅ y` is useless because we already have `dot(x, y)`. They might both do the same thing, but one is a lot more readable and aligns more closely with notation in theoretical work/mathematics. `:=` is commonly used in computer science papers for assignment because it is unambiguous, and it’s more readable than `=`; `dot` is there for accessibility (for those who don’t know how to use Unicode). I don’t see a reason to treat `≔` (or `:=` to avoid Unicode) any differently.

As for the comment on a stable keyword, that seems like a reasonable comment, but I don’t see why you’re shooting down your own proposal.

---

<div class="post-metadata">

**Author:** ![apo383](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/apo383/32/11272_2.png) [@apo383](https://discourse.julialang.org/u/apo383)\
**Post date:** [April 26, 2021, 3:39am UTC](https://discourse.julialang.org/t/aliases-for-and/60004/10 "2021-04-26T03:39:21Z")

</div>

> [@ParadaCarleton](#):
>
> `x ⋅ y` is useless because we already have `dot(x, y)`

The difference is that `⋅` is not just Unicode, but also an infix operator with syntactical sugar. To make `:=` an alias of `=` would just be noise. (Imagine reading code that mixes the two.) Also, it is not necessarily the goal of Julia to emulate Python. Any language should reasonably consider more fundamental reasons to adopt a particular syntax.

Now, there is serious argument that `=` is just poor syntax, dating back at least 60 years. Niklaus Wirth (and probably others earlier) argued as such, and we had `:=` as early as ALGOL (and Pascal as you note). The arguments still hold today, and might better support your proposal here, especially with `:=` replacing `=`. However, this would be quite the breaking change, so it would be more apt to propose for something like Julia 2.0. No such change, no matter how wonderful, would be considered before that version.

Your idea for `=?` is also stronger as a replacement. But then does your issue with `==` disappear once `=` is gone? It’s unclear whether you would keep `<`, or turn that into `<?`. It might help if you clarify your suggestion. Julia is not yet taking the approach of Python Extension Proposals (PEPs), but any big change probably needs a very seriously argued basis.

---

<div class="post-metadata">

**Author:** ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Post date:** [April 26, 2021, 3:42am UTC](https://discourse.julialang.org/t/aliases-for-and/60004/11 "2021-04-26T03:42:17Z")

</div>

I certainly don’t speak for everyone else, but I would _conjecture_ that many here disagree that your proposals are “more readable”

---

<div class="post-metadata">

**Author:** ![maxkapur](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maxkapur/32/21208_2.png) [@maxkapur](https://discourse.julialang.org/u/maxkapur)\
**Post date:** [April 26, 2021, 4:26am UTC](https://discourse.julialang.org/t/aliases-for-and/60004/12 "2021-04-26T04:26:53Z")

</div>

Aliasing `==` to `=?` would seem to also demand aliasing `===` to `==?`, but this invites further confusion, because `==?` might read to some as an alias of `==`.

And then wouldn’t users come to expect `>=?` and the like as well?

I don’t come from a CS background, but it seems to me that a maxim of “more synonyms is always good” could invite considerable bloat into the language down the line. There will always be _someone_ who favors adding a new alias you haven’t thought of. Why not alias `≡` as well? (Oh, looks like that one is already aliased to `===`.) What about `≜` (in LaTeX, `\triangleq`)?

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [April 26, 2021, 5:15am UTC](https://discourse.julialang.org/t/aliases-for-and/60004/13 "2021-04-26T05:15:02Z")

</div>

I _wish_ that from the beginning `:=` were assignment, `=` were equality test, and `==` were identity test. Then negation would be accomplished by simply prepending a `!`, just like with all other operators. That would also help with this [! for infix operators · Issue #25512 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/25512)

Unfortunately, it’s too late to fix now, and adding more superfluous syntax would just be confusing.

---

<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:** [April 26, 2021, 11:49am UTC](https://discourse.julialang.org/t/aliases-for-and/60004/14 "2021-04-26T11:49:25Z")

</div>

> [@ParadaCarleton](#):
>
> helps those coming from Python or Pascal, where `:=` is valid syntax

I don’t think it really helps those users. If they want to use Julia, they are better off just learning it as is. For one thing, running your private version of Julia with custom operators makes it much more difficult to ask for help.

---

<div class="post-metadata">

**Author:** ![aramirezreyes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aramirezreyes/32/42573_2.png) [@aramirezreyes](https://discourse.julialang.org/u/aramirezreyes)\
**Post date:** [April 26, 2021, 4:52pm UTC](https://discourse.julialang.org/t/aliases-for-and/60004/15 "2021-04-26T16:52:07Z")

</div>

In that regard, I think `:=` was only included in Python a few months ago? It is not like it is a long held standard, so It doesn’t look like it missing from Julia is a difficulty for people that just learned that operator. It doesn’t seem right to follow Python syntax everytime they add something.

---

<div class="post-metadata">

**Author:** ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)\
**Post date:** [April 26, 2021, 5:07pm UTC](https://discourse.julialang.org/t/aliases-for-and/60004/16 "2021-04-26T17:07:57Z")

</div>

Let’s not make Julia suffer for the poor decisions made during the development of Python and Pascal.

---

<div class="post-metadata">

**Author:** ![D\_A](https://avatars.discourse-cdn.com/v4/letter/d/8dc957/32.png) [@D\_A](https://discourse.julialang.org/u/D_A)\
**Post date:** [April 26, 2021, 6:49pm UTC](https://discourse.julialang.org/t/aliases-for-and/60004/17 "2021-04-26T18:49:29Z")

</div>

Same, and for people, like me, who use a lot of Unicode characters, make `←` (for example, same as `<-`) a natural alias for this `:=`. I also always feel strange when an equality test is longer than an inequality one in my code (`≠` versus `==`), making me often choose to test inequalities to avoid mistakes (confusion with `=`)…

---

<div class="post-metadata">

**Author:** ![jzr](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jzr](https://discourse.julialang.org/u/jzr)\
**Post date:** [April 26, 2021, 7:00pm UTC](https://discourse.julialang.org/t/aliases-for-and/60004/18 "2021-04-26T19:00:01Z")

</div>

> [@aramirezreyes](#):
>
> I think `:=` was only included in Python a few months ago?

It was very controversial during the proposal process and many Pythonistas still consider that change a mistake.

---

<div class="post-metadata">

**Author:** ![Jeff\_Emanuel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff_emanuel/32/15440_2.png) [@Jeff\_Emanuel](https://discourse.julialang.org/u/Jeff_Emanuel)\
**Post date:** [April 26, 2021, 7:49pm UTC](https://discourse.julialang.org/t/aliases-for-and/60004/19 "2021-04-26T19:49:55Z")

</div>

All this discussion of making Julia look like another language reminds me of the days when people would abuse the C preprocessor to make their C code look a bit more like Pascal. It did no one any good. You still couldn’t write Pascal and feed it to your C compiler, no one conversant with C could read your code, and it slowed learning proper C. Just bite the bullet and learn the language instead of doing a half-baked emulation for another language.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [April 26, 2021, 7:51pm UTC](https://discourse.julialang.org/t/aliases-for-and/60004/20 "2021-04-26T19:51:25Z")

</div>

`=` is pretty similar to `:=` already

```julia
julia> if (m = match(r"foo", "foobar")) !== nothing
          print(m)
       end
RegexMatch("foo")

```

[Next page](https://discourse.julialang.org/t/aliases-for-and/60004.md?page=2)
