Qqwy
I am working on an implementation of a forth-like language on top of Elixir.
One of the things that is a major part of any forth-like language, is the dictionary of defined functions (called words). This is usually implemented as a linked list, so that multiple vocabularies (i.e. execution contexts) might coexist without conflicting definitions (they are re-using the same tail of the list, but each context might have its own head).
I wanted to build this in Elixir using a list. But now I found out that functions like Keyword.get, Keyword.put, etc. only work if the key is an atom. Why is this restriction on atom keys there?
The foo: 1, bar: 2 syntactic sugar of course desugars to a ‘keyword list’, but even without using this syntactic sugar it would be useful to use Keyword.get, Keyword.get_values etc. with different types of keys.
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #hex











Showing Posts 4 to 1- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
benwilson512
Pretty sure the Elixir List module also has those functions.
OvermindDL1
It is just an Elixir convention, Erlang often broke that style.
Precisely this.
NobbZ
You should be able to use
:lists.key*/*(erlang documentation) for what you want. Also it should be very simple to write up functions as needed for yourself.I do think, that the overall fact has to do something with the expenses of comparing anything else than atoms for equality, but this is in fact only a guess.
gregvaughn
There used to be a data structure called a ListDict, which fundamentally was something like
[{"foo", 1}, {"bar", 2}]that could use binaries for the keys, but didn’t require them to be IIRC. It was a confusing time between theDictmodule and maps being introduced, and when APIs were refactored we lost the convenience of that ListDict structure. I too have missed it.