# Weird bug: Printing a variable vs. not printing a variable give different results

**URL:** <https://discourse.julialang.org/t/weird-bug-printing-a-variable-vs-not-printing-a-variable-give-different-results/12728>\
**Category:** Optimization (Mathematical)\
**Created:** [July 30, 2018, 12:15am UTC](https://discourse.julialang.org/t/weird-bug-printing-a-variable-vs-not-printing-a-variable-give-different-results/12728 "2018-07-30T00:15:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![CanLi1](https://avatars.discourse-cdn.com/v4/letter/c/6a8cbe/32.png) [@CanLi1](https://discourse.julialang.org/u/CanLi1)\
**Post date:** [July 30, 2018, 12:15am UTC](https://discourse.julialang.org/t/weird-bug-printing-a-variable-vs-not-printing-a-variable-give-different-results/12728/1 "2018-07-30T00:15:54Z")

</div>

Hi folks,

I’m using Julia/JuMP and I recently encountered a weird bug. The whole package I’m writing is too big so I only include the code that this bug occurs. I have the following lines of code

 ![image](https://global.discourse-cdn.com/julialang/original/3X/b/4/b42a418f1a294892af6842ccdc54f7ab64800c04.png)  
The code does not give me the results I expect.  
However, if I uncomment the “println” on line 483 and 488, the code runs all right.

I really have no idea why this occurs. It seems that if I do not print “m.ext[:varmap]”, Julia just treats “m.ext[:varmap]” as an empty dictionary and ignores all the elements in m.ext[:varmap].

This seems to be a Julia issue rather than JuMP issue. I wonder if anyone has encountered the same problem before.  
Thanks in advance.

Best regards,  
Can

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [July 30, 2018, 1:35am UTC](https://discourse.julialang.org/t/weird-bug-printing-a-variable-vs-not-printing-a-variable-give-different-results/12728/2 "2018-07-30T01:35:50Z")

</div>

Unfortunately it is really hard to say anything without code that demonstrates the problem.

Try commenting out code until you have the smallest reproducible error.

I’m guessing that `:varmap` is an extension you are writing? What is the type of the value in `:varmap`? A dictionary?

What happens if you print `keys(m.ext[:varmap])` instead?

---

<div class="post-metadata">

**Author:** ![CanLi1](https://avatars.discourse-cdn.com/v4/letter/c/6a8cbe/32.png) [@CanLi1](https://discourse.julialang.org/u/CanLi1)\
**Post date:** [July 30, 2018, 2:25am UTC](https://discourse.julialang.org/t/weird-bug-printing-a-variable-vs-not-printing-a-variable-give-different-results/12728/3 "2018-07-30T02:25:29Z")

</div>

Hi Oscar,

Thanks for your answer. I will try to reproduce it with a small example.

Yes, :varmap is an extension for a JuMP model and it’s a Dict(). The keys of :varmap is JuMP variables. The values in :varmap are IntArray.

If I print keys(m.ext[:varmap]), it still works.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [July 30, 2018, 4:33am UTC](https://discourse.julialang.org/t/weird-bug-printing-a-variable-vs-not-printing-a-variable-give-different-results/12728/4 "2018-07-30T04:33:15Z")

</div>

> [@CanLi1](#):
>
> The code does not give me the results I expect.

What do you mean?

---

<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:** [July 30, 2018, 7:21am UTC](https://discourse.julialang.org/t/weird-bug-printing-a-variable-vs-not-printing-a-variable-give-different-results/12728/5 "2018-07-30T07:21:25Z")

</div>

In addition to posting a “minimal working example”, remember to post the _actual_ code instead of an _image_ of the code, since one cannot cut and paste from an image. Rember to put the code inside backticks (see here: [PSA: how to quote code with backticks](https://discourse.julialang.org/t/psa-how-to-quote-code-with-backticks/7530))
