view types: spec changes (#18226)

* view types: spec changes

* Update doc/manual_experimental.rst

Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>

* Update doc/manual_experimental.rst

Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>

Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>
This commit is contained in:
Andreas Rumpf 2021-06-10 16:49:17 +02:00 • committed by GitHub
commit 2ea7287217
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 24 deletions

View file

@ -9,8 +9,9 @@ import tables
const
Whitespace = {' ', '\t', '\n', '\r'}
proc split*(s: string, seps: set[char] = Whitespace,
maxsplit: int = -1): Table[int, openArray[char]] =
proc split*(s: string, seps: set[char] = Whitespace, maxsplit: int = -1): Table[int, openArray[char]] #[tt.Error
'result' borrows from the immutable location 's' and attempts to mutate it
]# =
var last = 0
var splits = maxsplit
result = initTable[int, openArray[char]]()
@ -22,9 +23,7 @@ proc split*(s: string, seps: set[char] = Whitespace,
if splits == 0: last = len(s)
result[first] = toOpenArray(s, first, last-1)
result[first][0] = 'c' #[tt.Error
attempt to mutate a borrowed location from an immutable view
]#
result[first][0] = 'c'
if splits == 0: break
dec(splits)