# Is it a bug in comprehension?

**URL:** https://discourse.julialang.org/t/is-it-a-bug-in-comprehension/10725
**Category:** General Usage
**Created:** [May 5, 2018, 11:48am UTC](https://discourse.julialang.org/t/is-it-a-bug-in-comprehension/10725 "2018-05-05T11:48:04Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![mobius-eng](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mobius-eng/32/99_2.png) [@mobius-eng](https://discourse.julialang.org/u/mobius-eng)
#### Post date: [May 5, 2018, 11:48am UTC](https://discourse.julialang.org/t/is-it-a-bug-in-comprehension/10725/1 "2018-05-05T11:48:04Z")

</div>

I got… hmmm… let’s call interesting behavior with the comprehension but only in function:

```julia
function foo(tmax, a, b, M, N)
    println("1: a=$a, b=$b, tmax = $tmax, M = $M, N = $N")
    tpts = [tmax/M*i for i in 0:N]
    println("2: a=$a, b=$b, tmax = $tmax, M = $M, N = $N")
    xpts = [a+(b-a)/N*j for j in 0:M]
    println("3: a=$a, b=$b, tmax = $tmax, M = $M, N = $N")
    return (tpts, xpts)
end

```

And then:

```julia
(t1, x1) = foo(1.0, -1.0, 2.0, 10, 10);

```

produces

```julia
1: a=-1.0, b=2.0, tmax = 1.0, M = 10, N = 10
2: a=-1.0, b=0.0, tmax = 1.0, M = 10, N = 10
3: a=-1.0, b=0.0, tmax = 1.0, M = 10, N = 10

```

Coefficient `b` got turned to zero after the first comprehension. (Julia 0.6.2 on Windows) Can anyone else confirm it?

---

<div class="post-metadata">

### Author: ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)
#### Post date: [May 5, 2018, 11:53am UTC](https://discourse.julialang.org/t/is-it-a-bug-in-comprehension/10725/2 "2018-05-05T11:53:33Z")

</div>

That is odd, and I can’t reproduce it on Linux (0.6.2 nor 0.7-dev). What do get as return for `x1`?  
I get

```julia
julia> x1'                                                                                                                                                               
1×11 LinearAlgebra.Adjoint{Float64,Array{Float64,1}}:                                                                                                                    
 -1.0 -0.7 -0.4 -0.1 0.2 0.5 0.8 1.1 1.4 1.7 2.0                                                                                                               

```

Maybe someone else with a windows install can check too.

---

<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: [May 5, 2018, 11:56am UTC](https://discourse.julialang.org/t/is-it-a-bug-in-comprehension/10725/3 "2018-05-05T11:56:48Z")

</div>

```julia
               _
   _ _ _(_)_ | A fresh approach to technical computing
  (_) | (_) (_) | Documentation: https://docs.julialang.org
   _ _ _| |_ __ _ | Type "?help" for help.
  | | | | | | |/ _` | |
  | | |_| | | | (_| | | Version 0.6.2 (2017-12-13 18:08 UTC)
 _/ |\ __'_|_|_|\__'_| | Official http://julialang.org/ release
|__/ | x86_64-w64-mingw32

julia> function foo(tmax, a, b, M, N)
           println("1: a=$a, b=$b, tmax = $tmax, M = $M, N = $N")
           tpts = [tmax/M*i for i in 0:N]
           println("2: a=$a, b=$b, tmax = $tmax, M = $M, N = $N")
           xpts = [a+(b-a)/N*j for j in 0:M]
           println("3: a=$a, b=$b, tmax = $tmax, M = $M, N = $N")
           return (tpts, xpts)
       end
foo (generic function with 1 method)

julia> (t1, x1) = foo(1.0, -1.0, 2.0, 10, 10);
1: a=-1.0, b=2.0, tmax = 1.0, M = 10, N = 10
2: a=-1.0, b=2.0, tmax = 1.0, M = 10, N = 10
3: a=-1.0, b=2.0, tmax = 1.0, M = 10, N = 10

```

---

<div class="post-metadata">

### Author: ![mobius-eng](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mobius-eng/32/99_2.png) [@mobius-eng](https://discourse.julialang.org/u/mobius-eng)
#### Post date: [May 5, 2018, 1:20pm UTC](https://discourse.julialang.org/t/is-it-a-bug-in-comprehension/10725/4 "2018-05-05T13:20:08Z")

</div>

Interesting… I have exact same version of Julia.

However, I remember that about a month or two ago I was playing with PackageComiler.jl and I may have replaced original Julia image. Is there a way to check this?

---

<div class="post-metadata">

### Author: ![mobius-eng](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mobius-eng/32/99_2.png) [@mobius-eng](https://discourse.julialang.org/u/mobius-eng)
#### Post date: [May 5, 2018, 1:22pm UTC](https://discourse.julialang.org/t/is-it-a-bug-in-comprehension/10725/5 "2018-05-05T13:22:11Z")

</div>

> [@mauro3](#):
>
> What do get as return for x1?

I get the range from -1.0 to 0.0. In fact, this is how I got onto this: I was generating the range like this only to see incorrect boundaries.

---

<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: [May 5, 2018, 1:54pm UTC](https://discourse.julialang.org/t/is-it-a-bug-in-comprehension/10725/6 "2018-05-05T13:54:39Z")

</div>

Well if you have recompiled other stuff into julia then all bets are off. I suggest you download a new fresh version.

---

<div class="post-metadata">

### Author: ![Seif\_Shebl](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@Seif\_Shebl](https://discourse.julialang.org/u/Seif_Shebl)
#### Post date: [May 5, 2018, 4:31pm UTC](https://discourse.julialang.org/t/is-it-a-bug-in-comprehension/10725/7 "2018-05-05T16:31:26Z")

</div>

```julia
Julia Version 0.6.0
Commit 903644385b* (2017-06-19 13:05 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i7-4790K CPU @ 4.00GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.9.1 (ORCJIT, haswell)
1: a=-1.0, b=2.0, tmax = 1.0, M = 10, N = 10
2: a=-1.0, b=2.0, tmax = 1.0, M = 10, N = 10
3: a=-1.0, b=2.0, tmax = 1.0, M = 10, N = 10

```

Also,

```julia
Julia Version 0.7.0-DEV.5012
Commit 4339f7416a* (2018-05-05 21:39 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i7-4790K CPU @ 4.00GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-3.9.1 (ORCJIT, haswell)
(t1, x1) = foo(1.0, -1.0, 2.0, 10, 10);
1: a=-1.0, b=2.0, tmax = 1.0, M = 10, N = 10
2: a=-1.0, b=0.0, tmax = 1.0, M = 10, N = 10
3: a=-1.0, b=0.0, tmax = 1.0, M = 10, N = 10

```

---

<div class="post-metadata">

### Author: ![mobius-eng](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mobius-eng/32/99_2.png) [@mobius-eng](https://discourse.julialang.org/u/mobius-eng)
#### Post date: [May 6, 2018, 11:28am UTC](https://discourse.julialang.org/t/is-it-a-bug-in-comprehension/10725/8 "2018-05-06T11:28:27Z")

</div>

Interesting that in 0.7 comprehension also destroys `b`.

---

<div class="post-metadata">

### Author: ![mobius-eng](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mobius-eng/32/99_2.png) [@mobius-eng](https://discourse.julialang.org/u/mobius-eng)
#### Post date: [May 6, 2018, 11:41am UTC](https://discourse.julialang.org/t/is-it-a-bug-in-comprehension/10725/9 "2018-05-06T11:41:35Z")

</div>

I can confirm the problem on

```julia
Julia Version 0.7.0-DEV.4690
Commit 78c7d87369* (2018-03-23 22:25 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i5-5200U CPU @ 2.20GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-3.9.1 (ORCJIT, broadwell)
Environment:

```

but not on JuliaBox with

```julia
Julia Version 0.6.2
Commit d386e40c17 (2017-12-13 18:08 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Xeon(R) CPU E5-2673 v3 @ 2.40GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.9.1 (ORCJIT, haswell)

```

> [@kristoffer.carlsson](#):
>
> Well if you have recompiled other stuff into julia then all bets are off. I suggest you download a new fresh version.

Re-installing clean Julia solved it on 0.6.2. It did look like I have replaced Julia’s image while playing with PackageCompiler.

**EDIT:** [Submitted an issue](https://github.com/JuliaLang/julia/issues/27004)

---

<div class="post-metadata">

### Author: ![tomaklutfu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomaklutfu/32/2411_2.png) [@tomaklutfu](https://discourse.julialang.org/u/tomaklutfu)
#### Post date: [May 6, 2018, 5:50pm UTC](https://discourse.julialang.org/t/is-it-a-bug-in-comprehension/10725/10 "2018-05-06T17:50:07Z")

</div>

Would it be Windows specific? All failures are in mingw environment.

---

<div class="post-metadata">

### Author: ![mobius-eng](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mobius-eng/32/99_2.png) [@mobius-eng](https://discourse.julialang.org/u/mobius-eng)
#### Post date: [May 6, 2018, 9:23pm UTC](https://discourse.julialang.org/t/is-it-a-bug-in-comprehension/10725/11 "2018-05-06T21:23:06Z")

</div>

> [@tomaklutfu](#):
>
> Would it be Windows specific? All failures are in mingw environment.

This seems to be the case. I don’t have other systems to test elsewhere.
