On Thursday, July 24, 2014 5:58:33 PM UTC-5, [email protected] wrote: > > Regarding Steven Johnson's suggestion, I am unclear about a certain point. > Suppose, following Steven's suggestion, I define > > isless_eq(x,y) = !isless(x,y) && !isless(y,x) > > First question: this is equivalent to: > > isless_eq(x::Any,y::Any) = !isless(x,y) && !isless(y,x) > > correct? >
Yes. > Now suppose I have another function in which there is an invocation > isless_eq(a,b) where a and b are both Int, and the compiler knows that they > are both Int. > > Does the compiler generate a specialized version of isless_eq with the > comparison for Int hard-coded? Or does the above definition of isless_eq > generate a single function called isless_eq that decides at run-time using > some kind of dispatch table which version of isless should be invoked? > This is a testable hypothesis. Define: isless_eq(x,y) = !isless(x,y) && !isless(y,x) isless_eq_any(x::Any,y::Any) = !isless(x,y) && !isless(y,x) isless_eq_int(x::Int,y::Int) = !isless(x,y) && !isless(y,x) Then, see what happens when Julia has type-inferred the code: code_typed(isless_eq, (Int, Int)) code_typed(isless_eq_any, (Int, Int)) code_typed(isless_eq_int, (Int, Int)) I think you'll be pleasantly surprised by what pops out.
