moacirbishopcamata
Binding operator - is it possible to add the ‘:=’ operator for binding assignments and keep the ‘=’ operator for pattern matching
Good morning to the Elixir team.
Please excuse me if I’m commenting in the wrong place; please indicate where I should discuss this.
I would like to know if it’s possible to add the ‘:=’ operator for binding assignments and keep the ‘=’ operator for pattern matching.
This would make teaching the features of Elixir/Erlang easier (as a language promoter).
Thank you very much for your attention.
Most Liked
sodapopcan
At first I also had a hard time accepting that there was no difference between pattern matching and assignment, especially when you’re told = is not “assign” but “match” and then get an example of foo = "bar" # "bar"
The guides have been improved a bit since I initially read them by immediately showing the “inverse” expression:
iex> x = 1
1
iex> 1 = x
1
1 = x is an brow-raiser for newbies but I think they must get some idea that it’s a special case to put a variable on the right hand side or something? I’m only guessing, but I find that showing them this last example really tends to drive it home that = really indeed not an assignment operator:
iex> 1 = 1
1
I always explain it as assignment being a side effect of matching. I know that’s sorta overloading a term, but it seems to help in the beginning, lol.
hauleth
But there is no such thing as “binding assignment operator” in Elixir. There is only pattern matching (with potential rebinding). So I do not really get how these operators would differ.
andyleclair
Pattern-matching IS binding assignments, there’s no difference. An example:
{:ok, something} = MyFunc.call(params)
response = MyFunc.call(params) # Returns same, now `response` is bound as {:ok, something}
If you are a “language promoter” with the goal of teaching Elixir, you should probably spend some more time writing it, so you’re comfortable with how the language works.
Popular in Proposals: Ideas
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex









