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

Modifying Julia-internal format #1

Open
fbruetting opened this issue Dec 20, 2016 · 3 comments
Open

Modifying Julia-internal format #1

fbruetting opened this issue Dec 20, 2016 · 3 comments

Comments

@fbruetting
Copy link

fbruetting commented Dec 20, 2016

I sadly haven't found any Matlab-like „format“ command. Would you extend your code, so that it could be used in the REPL for every number as standard output format? Or does this need involvement of the Julia developers?

@ma-laforge
Copy link
Owner

Interesting question:

I think I would have to overwrite the default show()/print() method (still not exactly certain which one of the two) for Float64/Float32/....

I do not believe it is considered acceptable to overwrite methods in Julia as is the case for other languages. It only appears to be acceptable to extend a function with additional methods.

I will have to think about it more....

What you could do
I think this issue might indeed have to be brought up with the Julia devlopers: Code from NumericIO could indeed be used to add "more control" to Julia's core numeric output. It might also be acceptable to set a default precision/output format in the REPL, etc. I just have not seen much interest in this idea/module yet.

For the moment
You can at least define a shorthand to make it less painful to generate SI output:

SI(x) = formatted(x, :SI, ndigits=4)
SI(3.14159e-9) # => "3.142n"

To get rid of the quotes in the output (because the output is of type String): You would probably have to create a thin wrapper object that implements its own show() method.

@ma-laforge
Copy link
Owner

I just added a section:
https://github.com/ma-laforge/NumericIO.jl/blob/master/README.md#Sample_Applications

One thing you could do is add something similar to the following to your ~/.juliarc.jl file:

using NumericIO
Base.display(r::Base.REPL.REPLDisplay, v::Union{Float32,Float64}) = print(formatted(Base.REPL.outstream(r.repl), :SI, ndigits=4), v)

...But this only works to display floating-point results on the Julia console. This is not a complete solution.

@fbruetting
Copy link
Author

fbruetting commented Jan 2, 2017

Since this solutions are suboptimal, I'll file a feature request in Julia. :)

// JuliaLang/julia#19824

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

2 participants