> # -- or happy's way --
> {:ok, str} when is_binary(str) = get_a_string_or_whatever() # Enforce
> entire matching semantics, inline!
>
Unfortunately this requires mangling of the AST because "=" has higher
precedence than "when". I wonder if happy path behaves correctly in cases
such as:
IO.inspect({:ok, str} when is_binary(str) = get_a_string_or_whatever())
Or in cases such as:
{:ok, str} when is_binary(str) = tuple when is_tuple(tuple) =
get_a_string_or_whatever()
And we cannot change the precedence as it would break cases such as:
{:ok, str} = tuple when is_binary(str) ->
I do like `<-` and `->` but when I see them I think of list stuff (I'm an
> old erlang programmer) and certainly not inline matching enforcement.
>
None of them are related to looping. -> is only used inside do blocks to
specify clauses, such as case and receive (exactly the same as in Erlang).
<- would be more correctly described as a "soft-matching" operator. In both
for and with, they specify that the construct should not continue if there
is not a match. The looping is not a property of <-, but a property of the
enclosing construct (i.e. for/with). This is also inline with the usage of
<- in monads (which could describe both for and with).
> Personally, I'd change Elixir so that `=` supports `when`, just naturally
> and everywhere
>
I would love this too, it is one the things I attempted early on but the
operator precedence would never work out. Which is what makes me wary of
overloading =, specially if it requires mangling the AST.
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4KFXBgXZJOfTU8xL391jPbSc1eM%2BFXFYtf4PoTacJaH_w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.