What is the correct way to convert lossless Mathematica expressions into a string (the string is stored in memory, not exported to a file)?
I'm looking for a text view that
- It retains all the information, including the retention of special (and possibly nuclear) facilities, such as
SparseArray, Graph, Dispatch, CompiledFunctionetc. intact. For instance. looping a SparseArraythrough this view should keep it sparse (and not convert it to a regular list). - relatively fast cyclically (convert back and forth).
Is ToString[expr, FullForm]enough for this? What about ToString[expr, InputForm]?
Note 1: This happened while trying to get around some errors in Graphwhere the internal representation is sometimes damaged. But I'm interested in the answer to the general question above.
Note 2: it Savewill certainly do this, but it writes files (maybe this can be solved using streams), and it writes only definitions associated with characters.
source
share