-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Strange behavior after defining show() #3570
Comments
I don't remember when this changed, but the current method to overload for custom types is |
You don't need to edit repl_show() most of the time: just show(io::IO, o::Object). -- John On Jun 28, 2013, at 9:14 AM, Jacob Quinn [email protected] wrote:
|
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] https://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: