bodhilogic

bodhilogic

Elixir is touted as being a ‘Functional Language’ and the common characteristic of a functional language is that its ‘variables’ are immutable.

Other functional languages allow some tolerance for mutability, as long as some explicit ceremony is employed so that the developer knows he/she is ‘breaking the rules’.

it seems to me that the Pin operator should really be an ‘UnPin’ operator so that allowing a left side to be re-matched to a right side becomes an explicit operation i.e. the left side is immutable unless I use the ‘UnPin’ symbol - “I know that by writing ‘^a’ I am explicitly allowing a state change”.

Does this make sense or do I misunderstand something?

I’m not putting Elixir down - just trying to understand it.

Yes, I have read José’s github posting about why he allows re-matching. I am just thinking that allowing re-matching shouldn’t be the default behavior and that it doesn’t cost much time or effort to type one extra character to allow the re-match.

Most Liked

michalmuskala

michalmuskala

How would that work in expressions where you bind some variables and match on others? Which operator would you use and why?

Also, what about pattern matching in case or function heads, where you don’t have the operator at all, yet still have the matching/binding behaviour.

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Rebinding a variable does not mutate data. If I have:

x = %{foo: 1}
y = x
x = Map.put(x, :bar, 2)

y is still %{foo: 1}. The data itself is completely unchanged. We have shadowed x, but that isn’t the same thing as mutability. Data and bindings to data aren’t the same thing. It can be a difficult thing to see at first for some, but the “tolerance for mutability” you speak of from other functional languages doesn’t even apply here, since mutable data is not a feature available in the VM.

This is perhaps easier to see in a loop:

x = 1
for i <- 1..10 do
  x = i
end

If = were performing a mutation, x would be 10, but in fact it’s still just 1. All that happens is shadowing / rebinding, and that naturally doesn’t work across lexical scopes.

bodhilogic

bodhilogic OP

Fantastic responses!

Thank you all so much.

I suppose I just need to “retrain the brain” from a world of imperative programming to that of functional programming.

I had to go through a similar shift many, many years ago coming from iterative programming to the world of Prolog - you just have to learn to think differently ;).

I suppose a year from now, I’ll look back and laugh at myself for not appreciating the syntactic sugar that José took the time to build into Elixir.

Having said all that, I am really looking forward to exploring Elixir and becoming fluent in a ‘new’ way to program!

Last Post!

OvermindDL1

OvermindDL1

Depends on the expression.

Personally I’d just not have implicit rebinding at all, rather just force rebinding to use := to be explicit but otherwise all matches in all cases otherwise would follow erlangs semantics, no pin operator needed (although I guess you could allow {:ok, :=rebind} = ... to allow in-match rebinding, which would still do the whole invert thing, or maybe :: or something, or ^ since it’s not used anymore with this style).

But yeah, the erlang method feels far more natrual to me, but since I came from erlang that could easily just be bias. ^.^;

I think that piping fixes most of the ‘naming’ issues, otherwise use better names and don’t append numbers.

Where Next? Top

Trending in Discussions Top

cblavier
Hey there, It’s been more than a year since we started using LiveView as our main UI library and building a whole library of UI componen...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
axelson
Hi there! :wave: @frigidcode and I (but mostly him) have been running an Elixir Book club, we’re almost done with Designing Elixir Syste...
New
achempion
I’ve been using Emacs as my main code editor for more than a two years. It’s a custom build version although I’ve tried doom emacs and sp...
New
budgie
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with. But I don’t use it anymore. Serverless was the promis...
New
jtormey
Lately I’ve been thinking about how to organize components as a LiveView application grows. One of the pain points I’ve found (for myself...
New

Other Trending Topics Top

GenericJam
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
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
georgeguimaraes
Just published claude-code-elixir, a plugin marketplace for Claude Code with Elixir support. These are the plugins I’ve been using for my...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews