Comment

Comment by jzimbel

Elixir puts some guardrails on its numbered-argument anonymous function syntax, which I think do a good job of restricting its use to defining extremely simple functions.

1. The function has to use all of its arguments at least once. You can’t do `&(&2)`, because it skips the first argument.

2. Single-expression. You can’t do something like `&(x = &1; x + 1)`.

3. No nesting. You can’t define an additional anonymous function inside of a & expression, or even use a `&SomeModule.some_fn/arity` capture. For anonymous functions with nesting, you have to use the `fn arg1, arg2, ... -> body end` syntax.

parent jzimbel 3 years ago

No comments yet

Be the first to share your thoughts.

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton