Vishesh I would use `serialize` and `deserialize` to ensure that you get exactly the same expression back that you wrote out initially. There are several caveats that would be very difficult to get correct in a string representation, e.g. if objects are aliased (if the same object appears multiple times in the expression).
-erik On Fri, Apr 1, 2016 at 7:36 PM, <vish...@stanford.edu> wrote: > basically, if I do: > >> e = Expr(:quote, :(:x)) # (quoting a symbol) >> show(e) > > :($(Expr(:quote, :(:x)))) > >> print(e) > > $(Expr(:quote, :(:x))) > >> string(e) > > "\$(Expr(:quote, :(:x)))" > >> parse(string(e)) > > :($(Expr(:$, :(Expr(:quote,$(Expr(:quote, :(:x)))))))) > > > that's not the same expression as represented by the string. Then when I go > to eval it (which should still work, semantically speaking) > > ERROR: unsupported or misplaced expression $ > > > Is there a way around this? I'd like to make an expression a string, print > it to a file, then slurp it up later and eval it. > > At the very least, there should be a consistent way to stringify and > reparse/eval expression objects, even if they look ugly like > :($(Expr(:quote, :(:x)))). I'd hate to have to reimplement the whole > printing of every expression ever in order to make this work (there doesn't > seem to be a way to extend a method, like print or show, to only work on > expressions with a particular head?) > > > > Vishesh -- Erik Schnetter <schnet...@gmail.com> http://www.perimeterinstitute.ca/personal/eschnetter/