Hey Ivan, You're just missing the introductory &
iex(1)> & &1 + 1 #Function<42.105768164/1 in :erl_eval.expr/6> On Wednesday, August 21, 2024 at 2:03:24 AM UTC-4 ivan.y...@gmail.com wrote: > I realize it might be controversial, but I truly enjoy short form lambdas > in any language I touch and Elixir is one of them. Yet I think there's a > couple of use cases that are uncovered. One is when you need to encode a > zero argument lambda returning a value and the second one is when there are > more arguments than actually used: > > iex(1)> &(&2 + 1) > > error: capture argument &2 cannot be defined without &1 (you cannot skip > arguments, all arguments must be numbered) > > └─ iex:1 > > > ** (CompileError) cannot compile code (errors have been logged) > > > iex(1)> &(1) > > error: capture argument &1 must be used within the capture operator & > > └─ iex:1 > > > ** (CompileError) cannot compile code (errors have been logged) > > I think both of these cases would be handled if we let explicitly defining > the arity of lambda: &2(&2 + 1) or something like that. Since nested > lambdas are not allowed anyways, this should work (unless I'm missing > something). And we'd assume if there's no access to the variables, it would > be a zero argument function, so &(1) would work too. > > This should be fundamentally possible, since I can do this: > > iex(9)> fn () -> :ok end > > #Function<43.105768164/0 in :erl_eval.expr/6> > > iex(10)> fn (_a, b) -> b * 2 end > > #Function<41.105768164/2 in :erl_eval.expr/6> > > So I assume it boils down to parsing? Either way, I'd love to see that in > Elixir and I'm willing to contribute some time to get it implemented if the > community approves it. > -- 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/11ca2681-4b0e-4875-ac48-455a5e684f6en%40googlegroups.com.