On 5/7/14, 6:18 AM, "Marc Schütz" <[email protected]>" wrote:
On Wednesday, 7 May 2014 at 07:27:42 UTC, Mason McGill wrote:
On Tuesday, 6 May 2014 at 21:00:18 UTC, bearophile wrote:
The language tries its best to be flexible as a dynamic language. But
variables never carry a run-time type tag, unlike in Lisp.

Hmm... Then how can I do this:

  x = 5
  typeof(x) # evaluates to "Int64"
  x = 5.0
  typeof(x) # evaluates to "Float64"

?

Is Julia doing something trickier than I think it is? Or do you just
mean they don't carry type tags after compilation?

Maybe the first x stops existing, and a new one is created on reassignment?

A more interesting case is this (pseudo code, don't know Julia syntax):

     x = 5
     if (...) {
         x = "Hello"
     }
     typeof(x) # ???

Is that disallowed?

I just tried it. I also used the code_llvm function to see what llvm is generated. Some lines:

%8 = call %jl_value_t* @jl_box_int32(i32 %0), !dbg !4339

(an int is being boxed and you get a pointer to a jl_value_t)

%13 = call %jl_value_t* @jl_apply_generic(%jl_value_t* inttoptr (i64 4373507136 to %jl_value_t*), %jl_value_t** %6, i32 2), !dbg !4346

(a generic function call is being made)

So, there clearly must be runtime information associated to the variables, at least when they need boxing or this kind of multi-dispatch at runtime.


Reply via email to