3 ms·
There are so many purity escape hatches in elixir!!
by throwawaymaths 1y ago
There are so many purity escape hatches in elixir!!
- hinkley 1y agoThe only ones I know about are the ones in functions and closures, where SSA basically just creates a new variable that hides the original (until the end of the block at which point you discover the reassignment didn't stick). What did you have in mind?
- throwawaymaths 1y agoets tables are the goto for data structures (for example the :digraph module that ships with elixir is built on an ets table, presumably because A* needs a mutable datatype) Process dictionary is also an option. Can always use a genserver as a data store (but only do that if lifetime shenanigans make it make sense) Postgres is also an option. Sqlite if you don't want to stand up a service.
- hinkley 1y agoAh yes. I’m using a genserver to persist a countdown clock across page loads. ETS gives me a memory leak vibe but I need to bite the bullet and learn to use it properly.
- throwawaymaths 1y agoThink of ets as an arena. You can clear the whole table by yanking its owning process. This could even be made automatic by linking it to whatever process needs the ets table.
- hinkley 1y agoHmmm. Maybe I’m misremembering some Erlang release notes then.