As someone who has encountered quite a number of situations in
which an empty range would have been useful, I am very excited by
this proposal!
Two questions:
1. What about using a different syntax for separating the third
parameter?
If there is any way to make it more obvious that the third parameter is the step rather than the (upper) bound, then in my opinion this might be preferable over having syntax which is e.g. "just like F#'s but with opposite meaning". The less ambiguous we can make it (for people coming from other languages, and for people in general), the better.
Maybe `1..10:3`?
2. What will the step-based syntax expand to in guards?
`when foo in 42..69` expands to `when is_integer(foo) and foo >= 42 and foo <= 69`.
What should `when foo in 42..69..3` (again assuming x, y, z to be literals) expand to?
Maybe `when is_integer(foo) and foo >= 42 and foo <= 69 and rem(foo - 42), 3)`?
Or is there a better alternative?
~Marten / Qqwy
--
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-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4%2BxGUW-nBj0qqRygR_-J05c05bW6mpDV9ki-HPCvfrudQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/e1f904b3-3cd2-0ef1-f438-8408f5102c48%40resilia.nl.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4%2BX2CPbHsMgM0vMOpmV%2BjvE26r%2Bw-%2BmafnQC5i-G8Qspg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/7F881DB7-5E72-4DEC-AE89-9558E72E253F%40binarynoggin.com.
What about something closer to Haskell’s ranges? [first, second..last] is their syntax and the step in inferred by the difference between first and second. 1..2..n would step by one. 1..3..n is step by two. 1..2..0 would be empty, etc.
Negative steps. 1..0..-10. 1..0..10 would return an empty range.
I like this syntax because it creates an interesting logical thought as I how I’m counting. I think it is a friendlier syntax that doesn’t have to be explained in as much detail. 1..n makes sense when I look at it. 1..-1 also makes sense at a glance. 1..2..10 makes sense IMO. 1..10..2 looks surprising and confusing to me.
Amos
On Mar 22, 2021, at 06:32, José Valim <jose....@dashbit.co> wrote:
> 1. What about using a different syntax for separating the third parameter?
Suggestions are welcome. The proposed x..y:z doesn't work though, since y/z can be taken to mean keyword or an atom. And, FWIW, I didn't take x..y..z because of F#, but rather as a natural extension of .. that at least exists elsewhere too. It is important to not confuse the cause here. :)
> 2. What will the step-based syntax expand to in guards? Maybe `when is_integer(foo) and foo >= 42 and foo <= 69 and rem(foo - 42), 3)`?
Correct.
--
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-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4%2BX2CPbHsMgM0vMOpmV%2BjvE26r%2Bw-%2BmafnQC5i-G8Qspg%40mail.gmail.com.
--
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-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/7F881DB7-5E72-4DEC-AE89-9558E72E253F%40binarynoggin.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/7F881DB7-5E72-4DEC-AE89-9558E72E253F%40binarynoggin.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4JL-Ge-c5LF%3DH5pCiGeDwug1Nt6c-fMzuxGizaeh_%2BECA%40mail.gmail.com.
Amos King, CEO
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4JwHL4f3M1Lq-C6ATxrAeu2VkW0_a6P_dGQ%2BGfjqUV-Cg%40mail.gmail.com.
I still find the syntax to be confusing with the step as the last element. I really wish that we could do something like `a..b by: 3` but that comes with other implementation issues. I like the proposals using a different operator for the step. `a..b\\c`?
Amos King, CEO
--
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-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4JNXVDdJG%3DJ2MuiiN9%2BxHNUm58%2Bi%3DAbPygGkZm6sZ4jEA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/cfc0db92-7165-41dc-9241-8c9d6ef3a026n%40googlegroups.com.
--
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-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4JNXVDdJG%3DJ2MuiiN9%2BxHNUm58%2Bi%3DAbPygGkZm6sZ4jEA%40mail.gmail.com.
Since we're bike shedding on the syntax, I would throw my hat into the ring for
1..10:2
--
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-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/f6221657-7bd7-4f77-9917-157da64d7509n%40googlegroups.com.