-
Notifications
You must be signed in to change notification settings - Fork 398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Information loss with current variable name binding model (JSON -> Json) #2551
Comments
Thank you for the report. Maybe we will need to keep a mapping in the evaluator to know how to handle those. I also can't think of alternatives. :( |
Perhaps instead of keeping a list of bindings by name only, you could keep them with their original name and a tag suggesting an origin, which can be converted when necessary. Bindings = [{erlang, Name}, ...].
to_erlang_var({erlang, Name}) -> Name;
to_erlang_var({elixir, Name}) -> to_camel_case(Name). |
Good catch. There is more to it, the current conversion maps I think we really need an unambiguous mapping. My vote is to convert |
I think we don’t need to worry about multiple Elixir vars converting to the same Erlang one, that’s fine. Just change your Elixir var name. But Erlang vars should go back and forth without issues. |
Ideally we should not have conflicts in the conversion, I think that's confusing. My point is that with an unambiguous mapping we achieve both and it seems like the simplest approach. There are a couple more cases, because technically Erlang env vars can also have underscores. But I think the following would be unambiguous (same procedure both ways):
And this results in:
|
regardless of what I said, that’s by far the simplest option, so I agree. :) |
Environment
git rev-parse HEAD
if running with mix): cb11b26Current behavior
Some background: I wanted to write an all-Erlang livebook, to check this project out, and to experiment with live documentation for a project of mine.
That project is a JSON parser, and so I used the variable name "JSON" for a binary with data that any reader could quickly edit.
However, I ran into an issue where the "JSON" term would disappear after one cell. I figured this had to do with the variable name normalization between Elixir and Erlang, and I've now checked the code to confirm those suspicions.
First: A simple test case.
I hoped this would be an easy fix, but I took a look at the code, and it seems like variable names are always remembered in the Elixir form even if you only have Erlang blocks in a document.
Of course, when you convert "JSON" to "json", you have no idea what the capitalization is supposed to be when you turn it back. "JSON" or "Json"? In this case, Livebook chooses "Json".
So it's not an easy fix, it's a bit of a head scratcher and to me, being new to your codebase, this is out of my league.
I would like to hear your thoughts on the matter.
The text was updated successfully, but these errors were encountered: