# Unexpected behavior of #==#

**URL:** https://discourse.julialang.org/t/unexpected-behavior-of/2891
**Category:** General Usage
**Created:** [March 27, 2017, 12:04am UTC](https://discourse.julialang.org/t/unexpected-behavior-of/2891 "2017-03-27T00:04:18Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Till](https://avatars.discourse-cdn.com/v4/letter/t/22d042/32.png) [@Till](https://discourse.julialang.org/u/Till)
#### Post date: [March 27, 2017, 12:04am UTC](https://discourse.julialang.org/t/unexpected-behavior-of/2891/1 "2017-03-27T00:04:18Z")

</div>

Hi,  
I was playing around with multi line comments (in Julia v0.5.1) , and got some interesting results.  
So I tried:

julia\> my#=comment=#var = 0

- (generic function with 1 method)

And now I get:  
julia\> 3 \* 4  
0

So I just overloaded (\*) for (Any,Any). That’s weird.  
So, I wanted to retry in a way, that I can edit \*, so:

import Base.\*  
my#=comment=#var = 0

This creates a new method for (\*), so “hi” \* false returns now 0.

When I try this in Jupyter via Juliabox (Version 0.5), I get an error, if I don’t include Base.\* first, but than it also adds a new method to it.

So, does anybod know, why this happens?

Here’s my versioninfo():  
Julia Version 0.5.1  
Commit 6445c82\* (2017-03-05 13:25 UTC)  
Platform Info:  
OS: Linux (x86\_64-pc-linux-gnu)  
CPU: AMD Phenom™ II X6 1100T Processor  
WORD\_SIZE: 64  
BLAS: libblas  
LAPACK: liblapack  
LIBM: libm  
LLVM: libLLVM-3.9.1 (ORCJIT, amdfam10)

---

<div class="post-metadata">

### Author: ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)
#### Post date: [March 27, 2017, 12:53am UTC](https://discourse.julialang.org/t/unexpected-behavior-of/2891/2 "2017-03-27T00:53:46Z")

</div>

It’s parsed as juxtapose, i.e. multiplication.

---

<div class="post-metadata">

### Author: ![ScottPJones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scottpjones/32/146_2.png) [@ScottPJones](https://discourse.julialang.org/u/ScottPJones)
#### Post date: [March 27, 2017, 1:13am UTC](https://discourse.julialang.org/t/unexpected-behavior-of/2891/3 "2017-03-27T01:13:41Z")

</div>

That seems like it is probably unexpected behavior, which probably should be changed in the parser to not count as juxtaposition.

---

<div class="post-metadata">

### Author: ![Till](https://avatars.discourse-cdn.com/v4/letter/t/22d042/32.png) [@Till](https://discourse.julialang.org/u/Till)
#### Post date: [March 27, 2017, 1:21am UTC](https://discourse.julialang.org/t/unexpected-behavior-of/2891/4 "2017-03-27T01:21:09Z")

</div>

Thank you vary much for the answer, I didn’t think of that.

I also didn’t know you can overload operators that simply.

Also a thing that surprised me, though understandable:

If I open an new julia instance and run a+b=0, it just sets this as the only method for (+). But if use (+) once before in that instance, than I can’t redefine it like that, without including Base.+, and even than it would only add a new method, not “remove” the old ones.

---

<div class="post-metadata">

### Author: ![Stephen\_Vavasis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stephen_vavasis/32/3389_2.png) [@Stephen\_Vavasis](https://discourse.julialang.org/u/Stephen_Vavasis)
#### Post date: [March 27, 2017, 5:03am UTC](https://discourse.julialang.org/t/unexpected-behavior-of/2891/5 "2017-03-27T05:03:37Z")

</div>

In my opinion, this is a flaw in Julia. It is too easy to accidentally redefine a built-in operator. Indeed, I posted an issue last year on github to gripe about my experience when I made a small typo in a function – I put an = instead of a colon somewhere, or something similar (inside an array subscript!). The consequence was that “+” was redefined for the whole function, causing the function to fail with a mysterious error on a line that was distant from the line with the typo.

I would say that redefining a built-in operator should require that the programmer write a highly obvious chunk of code, or else a syntax error should result.

---

<div class="post-metadata">

### Author: ![Per](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/per/32/10387_2.png) [@Per](https://discourse.julialang.org/u/Per)
#### Post date: [March 27, 2017, 5:52am UTC](https://discourse.julialang.org/t/unexpected-behavior-of/2891/6 "2017-03-27T05:52:43Z")

</div>

On the other hand, if there’s ever an international obfuscated julia code contest, this will be a useful feature to have. 😉

```julia
julia> import Base.-

julia> my_var = 0;

julia> my-var = my_var + 1;

julia> 4 - 2
1

```

---

<div class="post-metadata">

### Author: ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)
#### Post date: [March 27, 2017, 8:19am UTC](https://discourse.julialang.org/t/unexpected-behavior-of/2891/7 "2017-03-27T08:19:41Z")

</div>

It occurred to me as well. The problem is that this happens even without importing the function:

```julia
julia> a-b=rand(15)
- (generic function with 1 method)

julia> rand(5) .- rand(5)
5-element Array{Array{Float64,1},1}:
 [0.83553, 0.846525, 0.447319, 0.829272, 0.14231, 0.671123, 0.532965, 0.704368, 0.280074, 0.180665, 0.833187, 0.589239, 0.335998, 0.216206, 0.992392]       
 [0.269979, 0.313953, 0.313245, 0.969569, 0.772667, 0.934492, 0.93995, 0.188244, 0.101232, 0.0525931, 0.12574, 0.692653, 0.471061, 0.366899, 0.462796]      
 [0.334985, 0.12022, 0.0730848, 0.65934, 0.588324, 0.160928, 0.274765, 0.267733, 0.730062, 0.253658, 0.837493, 0.00747138, 0.983055, 0.290284, 0.27298]     
 [0.000187563, 0.605232, 0.0321455, 0.212838, 0.103809, 0.557014, 0.625323, 0.266018, 0.363476, 0.591861, 0.544453, 0.17569, 0.769616, 0.00455865, 0.395421]
 [0.781084, 0.348457, 0.523047, 0.727615, 0.375016, 0.674879, 0.328631, 0.942764, 0.827079, 0.860394, 0.845891, 0.416686, 0.125326, 0.723758, 0.603509]

```

I expected to get a 5-element array of scalars, not an array of arrays, it took me a while to understand what was going on.

Actually, I can swear that when I defined the variable I didn’t even get in the REPL the message about (re-)definition of the method, but I couldn’t reproduce the issue afterwards (I should have taken a screenshot ☹ )

---

<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: [March 27, 2017, 8:29am UTC](https://discourse.julialang.org/t/unexpected-behavior-of/2891/8 "2017-03-27T08:29:44Z")

</div>

Ref [Infix operator definition syntax needs documentation · Issue #15483 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/15483), [https://github.com/JuliaLang/julia/issues/16383](https://github.com/JuliaLang/julia/issues/16383)

---

<div class="post-metadata">

### Author: ![Per](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/per/32/10387_2.png) [@Per](https://discourse.julialang.org/u/Per)
#### Post date: [March 27, 2017, 8:37am UTC](https://discourse.julialang.org/t/unexpected-behavior-of/2891/9 "2017-03-27T08:37:44Z")

</div>

This one’s also interesting: Let’s say I want `t` to be `true` if `a<=b` and `b==3`, but I make a typo.

```julia
julia> versioninfo()
Julia Version 0.6.0-pre.alpha.263
Commit 55f44179b9 (2017-03-27 00:01 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin13.4.0)
  CPU: Intel(R) Core(TM) i5-4690K CPU @ 3.50GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.9.1 (ORCJIT, haswell)

julia> t = (a <= b = 3)
3

julia> 1<=2

signal (11): Segmentation fault: 11
while loading no file, in expression starting on line 0
unknown function (ip: 0x31b7f2e83)
Allocations: 2846087 (Pool: 2844545; Big: 1542); GC: 3
Segmentation fault: 11

```

---

<div class="post-metadata">

### Author: ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)
#### Post date: [March 27, 2017, 10:04am UTC](https://discourse.julialang.org/t/unexpected-behavior-of/2891/10 "2017-03-27T10:04:32Z")

</div>

That shouldn’t crash and looks like a more fundamental problem with assigning function definitions. Reported as [https://github.com/JuliaLang/julia/issues/21172](https://github.com/JuliaLang/julia/issues/21172).
