JsonKody
This is highly subjective but in my mind Haskell and Ruby/Rust has one of the most beautiful lambda syntax
\a b → a + b
and
|a, b| a + b
so if Elixir syntax is mostly form Ruby why they ditched one of the most beautiful things on Ruby and goes with this abomination monster:
&(&1 + &2)
??
![]()
PS: Please note, my intent is not to criticize; I’m genuinely interested in understanding the design choices behind this syntax. ![]()
edit/note: |a, b| a + b is just Rust syntax, I thought that it’s also Ruby, but while Ruby is similar it wraps it in labda { ... }
Trending in Questions
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
I’m working on a small exercise involving update_in/3, and I came up with this solution:
data = %{
name: "Periodic Table",
category:...
New
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication):
toke...
New
Other Trending Topics
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
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
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
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










Showing Posts 20 to 11- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
carterbryden
I find the &1, &2 syntax hard to read too, though I can also see why some people like it.
The fn args → … end syntax I find a bit odd too just because it’s the only place I know of that isn’t a do/end block.
sodapopcan
That actually doesn’t look bad to me as you have it but I have never written something like that myself before where I extract the reducer with extra arg(s). In any event, I was mostly being silly—I grepped a recent codebase right after I posted to make sure I wasn’t lying about not ever using
—it’s more of an arbitrary line I draw for myself as
&2&can definitely look janky to me in many cases. I imagine it’s one of those things that’s easier for teams to either say yes or no to.dimitarvp
You are right, there are degrees. Your examples I too don’t find bad.
But you are also right that
elem/2is jarring.krasenyp
I have used
Enum.reduce(enumerable, initial, &reducer(extraarg, &1, &2)numerous times when I don’t want to use a lambda for whatever reasons. Maybe I’ve gotten used to it and I don’t find it hard to read.sodapopcan
Not to bikeshed (except that I’m gonna) but I do agree the
It’s a bit of a tough example for me to judge because I find 
&elem(&1, 2)is a little jarring even though I do use it sometimeselem/2jarringI do this kind of thing with abandon:
I see
usersso&1must be auserbecause even though naming is hard, it’s not that hardAlso, the odd time I need an identity function (almost always as a parameter default) I like
& &1as a nice little concise option, as in:fn x -> x endjust looks like someone made a mistake to me. Of course, the best option is likely&Function.indentity/1. You’re still using a capture there, but it’s the nice capture syntax and clear as day.I do also do stuff like this:
I can’t explain it but that looks totally fine to me, again, so long as there is clear naming. It also certainly makes a difference if it’s used in a common pattern or not.
I work solo, though. I wouldn’t fight anyone too hard on any of this stuff in a team situation.
One thing I never use (anymore) is
&2.&2can heck off!dimitarvp
Yeah, it ruins readability.
D4no0
This one baffles me too, I’m not sure what the thought process behind it was. This syntax is barely readable in isolation, not to talk in situations where there are multiple chained calls like this one.
dimitarvp
Exactly the same and it’s also one of my top 5 reasons to leave it behind. That, plus it being so hopelessly dynamic to the point that even Elixir looks strict like Rust when compared to it.
Ruby remains a very friendly to look at language (and to write in, until you have to do something serious at least; cue 1000 angry comments saying “BUT SO MUCH SERIOUS STUFF IS DONE IN RUBY, YOU ARE WRONG!”
) but its runtime properties are a complete “nah I am good” factor for me.
To the OP @JsonKody, I too find Rust’s syntax one of the best, and it leaves room for adding types too. OCaml is nice too.
And btw I kind of agree with him, I don’t think that the capture syntax with &1 and &2 etc. adds something tangible to the language.
Though there are two kinds of capture syntaxes. This one I like a lot:
…and this one I avoid like the plague most of the time:
To me it just looks confusing and even after 7.5y with Elixir I still find it an eye-sore that prevents me to scan code well and comprehend it quickly. No idea why but I never got used to it.
Finally, this SO thread is good: https://stackoverflow.com/questions/44266193/why-do-we-need-a-function-capture-operator-in-elixir
sodapopcan
By default Rubocop (at least the last time I used it) makes you write it like this:
->(a, b) { a + b }and the arrow must touch the parens! But if it spans multiple lines, it wants you do write it aslambda do ... end.sodapopcan
…and if you want to capture a block then it’s
proc { ... }, orProc.new { ... }!I do still have a softspot for Ruby, but I wish it would have stopped adding syntax a long time ago. I happened to switch fully over to Elixir just as field punning was introduced to Ruby. Just in the nick of time!