Qqwy

Qqwy

TypeCheck Core Team

Why is Keyword restricted to atom keys?

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.

Most Liked

NobbZ

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

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 the Dict module and maps being introduced, and when APIs were refactored we lost the convenience of that ListDict structure. I too have missed it.

Where Next?

Popular in Questions Top

sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New

Other popular topics Top

pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New

We're in Beta

About us Mission Statement