Possible bug?

using Base
global primel = []
println(primel)
println(div(10,3))
if true
  println(primel)
  println(div(10,3))
  if true
    println(primel)
    println(div(10,3))
    if true
      println(primel)
      println(div(10,3)
      if true
        println(primel)
        #println(div(10,3))
        if true
          println(primel)
          #println(div(10,3))
          if true
            println(primel)
            ##println(div(10,3))
          end
        end
      end
    end
  end
end

I am using div with bigints but when the scoping gets deep it no longer recognizes the div function…is this bug or a feature :smiley:

In pluto it throws “UndefVarError: div not defined”

you never assign anything to primel except [].
println(div(10,3) needs another ')`
I really don’t know what you are trying to test.

BigInts need to be used like this

ten = big(10)
three = big(3)
div(ten, three)
# or
div(big(10), big(3))

try typeof(10), typeof(big(10))

Okay thanks but if you run the sample code it wont work…even with ints…if you comment out the fourth div then it will work…could be something with the Base library or with Julia itself…dont know I am new here…I could make my own function for division as a temporary solution

I can’t reproduce (in Julia 1.8.3), even if I uncomment everything:

julia> using Base

julia> global primel = []
Any[]

julia> println(primel)
Any
[]

julia> println(div(10,3))
3

julia> if true
         println(primel)
         println(div(10,3))
         if true
           println(primel)
           println(div(10,3))
           if true
             println(primel)
             println(div(10,3))
             if true
               println(primel)
               println(div(10,3))
               if true
                 println(primel)
                 println(div(10,3))
                 if true
                   println(primel)
                   println(div(10,3))
                 end
               end
             end
           end
         end
       end
Any[]
3
Any[]
3
Any[]
3
Any[]
3
Any[]
3
Any[]
3

(Note that your original post was missing a close parenthesis on one line.)

it is broken for me on both pluto and replit…but pluto I have real code not this example thing

What version of Julia are you using?

1.8.5…maybe that has something to do with it

replit is fast to use maybe you can understand the errors it is throwing…You can use it without signing up for an account

Nope, I just upgraded to 1.8.5 and it still works fine, in both the REPL and in Pluto.

Are you sure you are running exactly the same code as in my post? As I commented above, your original post was not runnable (it had a typo), so maybe you are running something different.

2 Likes

Yeah that solved it …thank you for finding my bug

The problem with my main program was I had a variable named div…so when I called the function div…the compliler had a breakdown. Now I am using the integer division operator and also changed the name of my variable…

That’s not “the compiler having a breakdown”, that’s the language telling you fairly specifically what’s wrong (you tried to call an integer):

julia> div = 123
123

julia> div(2, 3)
ERROR: MethodError: objects of type Int64 are not callable
Maybe you forgot to use an operator such as *, ^, %, / etc. ?

Actually I got variable undefined…which was confusing …sometimes it recognised it as a function and other times it thought it was a variable…mostly as the scoping got deeper…since I am porting My code I didnt know I had a variable “div”