So i was thinking about some of the conversations we had at JuliaCon about Julia’s ability to handle redefining
const variables, and i was wondering if we should just always prefer to use a single-method function instead of consts, since those play much nicer with Revise and changing them during development?
@oxinabox, @Syx_Pek, @Oscar_Smith, @oschulz and I were talking about julia redefinition and Revise and incrementality, and we reflected on how julia is able to handle redefined methods but not redefined consts. So I’m wondering, then, are there any features that a
const variable provides that a global function with only a single zero-arg method wouldn’t? Can you use a function with only a single zero-arg method as a replacement that supports live programming?
I know that if a function has more than one method, it can’t always be devirtualized (e.g. if its calling args are type unstable), but can a zero-argument method always be devirtualized and inlined? If its body is literally just a return statement of a literal, is it always available to the compiler just like a
const is? Or do we need something more to get that, like
@pure, in which case redefinition / live programming are similarly restricted?
If there are some other requirements to make this work (like the function must have no other methods, and the body must be only a return statement, etc), maybe we could just have a macro that asserts those things?
julia> @constf x() = 2 julia> f(a) = x() + 1 julia> @constf f() = 3 ERROR: Can't declare f() as a constant function; it has other methods.
Or something like that?