Hi,

You could use a function that manipulates your function:

def shift_args(f), do: fn _x, y -> f(y) end

Now, with that, your proposed:

&(&2 + 1)

becomes

shift_args(&(&1 + 1))

This is just food for thought. In my opinion, it's often better to just
resort to good old functions:

fn _, x -> x + 1 end

In Haskell, you get away with "end" due to indentation sensitivity, and
they use the "\" to construct a lambda (it looks like Greek lambda letter :)

\_, x -> x + 1

Or uncurried:

\_ -> \x -> x + 1

So if at all, I would like of a way to reuse or "fn" literal without the
verbose "end". That likely requires parenthesis, so you really would only
save one character in the end.

You might also try to mess around with macros. So I think something like
below could work:

f(_2 + 1, arity: 2)

The macro "f" would translate that into:

fn _, arg_2 -> arg_2 + 1 end

Just be aware that you'd need to do the variable substitution correctly :).

Regards,

Michael

Ivan Yurov <ivan.your...@gmail.com> schrieb am Sa., 24. Aug. 2024, 01:44:

> Right. Sorry, please ignore the proposal to use &X to denote arity, the
> intent was to rather test the idea to be able to do that in general, not a
> particular syntax that would facilitate that. Using &/X might be a better
> candidate since it reflects the arity just the same way function capture
> does (minus function name, which totally makes sense in case of an
> anonymous function). Yet there might be way better candidates which can be
> discovered through discussion I'm sure, if the community is in favor of
> such extension in principle.
>
> --
> 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/CAAoaZy4tQ4AfmrQvYUFngVbyZQvH5pyXDo%3Dx55wcTFOacUn68w%40mail.gmail.com
> <https://groups.google.com/d/msgid/elixir-lang-core/CAAoaZy4tQ4AfmrQvYUFngVbyZQvH5pyXDo%3Dx55wcTFOacUn68w%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/CAKjimW%2BG4Vh%3DE-fhzqb%2BwueS%3DbTa3cyrQTU-ArkLD%2BxtK%2Be9-g%40mail.gmail.com.

Reply via email to