Quick actions

cmd+k|ctrl+k

Navigation

Languages

open_intervals.nim

Snippet info

Language

Nim

Visibility

public

Author

mbarkhau

Created

2016-10-13T21:51:23Z

Updated

2016-10-13T22:20:14Z

proc `...`*[T](a, b: T): Slice[T] {.noSideEffect, inline, magic: "DotDot".} =
  ## `slice`:idx: operator that constructs an interval ``[a, b)``. `a` is
  ## inclusive and `b` is exclusive. Slices can also be used in the set
  ## constructor and in ordinal case statements, but then they are 
  ## special-cased by the compiler.
  result.a = a
  result.b = b - 1

let s = "test1234"

echo s[0...s.len]
echo s[0..s.len]

echo s[0...4]
echo s[4...8]

echo s[0..<4]
echo s[4..<8]

echo s[0..4]
echo s[4..8]
INFO