This has always bugged me as well, but I just assumed there was a good reason for it.
From: Allen Madsen <allen.c.mad...@gmail.com> <allen.c.mad...@gmail.com> Reply: elixir-lang-core@googlegroups.com <elixir-lang-core@googlegroups.com> <elixir-lang-core@googlegroups.com> Date: March 30, 2020 at 11:01:39 AM To: elixir-lang-core@googlegroups.com <elixir-lang-core@googlegroups.com> <elixir-lang-core@googlegroups.com> Subject: Re: [elixir-core:9441] Proposal: & should be able to create zero-arity functions I'm +1 for this. I didn't see any justification for it in the commit that introduced it. https://github.com/elixir-lang/elixir/commit/46fae17b7ec9d752b918aa0fbcab3cf4d6e04359#diff-35be93cb9497f709353d9ed9b488949cR89-R90 Allen Madsen http://www.allenmadsen.com On Sun, Mar 29, 2020 at 7:56 PM Felipe Stival <v0id...@gmail.com> wrote: > Zero-arity functions are useful. > > Some example use cases: > Repo.transaction(fn -> create_user(a, b) end) > :timer.tc(fn -> my_function(a, b, c) end) > spawn(fn -> my_function(a) end) > > But this fn -> ... end syntax is verbose. All we are doing is creating a > zero arity closure, it could be as simple as: > > Repo.transaction(&create_user(a, b)) > > But this throws an error: > ** (CompileError) iex:2: invalid args for &, expected an expression in > the format of &Mod.fun/arity, &local/arity or a capture containing at > least one argument as &1, got: create_user(a, b) > > Is there a reason for this behavior? A better approach? > Otherwise, maybe this case would be a good fit for the & operator. > > -- > You received this message because you are subscribed to the Google Groups > "elixir-lang-core" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to elixir-lang-core+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/elixir-lang-core/53d77a49-564e-44c8-8836-cd533f3b62f7%40googlegroups.com > <https://groups.google.com/d/msgid/elixir-lang-core/53d77a49-564e-44c8-8836-cd533f3b62f7%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "elixir-lang-core" group. To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAK-y3Cvhxh596ZAHRVsbKQHaUWka0EDX9S-toCgda0rwSgbQTQ%40mail.gmail.com <https://groups.google.com/d/msgid/elixir-lang-core/CAK-y3Cvhxh596ZAHRVsbKQHaUWka0EDX9S-toCgda0rwSgbQTQ%40mail.gmail.com?utm_medium=email&utm_source=footer> . -- You received this message because you are subscribed to the Google Groups "elixir-lang-core" group. To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAKBKqKQyR%2BpkJ2JwJW8hCakw4jJ4q8TB%2BASx95FKPeGry1somA%40mail.gmail.com.