diff options
author | Araq <rumpf_a@web.de> | 2012-07-14 14:44:54 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2012-07-14 14:44:54 +0200 |
commit | d2872748c2913ff9139185a42737030f36a46440 (patch) | |
tree | c02d048bb98348d89067cdc40eb74f0beaa71692 | |
parent | b4084df434dc22d61960bcd6374d34af27bba888 (diff) | |
download | Nim-d2872748c2913ff9139185a42737030f36a46440.tar.gz |
added system.@ for openarrays
-rwxr-xr-x | lib/system.nim | 9 | ||||
-rwxr-xr-x | todo.txt | 7 | ||||
-rwxr-xr-x | web/news.txt | 3 |
3 files changed, 11 insertions, 8 deletions
diff --git a/lib/system.nim b/lib/system.nim index 1849b7916..5e223eb10 100755 --- a/lib/system.nim +++ b/lib/system.nim @@ -687,7 +687,7 @@ proc `@` * [IDX, T](a: array[IDX, T]): seq[T] {. magic: "ArrToSeq", nosideeffect.} ## turns an array into a sequence. This most often useful for constructing ## sequences with the array constructor: ``@[1, 2, 3]`` has the type - ## ``seq[int]``, while ``[1, 2, 3]`` has the type ``array[0..2, int]``. + ## ``seq[int]``, while ``[1, 2, 3]`` has the type ``array[0..2, int]``. proc setLen*[T](s: var seq[T], newlen: int) {. magic: "SetLengthSeq", noSideEffect.} @@ -1339,6 +1339,13 @@ proc isNil*(x: cstring): bool {.noSideEffect, magic: "IsNil".} ## Fast check whether `x` is nil. This is sometimes more efficient than ## ``== nil``. +proc `@`*[T](a: openArray[T]): seq[T] = + ## turns an openarray into a sequence. This is not as efficient as turning + ## a fixed length array into a sequence as it always copies every element + ## of `a`. + newSeq(result, a.len) + for i in 0..a.len-1: result[i] = a[i] + proc `&` *[T](x, y: seq[T]): seq[T] {.noSideEffect.} = newSeq(result, x.len + y.len) for i in 0..x.len-1: diff --git a/todo.txt b/todo.txt index b7f0ad4a9..afa90cc70 100755 --- a/todo.txt +++ b/todo.txt @@ -90,13 +90,6 @@ Library - pdcurses bindings -- for system: - proc `@` [T](a: openArray[T]): seq[T] = - newSeq(result, a.len) - for i in 0..a.len-1: result[i] = a[i] - - --> ensure @[] still calls the array version! - Low priority ------------ diff --git a/web/news.txt b/web/news.txt index 0143d8f9a..be9e5bf08 100755 --- a/web/news.txt +++ b/web/news.txt @@ -59,6 +59,9 @@ Library Additions - The httpclient module now supports ssl/tls. - Added ``times.format`` as well as many other utility functions for managing time. +- Added ``system.@`` for converting an ``openarray`` to a ``seq`` (it used to + only support fixed length arrays). + Changes affecting backwards compatibility ----------------------------------------- |