moacirbishopcamata

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

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

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

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.

Where Next?

Popular in Proposals: Ideas Top

benkimpel
Background I work at a hedge fund and our traders need highly dynamic UIs (think splitters, tabbed panels, tree lists, enormous data grid...
New
markevans
Hi! I’m excited about everything that’s going on re. gradual typing and am really pleased to see that Jose and the team seem to be think...
New
markevans
Hi! I feel like Phoenix is slightly missing a trick when it comes to front-end Javascript libraries like React, Svelte, etc. I feel tha...
New
woylie
We are seeing a lot of warning logs like this: navigate event to "https://someurl" failed because you are redirecting across live_sessio...
New
iaguirre88
Hi, everyone! Sometimes, you might want to build your app using Phoenix just for the backend and use another tool for the frontend (such...
New
nocksock
LiveView has spoiled me and now I would LOVE to be able to write controllers like this: defmodule DeadViewWeb.ItemController do use De...
New
derekkraan
I have been using a multi-endpoint setup in my app, just because I think it makes the most sense for a multi-subdomain app. This worked w...
New
pierrelegall
Problem Currently, List.first/2 and List.last/2 return a default value (or nil) when the list is empty. However, there are cases where an...
New
kccarter
This is likely a feature request unless we’re overlooking something, but it would be a nice improvement to the developer experience if th...
New
davydog187
I’ve been enjoying the new Streams API, but I keep needing to work around the lack of access to the underlying items. One issue that cons...
New

Other popular topics Top

axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 48475 226
New
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New

We're in Beta

About us Mission Statement