nezzart
What’s the difference between variable binding and assignment? How does that work on a low level?
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
Hi all,
I’m working on a Phoenix project where I need to make external HTTP requests and I’m trying to choose between Req and HTTPoison....
New
How do I tell Hologram not to escape HTML when substituting into templates?
{Textile.render(@product.long_description)}
escapes the HTM...
New
I’d like to create a file with 600 permissions (rw-------), but there’s a race condition if I create it and then change the permissions. ...
New
Hi,
we run different LLM models across a cluster, with each node loading a configurable subset. Model-specific queues let nodes consume ...
New
When I use Mix.install with a git dependency, using git@github.com:... how do I change the SSH identity used?
I’ve got two Github accoun...
New
Hello all. I have a question as to best practices for code organization when implementing a liveview with a lot of responsibilities.
Sup...
New
Other Trending Topics
Hey there,
I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first.
...
New
Hi everyone :waving_hand:
I wanted to share something I’ve been building — NowBlind, a random chat app designed to help people discover ...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
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
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly)
AI dream has many faces, but general...
New
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
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
- #code-sync
- #discussion
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #elixirconf-us
- #blog-post
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #elixirconf-eu
- #processes
- #security
- #api
- #forms
- #performance










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
sysashi
As I understand it (read it with scepticism), in case of Elixir:
=is basically a pattern matching with binding(?)Hope I did not write some non sense
bbense
A couple clarifications:
There is no “assignment” in Elixir[1], when you use ‘=’ you are doing a pattern match and it either succeeds or fails. If it fails, the current process crashes.
The compiler/runtime has a set of rules that it uses to attempt to make the pattern match succeed. One of these is “binding” and “re-binding”. Binding creates a variable that references a term in memory, if that variable does not already exist in the current scope. In Erlang, all further uses of that variable in it’s current scope are fixed to that term in memory. Elixir cheats a bit and allows you to “re-bind”[2] a variable to a new term in memory in certain situations, however the actual term in memory from the original binding does not change and will need to be garbage collected at some point.
[1]- Except where there is… Process Dictionary comes to mind.
[2]- If I am understanding it correctly: Under the hood the Elixir compiler actually creates a new variable name and just remembers that x is really x1 from now on.
OvermindDL1
That is precisely correct, though the name is a bit different, but yep.
You can see the Erlang Core code by running erlang output manually through the internal compiler and out to erlang to dump out the Core if you are curious how it implements anything (I should probably document how sometime…).
AstonJ
Great question
I’ve also wondered the same thing.
So would it be safe to say the following?
From: https://cs.stackexchange.com/questions/39525/what-is-the-difference-between-assignment-valuation-and-name-binding
OvermindDL1
Seems pretty good.
I’d think the most ‘pure’ way of thinking of bindings are as unevaluated closures, so even doing just
a = 4means define a 0-arity functionain the current scope with the running environment that just returns a4and does nothing else, or thatb = a * 64is a 0-arity function like the above and uses theain the current scope, calls it, takes its value and returns it multiplied by64. In old functional design see:Is essentially just like a 0-arity function
athat returns an integer, a 1-arity functionbthat returns an integer, a 1-arity functiondthat returns a 1-arity function<anonymous>that returns an integer, and the top 0-aritytesterfunction that returns an integer. In Functional programming everything is a Function in concept.nezzart
Is there any problem in code like this?
smpallen99
The code you showed works. However, we usually try to reduce the number of single use variables. So, the “Elixir way” of writing that code is
Furthermore, if it was the last statement in a function, then we would drop the var1 like this:
peerreynders
The other issue with rebinding is that the name
var1may not only be bound to a new value but that the value could be an entirely different type.… which does not help code clarity.
Also another way of looking at the pipeline operator is that it “threads” the result of the previous function into the next function (which is why in Clojure it’s called the thread first macro). In a pipeline there is the expectation that the return type of the previous function is compatible the expected parameter type of the next function - there is no expectation of the values travelling through pipe being all of the same type.
nezzart
I’m not asking how to simplify that.
moreover, how’s that diffrent from?
nezzart
my question was about multithreading safety and related stuff.