SymbolicML / DynamicQuantities.jl

Efficient and type-stable physical quantities in Julia
https://symbolicml.org/DynamicQuantities.jl/dev/
Apache License 2.0
120 stars 15 forks source link

Round tripping Quantities through String #122

Open jdm204 opened 3 months ago

jdm204 commented 3 months ago

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.

MilesCranmer commented 3 months ago

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 commented 3 months ago

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?

jdm204 commented 3 months ago

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