defdelegate keys(map), to: :maps
defdelegate values(map), to: :maps
defdelegate to_list(map), to: :maps
Assuming they are done in erlang (did not check) could I just copy them over?
Since the compiler seems to understand %{} this should be possible to be used:
def new, do: %{}
And if I’d like to implement new_from_enum, I would have to check if Enum.to_list is there and then this should also work?
def new(enum), do: new_from_enum(enum)
defp new_from_enum(enumerable) do
enumerable
|> Enum.to_list()
|> :maps.from_list()
end
So how do I know what I can do and can’t do.
Is it enough to check if the Elixir/Erlang implementation is there and then I can just copy from the Elixir repo?
“Nearly all” might be a bit optimistic. AtomVM definitely implements a highly functional sub-set of erlang/OTP. At this moment we support building with OTP 21-23, but support for 24 and 25 is currently in progress.
I am still quite new to erlang and have even less experience with elixir, so I am no expert. But I have been learning elixir by working on expanding its support in AtomVM recently. With esp32 as the primary target device (I believe Raspberry Pi Pico support is also in progress) we are in a constrained environment so the approach to elixir support has been to rely as much as possible on what has already been implemented in erlang. For an example you could look at the recently added AVMPort module that was created to give an elixir native interface to our erlang port driver that is used for drivers that use the port method rather than nifs. Wherever possible we try to use nifs over ports, due to memory and resource constraints. Ports are mostly used for drivers that need to make use of interrupts, for an example to can look at the recently updated GPIO driver and how it is implemented in C.
Some elixir libraries can be copied over from the Elixir stdlib, as in the recently added Bitwise.ex, but in general the libraries will need a little extra work to be done. Due to the space and limitations of embedded devices some libraries will need to be picked through and paired down to their most essential features.
Currently the Elixir support in AtomVM is very thin, but we would like to remedy that situation. Any contributions are highly appreciated. A great place to start contribution would be to open an issue about any currently unsupported feature you would like to see added. As you can see we are currently missing some very important modules (IO, Strings, GenServer, etc…). Work on any of these modules is a fantastic way to start contributing. The README for the AtomVM repo has information about style guide and other info about contributing.
If you would like to chat in real time with the developers and community please feel free to join our Telegram Chat.
I forgot to mention that there is a lot more documentation available at https://atomvm.net - including API references, a Programmers Guide, and other helpful material for new users and contributors.