mward-sudo
Inconsistency between Erlang and Elixir with :filename.rootname/2
I’m working on the Hologram project which aims to transpile Elixir code to Javascript.
To give context, I’m working on a Javascript implementation of the :filename.rootname/2 function. This should be implemented to strictly follow the Erlang implementation.
This function is then tested using javascript tests, along with corresponding consistency tests that look for the same results using ExUnit.
However, I am experiencing an inconsistency between Erlang and Elixir when using this function with an empty list as the first argument.
If I use erl, passing an empty list returns an empty list.:
1> filename:rootname([], “.erl”).
[]
If I do the same in Elixir, passing an empty list returns an empty Binary.
iex(1)> :filename.rootname([], “.ext”)
“”
This is mirrored in ExUnit. the following passes:
assert :filename.rootname([], ".erl") == ""
But asserting an empty list fails:
assert :filename.rootname([], ".erl") == [ ]
This means I either cannot maintain strict compatibility with Erlang, or I cannot keep my javascript and ExUnit tests consistent as JS would test for an empty list (a boxed type in Hologram) and an empty Binary in ExUnit.
Is there any way I can coerce Elixir to return the same empty list type that Erlang does, or am I going to have to accept the inconsistency between tests?
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #performance
- #security










First Post!
mward-sudo
In the end, I think the solution is to maintain compatibility with Elixir’s implementation. But I’m surprised at the difference when calling an Erlang function.
Most Liked
NobbZ
If you do equivalent calls, then the behavior is consistent, list in, list out, binary in, binary out.
Remember,
"foo"in erlang is~c"foo"in elixir!edit
You should crosscheck all combinations of inputs and respective behaviour, with empty, non-empty but matching, and non-empty but not matching to ensure full compatibility.
Especially as I don’t know how you treat the difference between binary and charlist on your JS site.
NobbZ
I do not see how
'…'vs~c"…"changes anything here, as the confusion was on the erlang side, rather than on the elixir side.