> Then if `x` is zero or less than zero, I get an empty list? This would definitely be nice, we've been bitten by the exact scenarios mentioned in the first post.
Precisely. I will change the proposal in a couple minutes to use x..y//z. Thanks Amos for pushing into this direction. <3 On Mon, Mar 22, 2021 at 4:00 PM Ben Wilson <benwilson...@gmail.com> wrote: > The 1..9//2 structure feels like the best of the presented options to me. > I think it reads well out loud, since .. often means "to" and / is often > rendered as "by" so that would read 1 to 9 by 2. > > To make sure I'm clear about the semantics: If I have: > > ``` > 1..x//1 |> Enum.to_list > ``` > > Then if `x` is zero or less than zero, I get an empty list? This would > definitely be nice, we've been bitten by the exact scenarios mentioned in > the first post. > On Monday, March 22, 2021 at 10:26:13 AM UTC-4 am...@binarynoggin.com > wrote: > >> Yes, the `1..9//2` communicates intention a little better than `a..b..c` >> IMO. >> >> Amos King, CEO >> >> <https://twitter.com/binarynoggin> >> <https://www.facebook.com/BinaryNoggin/> >> <https://www.instagram.com/binarynoggin/> >> <https://www.linkedin.com/company/binary-noggin> >> >> 573-263-2278 <(573)%20263-2278> am...@binarynoggin.com >> >> >> On Mon, Mar 22, 2021 at 9:05 AM José Valim <jose....@dashbit.co> wrote: >> >>> >>> >>>> 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`? >>>> >>> >>> Unfortunately a..b\\c is ambiguous because \\ is used as default >>> arguments. So you could do "a..b\\1..3". It is semantically unambiguous in >>> this case, but definitely syntactically ambiguous. >>> >>> Here are some approaches of what we could allow. I am considering they >>> all represent the range from 1 to 9 by 2 and from 9 to 1 by -1: >>> >>> - 1..2..9 and 9..-1..1 - as someone proposed, maybe having the step >>> in the middle is clearer >>> >>> - 1..9//2 and 9..1//-1 - note // is generally ambiguous in Elixir >>> because of the capture operator. So this will only work if ..// is >>> defined >>> as a ternary operator. This means we will likely introduce the atom :..// >>> and the capture operator would be &..///3. I think those are acceptable >>> trade-offs, but worth mentioning. >>> >>> - Combinations with \ and /: >>> - 1..9/\2 and 9..1/\-1 >>> - 1..9*\2 and 9..1*\-1 >>> - 1..9\/2 and 9..1\/-1 >>> - 1..9*/2 and 9..1*/-1 >>> >>> - 1..9^^2 and 9..1^^-2 >>> >>> To be honest, I like the first two. One nice bonus about 1..9//2 is >>> because we can actually think that it is cutting the number of elements in >>> 2, by some approximation. 1..8//1 has 8 elements. 1..8//2 has 4. :) >>> >>> -- >>> 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 >>> <https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4JNXVDdJG%3DJ2MuiiN9%2BxHNUm58%2Bi%3DAbPygGkZm6sZ4jEA%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/cfc0db92-7165-41dc-9241-8c9d6ef3a026n%40googlegroups.com > <https://groups.google.com/d/msgid/elixir-lang-core/cfc0db92-7165-41dc-9241-8c9d6ef3a026n%40googlegroups.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/CAGnRm4JiNu_PxmBdyOH1KjPqEn3gai_TapnA9FtMShKSyURHeQ%40mail.gmail.com.