--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/1d816043-d473-4ced-8194-6c1227232e99%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
(while using `=` instead of `<-` while having the same features, and more)
--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4LKCpzZ4_S%2BbwTwpAp90zWhwSsbUZAoCOo01-kpaG2o9g%40mail.gmail.com.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAN3B1jdNDnjTFfqnM2wDEskJKpvL9j8M4KLLdo%3Diyj1QzhrBFg%40mail.gmail.com.
(while using `=` instead of `<-` while having the same features, and more)Coincidentally that's the one thing I dislike about happy: the overriding of the operator =. <- was made to be used exactly in situations such like this and that's why it has no semantics outside of existing constructs. :)
Has there been consideration of adding a "happy-like" macro version of with (that has the same syntax as happy, but with <-)? I've also implemented something like this locally for my projects, I find it reads more pleasantly.Obviously, this works fine for me but if many folks are interested in this syntactic form, perhaps including the alternative in elixir itself makes sense.
# -- or happy's way --{:ok, str} when is_binary(str) = get_a_string_or_whatever() # Enforce entire matching semantics, inline!
IO.inspect({:ok, str} when is_binary(str) = get_a_string_or_whatever())
{:ok, str} when is_binary(str) = tuple when is_tuple(tuple) = get_a_string_or_whatever()
{: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.
Personally, I'd change Elixir so that `=` supports `when`, just naturally and everywhere
# -- 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).
<-
:" to something of that form, maybe like "`<-` matches on each given element and skips non-matches", although that still does not match how `with` does it. Hmm, it seems that `for` and `with` are using an identical operator in incompatible ways. Unsure how to resolve that without changing the form of one or the other... (/me really dislikes operators that do different things in different areas)Personally, I'd change Elixir so that `=` supports `when`, just naturally and everywhereI 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.
Testing, indeed it is not valid there. :-)I wonder if it would be worth supporting such a case, I could report it in any case, done. :-)
Hmm, soft-matching operator, makes sense. Any chance on updating the docs at http://elixir-lang.org/docs/stable/elixir/Kernel.SpecialForms.html#for/1 where it states "Enumerable generators are defined using<-
:" to something of that form, maybe like "`<-` matches on each given element and skips non-matches", although that still does not match how `with` does it. Hmm, it seems that `for` and `with` are using an identical operator in incompatible ways.
Hmm, having `when` be directly adjacent to `=` in precedence, what side effects would that have? I do not think that `=` is allowed adjacent to a `when` that I can think of in function heads (which are the only other case where `when` is used that comes to immediate mind) so no issue there.