Reputation: 596
Is there a way to convert an Elm expression to a string representation of its code?
e.g.
sourceString : a -> String
sourceString (1 + 3) == "(1 + 3)"
I haven't heard of macros in Elm, but perhaps there is still a way to do this?
Upvotes: 2
Views: 128
Reputation: 222060
No, you cannot do this in Elm. The function will only have access to the computed value, which will be 4
in this case. In all the languages I know where this is possible (Rust, Elixir, all the Lisp dialects), it's done using macros and Elm does not have that feature as of the current version, 0.18.
Upvotes: 8