nim-lang / RFCs

A repository for your Nim proposals.
135 stars 26 forks source link

deprecate unary slice `b[..2]` (error prone and not useful) #311

Closed timotheecour closed 3 years ago

timotheecour commented 3 years ago

proposal

deprecate unary slice https://nim-lang.github.io/Nim/system.html#..%2CsinkT

rationale

example 1

it seems error prone eg:

when true:
  var b: array[-3..3, float]
  echo b[.. 2] == b[0 .. 2]
  echo b[b.low .. 2] == b[0 .. 2]

prints: true false

it'd be useful if b[.. 2] would be syntax sugar for b[b.low .. 2] (analog to b[3..^1) but it seems that all it does is being equal to default(int), ie 0.

I don't see the point of avoiding to type 0.

example 2

it also doesn't compose well with rest of nim, eg:

when true:
  var b: array[..3, float] # Error: illformed AST: ..3

(analog to https://github.com/nim-lang/Nim/issues/6215)

bluenote10 commented 3 years ago

Another argument in favor of deprecating: As far as I know only b[.. 2] but not b[2 ..] is a thing. This asymmetry feels a bit awkward, because in other languages slice boundaries are typically either mandatory or optional in both positions.

Araq commented 3 years ago

Well but Nim simply doesn't have postfix operators, at all. Which is OK.

bluenote10 commented 3 years ago

It only feels "awkwardly" asymmetric when you look at it from an ignorant angle though. Nim simply doesn't have postfix operators so why would 2 .. be a thing? Perfectly senseful design.

No need to insult anyone. It is still a matter of expectation coming from other languages, no matter how sensible it is.

Araq commented 3 years ago

Sorry, no insult implied. I suppose "ignorant angle" isn't as neutral as I hoped it to be.

juancarlospaco commented 3 years ago

Nuke it. :+1:

Araq commented 3 years ago

Again, "Accepted RFC" here means, "let's see what it breaks".

planetis-m commented 3 years ago

I might be using this, I don't really like it but why remove it and whats the alternative? Edit: Could it be fixed instead?

planetis-m commented 3 years ago

Fine. 0..x is easy to write as well. Actually it seems, I have already removed it from my project.