7stud
What is the Elixir equivalent to Ruby’s Hash.new where you can specify a block that returns an empty list when you access a non-existent key (or Perl’s autovivification feature)?
The idea is that when you access a key in a Map that doesn’t exist you get back an empty list, which you can then append values to. And, if the key does exist, then you get back a non-empty list, which you can also append values to.
Also, why is it that the editor for this forum has a textbox that says “choose optional tags for this topic”, yet when I submit my question, I get an alert that says “You must choose at least 1 tag”, yet none of the tags are relevant to my question?
Trending in Questions
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
I’m working on a small exercise involving update_in/3, and I came up with this solution:
data = %{
name: "Periodic Table",
category:...
New
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication):
toke...
New
Other Trending Topics
In my third year of college, around 2010, I found Erlang. A few years later, I found Elixir. I liked the ideas at once: many small proces...
New
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
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
- #ai
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #metaprogramming
- #hex










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
OvermindDL1
In functional languages that kind of access is ‘inverted’, you specify the default arguments on the calls instead of the object, thus:
Which of course you can wrap up as new calls in your own custom module.

Or do something generic like make a
DefaultMapmodule that delegates to the normalMapmodule but sets an override default key in the map or something.Lots of options.
A relevant tag would just be ‘elixir’ or so, but adding tags is a good way to be able to search for topics in the future.
7stud
Thanks for the response.
There is no elixir tag shown in the drop down list. And, when I select a tag in error, and I want to remove the tag, I try to click on the the ‘x’ in the tag, but that doesn’t work (in Safari 11.1).
OvermindDL1
@AstonJ will need to look in to that, but do you get any error message in the javascript console or any error server responses in the network inspector?
7stud
Yeah, that doesn’t do what Ruby’s
Hash.newdoes when you specify a block (or Perl’s autovivification). The idea is that you can treat the value returned by a non-existent key the same way you do an existing key. What’s lacking is that Map.udpate/4 does not pass the default value to the function, which I think is a terrible oversight:Here’s what
Map.update/4does:I think
Map.update/4should create the keyc: [10]on line 6.Here is what you can do in Ruby:
See how convenient that is? Perl also allows you to do something similar.
OvermindDL1
I wish it did that as well, but you can always make your own function do it.
For note, I’ve barely touched Ruby, I find it a very difficult to reason about language due to everything being in flux and so very untyped, so I don’t know what the defaults do, so overall it is better to explain what you want it to do rather than just say ‘this other language thing’ where not everyone knows that other language. ^.^;
I agree, I’ve always found that to be really weird, but I’ve chalked up a lot of Elixir’s weirdness to Ruby, guess it is the opposite this time. ^.^
AstonJ
We generally don’t use ‘elixir’ as a tag since pretty much everything is related to Elixir on this forum
(and so I’ve made it a staff only tag)
I’ve added maps and lists as tags as they seem most relevant
peerreynders
Something else to ponder:
Kernel.update_in/3Access.key/27stud
Here are the javascript errors I get when I load the elixir forum page:
I don’t get any additional js errors when I try to “x out” a tag.
But the editor makes me choose at least one tag, and
elixiris not a choice. So, should I choose theEctotag when my question has nothing to do with Ecto?OvermindDL1
Ahh, okay that works!
I’m wondering if something more generic like ‘language implementation’ or ‘stdlib’ might be good?
AstonJ
The tags displayed change as you type and if the tag you want doesn’t exist, you can create it. So just tag a thread with what the thread is about
The language-implementation tag already exists and stdlib exists as standard-library