Generally I like the proposal, especially 1..0 returning an empty list.

Since we're bike shedding on the syntax, I would throw my hat into the ring for
1..10:2

Reasons:
1) : is used in many languages as part of the ?: ternary operator. (I know 
elixir doesn't have it but maybe in the future :D) so if ?: is ternary for 
branch then ..: is ternary for range and you could continue the approach for 
other syntax in the future.
2) \\ means optional right now but in practice we don't really want this to be 
optional in the future, correct? E.g. If new docs/syntax are going to say 
always do 1..10\\2 then the optional meaning is lost to me
3) minor: I always get \\ and // mixed up so it's a harder syntax personally to 
remember.

Thanks,
Anil

-------- Original Message --------
On Mar 22, 2021, 07:05, José Valim 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 [email protected].
> 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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/lE8_OJ65Fxuvk1FZxf3fcjEsyYa70CaB0ZpgJuwh8MAJMHvhm7tQDhvWPx9w2c9ZVK4b19hDQDHeD3iEmRKPS_-xdnTlG-1_-RBwKNzw5eU%3D%40terminal.space.

Reply via email to