GithubHelp home page GithubHelp logo

Comments (6)

josevalim avatar josevalim commented on May 20, 2024

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. :(

from livebook.

nixxquality avatar nixxquality commented on May 20, 2024

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.
An example, in Erlang terms, would be:

Bindings = [{erlang, Name}, ...].

to_erlang_var({erlang, Name}) -> Name;
to_erlang_var({elixir, Name}) -> to_camel_case(Name).

from livebook.

jonatanklosko avatar jonatanklosko commented on May 20, 2024

Good catch. There is more to it, the current conversion maps JsON and JsOn to the same Elixir name, so if both names were to be defined it can actually break the semantics.

I think we really need an unambiguous mapping. My vote is to convert JSON to j_s_o_n, this is not pretty, but only matters if the user writes both Erlang and Elixir. Besides, one may argue the variable should be Json anyway :) @josevalim wdyt?

from livebook.

josevalim avatar josevalim commented on May 20, 2024

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.

from livebook.

jonatanklosko avatar jonatanklosko commented on May 20, 2024

Just change your Elixir var name.

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):

  1. Toggle the first char case
  2. _x <-> X

And this results in:

Erlang <-> Elixir

# Usual
Json <-> json
JSON <-> j_s_o_n
JsOn <-> js_on
JsON <-> js_o_n

# Mostly irrelevant edge cases
J_s_o_n <-> jSON
Js__on <-> js_On
Js__o_n <-> js_ON
JsO_N <-> js_oN
Js_on <-> jsOn

from livebook.

josevalim avatar josevalim commented on May 20, 2024

regardless of what I said, that’s by far the simplest option, so I agree. :)

from livebook.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.