DynamicQuantities.jl icon indicating copy to clipboard operation
DynamicQuantities.jl copied to clipboard

Round tripping Quantities through String

Open jdm204 opened this issue 11 months ago • 3 comments

Hi, thanks for the package, nice to have an alternative approach to the Unitful type-based one.

Is there a way in this package to convert back and fourth between Quantities and String representations so that quantities could be serialised to strings and parsed back again? Like in Unitful, string(q::Quantity) prints a space between the last numeral and the unit, which yields an error with uparse.

jdm204 avatar Mar 13 '24 17:03 jdm204

Just so I understand, would you want a way to parse the current pretty-printed output? Or would you want to have a printing function that gives something you can directly type into the REPL?

MilesCranmer avatar Mar 13 '24 19:03 MilesCranmer

Btw, is there a function in Base for prints that aim to give a string representation that can be typed back into the REPL? Like some show(::IO, ::Val{:raw}, x) or something?

MilesCranmer avatar Mar 13 '24 19:03 MilesCranmer

Just so I understand, would you want a way to parse the current pretty-printed output? Or would you want to have a printing function that gives something you can directly type into the REPL?

I suppose either would suit my needs, maybe parsing units with the space might make more sense as "2 mL"/1 nM" etc is a pretty common way to write these quantities for humans!

Btw, is there a function in Base for prints that aim to give a string representation that can be typed back into the REPL? Like some show(::IO, ::Val{:raw}, x) or something?

I was looking and didn't find it, though I did realise I don't understand Julia's display system as well as I should.

Also worth noting a similar issue with Unitful: https://github.com/PainterQubits/Unitful.jl/pull/470

jdm204 avatar Mar 14 '24 08:03 jdm204