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.
Trending in Discussions
Other Trending Topics
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











Most Liked- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
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
Rebinding a variable does not mutate data. If I have:
yis still%{foo: 1}. The data itself is completely unchanged. We have shadowedx, 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:
If
=were performing a mutation,xwould be10, but in fact it’s still just1. All that happens is shadowing / rebinding, and that naturally doesn’t work across lexical scopes.bodhilogic
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
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.