Skip to content
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

Closed
dinurp opened this issue Jun 28, 2013 · 3 comments
Closed

Strange behavior after defining show() #3570

dinurp opened this issue Jun 28, 2013 · 3 comments

Comments

@dinurp
Copy link

dinurp commented Jun 28, 2013

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

@quinnj
Copy link
Member

quinnj commented Jun 28, 2013

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.

@johnmyleswhite
Copy link
Member

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 notifications@github.com wrote:

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.

@StefanKarpinski
Copy link
Sponsor Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants