You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was watching the video [Rationale Behind Julia and the Vision] http://www.youtube.com/watch?v=02U9AJMEWx0) trying to do the same in REPL at the same time. I noticed a strange behavior. Can someone please explain this?
after julia> importall Base julia> type ModInt{n} <: Integer
k::Int
ModInt(k) = new(mod(k,n))
end
when i entered julia> a = ModInt{11}(2011)
when I entered julia> show{n}(io::IO, k::ModInt{n}) = print(io, "$(k.k) mod $n")
all the definitions of show got listed.
now,when i entered julia> a
ModInt{11}(9)
but when I enter julia> print(a)
9 mod 11
but when I entered julia> (a,a)
(9 mod 11,9 mod 11)
strangely
*julia> * c = ModInt{13}(45)
6 mod 13
but
julia> ModInt{11}(45)
ModInt{11}(1)
julia> ModInt{12}(45)
9 mod 12
Version: (julia-0.2pre-dbac83fb44-WINNT-i686.zip)
Version 0.2.0 dbac83f-WINNT-i686 (2013-06-12 15:23:39)
i686-w64-mingw32
The text was updated successfully, but these errors were encountered:
I don't remember when this changed, but the current method to overload for custom types is repl_show. We should make sure the documentation is accurate on this.
I don't remember when this changed, but the current method to overload for custom types is repl_show. We should make sure the documentation is accurate on this.
—
Reply to this email directly or view it on GitHub.
This is just an artifact of having already generated code for ModInt{11} before defining a specialized show. Since ModInt{12} is a different type, it gets its own code. Dup of #265.
I was watching the video [Rationale Behind Julia and the Vision] http://www.youtube.com/watch?v=02U9AJMEWx0) trying to do the same in REPL at the same time. I noticed a strange behavior. Can someone please explain this?
after
julia> importall Base
julia> type ModInt{n} <: Integer
k::Int
ModInt(k) = new(mod(k,n))
end
when i entered
julia> a = ModInt{11}(2011)
when I entered
julia> show{n}(io::IO, k::ModInt{n}) = print(io, "$(k.k) mod $n")
all the definitions of show got listed.
now,when i entered
julia> a
ModInt{11}(9)
but when I enter
julia> print(a)
9 mod 11
but when I entered
julia> (a,a)
(9 mod 11,9 mod 11)
strangely
*julia> * c = ModInt{13}(45)
6 mod 13
but
julia> ModInt{11}(45)
ModInt{11}(1)
julia> ModInt{12}(45)
9 mod 12
Version: (julia-0.2pre-dbac83fb44-WINNT-i686.zip)
Version 0.2.0
dbac83f-WINNT-i686 (2013-06-12 15:23:39)
i686-w64-mingw32
The text was updated successfully, but these errors were encountered: