Skip to content

mathematical interval notation for slice syntax #432

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
oli-obk opened this issue Nov 3, 2014 · 2 comments
Closed

mathematical interval notation for slice syntax #432

oli-obk opened this issue Nov 3, 2014 · 2 comments

Comments

@oli-obk
Copy link
Contributor

oli-obk commented Nov 3, 2014

https://github.com/rust-lang/rfcs/blob/master/text/0198-slice-notation.md introduced the [start..end] syntax for slices. There was some serious discussion about the readability of the notation (#198). I suggest using interval notation (https://en.wikipedia.org/wiki/Interval_%28mathematics%29).
Using [), (] or () like in the docs (http://doc.rust-lang.org/std/slice/trait.ImmutableSlice.html#tymethod.slice) is not a good idea, since it'll be confused with function syntax. But the alternative (US) notation [[, ]] or ][ is also part of the ISO 80000-2 standard (behind paywall, or google "international iso standard 80000-2 interval notation").

  • foo][ for foo.as_slice()
  • foo[n,m[ for foo.slice(n, m) or foo[n..m]
  • foo[n,m] for foo.slice(n, m+1)
  • foo]n,m] for foo.slice(n+1, m+1)
  • foo]n,m[ for foo.slice(n+1, m)
  • mut variants of all the above

I'm not sure about the unbounded versions though. Following my above suggestions it would be:

  • foo[n,] for foo.slice_from(n) or foo[n..]
  • foo[,m] for foo.slice_to(m) or foo[..m]

But right there the #198 notations appeals to me more. Another alternative, that also helps prevent typos would be to require an underscore for open ended intervals.

  • foo[n,_] for foo.slice_from(n) or foo[n..]
  • foo[_,m] for foo.slice_to(m) or foo[..m]

Intervals are not ranges. So technically this should be a way to declare intervals which then could be passed to the slice function. But i do not think the following looks readable (which is the whole point of this feature request).

  • foo[[n,m[] for foo.slice(n, m) or foo[n..m]
@nrc
Copy link
Member

nrc commented Nov 3, 2014

Anything which uses unbalanced brackets of any kind is a non-starter since it will break the tokeniser and confuse every editor in existence. I guess the other suggestions could be considered, but most people seem pretty happy with the existing syntax (with some minor disagreement with [] vs [..]).

@oli-obk
Copy link
Contributor Author

oli-obk commented Nov 4, 2014

ok, I can see how this is not a good idea from the parser point of view.

@oli-obk oli-obk closed this as completed Nov 4, 2014
wycats pushed a commit to wycats/rust-rfcs that referenced this issue Mar 5, 2019
Contextual Helpers and Modifiers (a.k.a. "first-class helpers/modifiers")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants