other-languages

grav 2022-10-20T19:59:35.423629Z

What the devil is up with Elixir's tuples? They seem to be a bit like vectors in Clojure, but then again there's this magic syntax around 2-ples, like

iex> [name: "Dave", city: "Dallas", likes: "Programming"]
[{:name, "Dave"}, {:city, "Dallas"}, {:likes, "Programming"}]
(from Programming Elixir) Why not just a map? Is ordering somehow more important in idiomatic Elixir?

grav 2022-10-20T20:16:50.258459Z

Later in Programming Elixir, it states: > In general, use keyword lists for things such as command line parameters and passing around options, and use maps when you want an associative array. Those use-cases seem very specific to warrent special syntax, and I'd argue that maps would be at least as suitable for passing around options. So I'm wondering if something's missing on the list?

russmatney 2022-10-20T20:44:07.709439Z

my memory of elixir (it's been a few years) is that maps vs keyword lists have a lot of overlap, as you're sensing - for me it comes down to the ergonomics of the api/implementation you're writing. for example, sometimes it makes sense to pop/destructure some kwarg off the list and pass the rest of the list to downstream functions. tho you could achieve that with a map as well, it might not be as minimal to implement. one detail is that i think keyword lists can have duplicate keys - i.e. multiple entries for "paths" if you're handling some --path "/a" --path "/b" input args

👍 1
2022-10-24T03:47:13.923439Z

I think it's an Erlangism, since Erlang has property lists, some old Lisps also have those, like Emacs and I think Common Lisp have property lists as well.

Cora (she/her) 2022-10-23T03:27:56.432909Z

keyword lists are super cool, though

Cora (she/her) 2022-10-23T03:28:15.932789Z

and yes, maps are quite recent

Cora (she/her) 2022-10-23T03:29:10.945729Z

parsing query strings is another place that keyword lists shine

Cora (she/her) 2022-10-23T03:29:34.544959Z

iirc

Cora (she/her) 2022-10-23T03:29:50.398539Z

as in, a value can appear more than once in a query string and keyword lists preserve that

mauricio.szabo 2022-10-21T19:38:05.047609Z

I also remember that Erlang didn't have maps before, so this "Keyword List" is the historical way of doing things where maps are the more recent version that almost nobody uses, or something 🤔

💡 1
grav 2022-11-05T09:16:03.926269Z

@corasaurus-hex So eg ?foo=42&foo=43 right? I guess it makes sense, but I think I'd still prefer to work with something like {:foo [42 43]} ...

grav 2022-11-05T09:21:10.427899Z

In the https://podcast.thinkingelixir.com/ podcast, in one of the "10 years of Elixir", the author of Elixir, José Valim, also mentions that Beam (the Erlang VM) originally didn't have hashmaps, so Elixir didn't either. That also seems to indicate that the use of property lists is a legacy thing. I don't remember the specific episode, but in general I think those five "10 years" episodes give a nice intro to Elixir. Can recommend!

Cora (she/her) 2022-11-05T09:33:27.926059Z

yes, beam didn't have maps to begin with (I used it both before and after that)