The lambdas I want to be able to create using short notation are in the second block of code in the original posting. They are slightly less obvious than & &1 + 1. As far as I understand, there's no way to compose them using short form, unless I'm missing something. The idea to supply a number of arguments along with introductory & is probably not gonna fly — it would look too similar to argument itself, although there shouldn't be any ambiguity with parsing since nested short form lambdas are not allowed anyways. Maybe &/2 which would be consistent with captures?
On Thu, Aug 22, 2024 at 10:19 AM Ben Wilson <benwilson...@gmail.com> wrote: > 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 a topic in the > Google Groups "elixir-lang-core" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/elixir-lang-core/g2tQI1FjcNU/unsubscribe > . > To unsubscribe from this group and all its topics, 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 > <https://groups.google.com/d/msgid/elixir-lang-core/11ca2681-4b0e-4875-ac48-455a5e684f6en%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- Kind regards, Ivan Yurov -- 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/CAAoaZy4gPokWC7urFA7sjqHzL%3DyVKdkHqGd6PM_Sc5o0MDtVGg%40mail.gmail.com.