diff options
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/core/macros.nim | 6 | ||||
-rw-r--r-- | lib/impure/db_mongo.nim | 6 | ||||
-rwxr-xr-x | lib/impure/db_mysql.nim | 24 | ||||
-rwxr-xr-x | lib/impure/db_postgres.nim | 24 | ||||
-rwxr-xr-x | lib/impure/db_sqlite.nim | 24 | ||||
-rwxr-xr-x | lib/pure/collections/intsets.nim | 22 | ||||
-rw-r--r-- | lib/pure/ftpclient.nim | 2 | ||||
-rwxr-xr-x | lib/pure/pegs.nim | 8 | ||||
-rwxr-xr-x | lib/pure/strtabs.nim | 4 | ||||
-rwxr-xr-x | lib/pure/strutils.nim | 7 | ||||
-rwxr-xr-x | lib/system.nim | 20 | ||||
-rwxr-xr-x | lib/system/sysio.nim | 4 |
12 files changed, 80 insertions, 71 deletions
diff --git a/lib/core/macros.nim b/lib/core/macros.nim index 9d0994c2f..1881faf63 100755 --- a/lib/core/macros.nim +++ b/lib/core/macros.nim @@ -122,7 +122,7 @@ proc len*(n: PNimrodNode): int {.magic: "NLen".} proc add*(father, child: PNimrodNode) {.magic: "NAdd".} ## adds the `child` to the `father` node -proc add*(father: PNimrodNode, children: openArray[PNimrodNode]) {. +proc add*(father: PNimrodNode, children: varargs[PNimrodNode]) {. magic: "NAddMultiple".} ## adds each child of `children` to the `father` node @@ -251,7 +251,7 @@ proc expectLen*(n: PNimrodNode, len: int) {.compileTime.} = if n.len != len: error("macro expects a node with " & $len & " children") proc newCall*(theProc: TNimrodIdent, - args: openArray[PNimrodNode]): PNimrodNode {.compileTime.} = + args: varargs[PNimrodNode]): PNimrodNode {.compileTime.} = ## produces a new call node. `theProc` is the proc that is called with ## the arguments ``args[0..]``. result = newNimNode(nnkCall) @@ -259,7 +259,7 @@ proc newCall*(theProc: TNimrodIdent, result.add(args) proc newCall*(theProc: string, - args: openArray[PNimrodNode]): PNimrodNode {.compileTime.} = + args: varargs[PNimrodNode]): PNimrodNode {.compileTime.} = ## produces a new call node. `theProc` is the proc that is called with ## the arguments ``args[0..]``. result = newNimNode(nnkCall) diff --git a/lib/impure/db_mongo.nim b/lib/impure/db_mongo.nim index a2aebb6da..5195e2a09 100644 --- a/lib/impure/db_mongo.nim +++ b/lib/impure/db_mongo.nim @@ -165,13 +165,13 @@ iterator find*(db: var TDbConn, namespace: string, yield bson(cursor[])[] destroy(cursor[]) -proc setupFieldnames(fields: openArray[string]): TBSon = +proc setupFieldnames(fields: varargs[string]): TBSon = init(result) for x in fields: add(result, x, 1'i32) finish(result) iterator find*(db: var TDbConn, namespace: string, - query: var TBSon, fields: openArray[string]): var TBSon = + query: var TBSon, fields: varargs[string]): var TBSon = ## yields the `fields` of any document that suffices `query`. If `fields` ## is ``[]`` the whole document is yielded. var f = setupFieldnames(fields) @@ -188,7 +188,7 @@ proc setupQuery(query: string): TBSon = finish(result) iterator find*(db: var TDbConn, namespace: string, - query: string, fields: openArray[string]): var TBSon = + query: string, fields: varargs[string]): var TBSon = ## yields the `fields` of any document that suffices `query`. If `fields` ## is ``[]`` the whole document is yielded. var f = setupFieldnames(fields) diff --git a/lib/impure/db_mysql.nim b/lib/impure/db_mysql.nim index 2b94ab614..2b63137c8 100755 --- a/lib/impure/db_mysql.nim +++ b/lib/impure/db_mysql.nim @@ -34,7 +34,7 @@ proc dbError*(msg: string) {.noreturn.} = raise e when false: - proc dbQueryOpt*(db: TDbConn, query: string, args: openarray[string]) = + proc dbQueryOpt*(db: TDbConn, query: string, args: varargs[string]) = var stmt = mysql_stmt_init(db) if stmt == nil: dbError(db) if mysql_stmt_prepare(stmt, query, len(query)) != 0: @@ -50,7 +50,7 @@ proc dbQuote(s: string): string = else: add(result, c) add(result, '\'') -proc dbFormat(formatstr: TSqlQuery, args: openarray[string]): string = +proc dbFormat(formatstr: TSqlQuery, args: varargs[string]): string = result = "" var a = 0 for c in items(string(formatstr)): @@ -60,12 +60,12 @@ proc dbFormat(formatstr: TSqlQuery, args: openarray[string]): string = else: add(result, c) -proc TryExec*(db: TDbConn, query: TSqlQuery, args: openarray[string]): bool = +proc TryExec*(db: TDbConn, query: TSqlQuery, args: varargs[string]): bool = ## tries to execute the query and returns true if successful, false otherwise. var q = dbFormat(query, args) return mysql.RealQuery(db, q, q.len) == 0'i32 -proc Exec*(db: TDbConn, query: TSqlQuery, args: openarray[string]) = +proc Exec*(db: TDbConn, query: TSqlQuery, args: varargs[string]) = ## executes the query and raises EDB if not successful. var q = dbFormat(query, args) if mysql.RealQuery(db, q, q.len) != 0'i32: dbError(db) @@ -80,7 +80,7 @@ proc properFreeResult(sqlres: mysql.PRES, row: cstringArray) = mysql.FreeResult(sqlres) iterator FastRows*(db: TDbConn, query: TSqlQuery, - args: openarray[string]): TRow = + args: varargs[string]): TRow = ## executes the query and iterates over the result dataset. This is very ## fast, but potenially dangerous: If the for-loop-body executes another ## query, the results can be undefined. For MySQL this is the case!. @@ -100,7 +100,7 @@ iterator FastRows*(db: TDbConn, query: TSqlQuery, properFreeResult(sqlres, row) proc getRow*(db: TDbConn, query: TSqlQuery, - args: openarray[string]): TRow = + args: varargs[string]): TRow = ## retrieves a single row. Exec(db, query, args) var sqlres = mysql.UseResult(db) @@ -115,7 +115,7 @@ proc getRow*(db: TDbConn, query: TSqlQuery, properFreeResult(sqlres, row) proc GetAllRows*(db: TDbConn, query: TSqlQuery, - args: openarray[string]): seq[TRow] = + args: varargs[string]): seq[TRow] = ## executes the query and returns the whole result dataset. result = @[] Exec(db, query, args) @@ -134,12 +134,12 @@ proc GetAllRows*(db: TDbConn, query: TSqlQuery, mysql.FreeResult(sqlres) iterator Rows*(db: TDbConn, query: TSqlQuery, - args: openarray[string]): TRow = + args: varargs[string]): TRow = ## same as `FastRows`, but slower and safe. for r in items(GetAllRows(db, query, args)): yield r proc GetValue*(db: TDbConn, query: TSqlQuery, - args: openarray[string]): string = + args: varargs[string]): string = ## executes the query and returns the result dataset's the first column ## of the first row. Returns "" if the dataset contains no rows. This uses ## `FastRows`, so it inherits its fragile behaviour. @@ -149,7 +149,7 @@ proc GetValue*(db: TDbConn, query: TSqlQuery, break proc TryInsertID*(db: TDbConn, query: TSqlQuery, - args: openarray[string]): int64 = + args: varargs[string]): int64 = ## executes the query (typically "INSERT") and returns the ## generated ID for the row or -1 in case of an error. var q = dbFormat(query, args) @@ -158,14 +158,14 @@ proc TryInsertID*(db: TDbConn, query: TSqlQuery, else: result = mysql.InsertId(db) -proc InsertID*(db: TDbConn, query: TSqlQuery, args: openArray[string]): int64 = +proc InsertID*(db: TDbConn, query: TSqlQuery, args: varargs[string]): int64 = ## executes the query (typically "INSERT") and returns the ## generated ID for the row. result = TryInsertID(db, query, args) if result < 0: dbError(db) proc ExecAffectedRows*(db: TDbConn, query: TSqlQuery, - args: openArray[string]): int64 = + args: varargs[string]): int64 = ## runs the query (typically "UPDATE") and returns the ## number of affected rows Exec(db, query, args) diff --git a/lib/impure/db_postgres.nim b/lib/impure/db_postgres.nim index 19701f896..46909b9b2 100755 --- a/lib/impure/db_postgres.nim +++ b/lib/impure/db_postgres.nim @@ -49,7 +49,7 @@ proc dbQuote(s: string): string = else: add(result, c) add(result, '\'') -proc dbFormat(formatstr: TSqlQuery, args: openarray[string]): string = +proc dbFormat(formatstr: TSqlQuery, args: varargs[string]): string = result = "" var a = 0 for c in items(string(formatstr)): @@ -60,14 +60,14 @@ proc dbFormat(formatstr: TSqlQuery, args: openarray[string]): string = add(result, c) proc TryExec*(db: TDbConn, query: TSqlQuery, - args: openarray[string]): bool = + args: varargs[string]): bool = ## tries to execute the query and returns true if successful, false otherwise. var q = dbFormat(query, args) var res = PQExec(db, q) result = PQresultStatus(res) == PGRES_COMMAND_OK PQclear(res) -proc Exec*(db: TDbConn, query: TSqlQuery, args: openarray[string]) = +proc Exec*(db: TDbConn, query: TSqlQuery, args: varargs[string]) = ## executes the query and raises EDB if not successful. var q = dbFormat(query, args) var res = PQExec(db, q) @@ -79,7 +79,7 @@ proc newRow(L: int): TRow = for i in 0..L-1: result[i] = "" proc setupQuery(db: TDbConn, query: TSqlQuery, - args: openarray[string]): PPGresult = + args: varargs[string]): PPGresult = var q = dbFormat(query, args) result = PQExec(db, q) if PQresultStatus(result) != PGRES_TUPLES_OK: dbError(db) @@ -91,7 +91,7 @@ proc setRow(res: PPGresult, r: var TRow, line, cols: int32) = add(r[col], x) iterator FastRows*(db: TDbConn, query: TSqlQuery, - args: openarray[string]): TRow = + args: varargs[string]): TRow = ## executes the query and iterates over the result dataset. This is very ## fast, but potenially dangerous: If the for-loop-body executes another ## query, the results can be undefined. For Postgres it is safe though. @@ -104,7 +104,7 @@ iterator FastRows*(db: TDbConn, query: TSqlQuery, PQclear(res) proc getRow*(db: TDbConn, query: TSqlQuery, - args: openarray[string]): TRow = + args: varargs[string]): TRow = ## retrieves a single row. var res = setupQuery(db, query, args) var L = PQnfields(res) @@ -113,26 +113,26 @@ proc getRow*(db: TDbConn, query: TSqlQuery, PQclear(res) proc GetAllRows*(db: TDbConn, query: TSqlQuery, - args: openarray[string]): seq[TRow] = + args: varargs[string]): seq[TRow] = ## executes the query and returns the whole result dataset. result = @[] for r in FastRows(db, query, args): result.add(r) iterator Rows*(db: TDbConn, query: TSqlQuery, - args: openarray[string]): TRow = + args: varargs[string]): TRow = ## same as `FastRows`, but slower and safe. for r in items(GetAllRows(db, query, args)): yield r proc GetValue*(db: TDbConn, query: TSqlQuery, - args: openarray[string]): string = + args: varargs[string]): string = ## executes the query and returns the result dataset's the first column ## of the first row. Returns "" if the dataset contains no rows. var x = PQgetvalue(setupQuery(db, query, args), 0, 0) result = if isNil(x): "" else: $x proc TryInsertID*(db: TDbConn, query: TSqlQuery, - args: openarray[string]): int64 = + args: varargs[string]): int64 = ## executes the query (typically "INSERT") and returns the ## generated ID for the row or -1 in case of an error. For Postgre this adds ## ``RETURNING id`` to the query, so it only works if your primary key is @@ -144,7 +144,7 @@ proc TryInsertID*(db: TDbConn, query: TSqlQuery, result = -1 proc InsertID*(db: TDbConn, query: TSqlQuery, - args: openArray[string]): int64 = + args: varargs[string]): int64 = ## executes the query (typically "INSERT") and returns the ## generated ID for the row. For Postgre this adds ## ``RETURNING id`` to the query, so it only works if your primary key is @@ -153,7 +153,7 @@ proc InsertID*(db: TDbConn, query: TSqlQuery, if result < 0: dbError(db) proc ExecAffectedRows*(db: TDbConn, query: TSqlQuery, - args: openArray[string]): int64 = + args: varargs[string]): int64 = ## executes the query (typically "UPDATE") and returns the ## number of affected rows. var q = dbFormat(query, args) diff --git a/lib/impure/db_sqlite.nim b/lib/impure/db_sqlite.nim index dbeb1e594..29ff0693e 100755 --- a/lib/impure/db_sqlite.nim +++ b/lib/impure/db_sqlite.nim @@ -49,7 +49,7 @@ proc dbQuote(s: string): string = else: add(result, c) add(result, '\'') -proc dbFormat(formatstr: TSqlQuery, args: openarray[string]): string = +proc dbFormat(formatstr: TSqlQuery, args: varargs[string]): string = result = "" var a = 0 for c in items(string(formatstr)): @@ -60,7 +60,7 @@ proc dbFormat(formatstr: TSqlQuery, args: openarray[string]): string = add(result, c) proc TryExec*(db: TDbConn, query: TSqlQuery, - args: openarray[string]): bool = + args: varargs[string]): bool = ## tries to execute the query and returns true if successful, false otherwise. var q = dbFormat(query, args) var stmt: sqlite3.PStmt @@ -68,7 +68,7 @@ proc TryExec*(db: TDbConn, query: TSqlQuery, if step(stmt) == SQLITE_DONE: result = finalize(stmt) == SQLITE_OK -proc Exec*(db: TDbConn, query: TSqlQuery, args: openarray[string]) = +proc Exec*(db: TDbConn, query: TSqlQuery, args: varargs[string]) = ## executes the query and raises EDB if not successful. if not TryExec(db, query, args): dbError(db) @@ -77,7 +77,7 @@ proc newRow(L: int): TRow = for i in 0..L-1: result[i] = "" proc setupQuery(db: TDbConn, query: TSqlQuery, - args: openarray[string]): PStmt = + args: varargs[string]): PStmt = var q = dbFormat(query, args) if prepare_v2(db, q, q.len.cint, result, nil) != SQLITE_OK: dbError(db) @@ -89,7 +89,7 @@ proc setRow(stmt: PStmt, r: var TRow, cols: cint) = if not isNil(x): add(r[col], x) iterator FastRows*(db: TDbConn, query: TSqlQuery, - args: openarray[string]): TRow = + args: varargs[string]): TRow = ## executes the query and iterates over the result dataset. This is very ## fast, but potenially dangerous: If the for-loop-body executes another ## query, the results can be undefined. For Sqlite it is safe though. @@ -102,7 +102,7 @@ iterator FastRows*(db: TDbConn, query: TSqlQuery, if finalize(stmt) != SQLITE_OK: dbError(db) proc getRow*(db: TDbConn, query: TSqlQuery, - args: openarray[string]): TRow = + args: varargs[string]): TRow = ## retrieves a single row. var stmt = setupQuery(db, query, args) var L = (columnCount(stmt)) @@ -112,19 +112,19 @@ proc getRow*(db: TDbConn, query: TSqlQuery, if finalize(stmt) != SQLITE_OK: dbError(db) proc GetAllRows*(db: TDbConn, query: TSqlQuery, - args: openarray[string]): seq[TRow] = + args: varargs[string]): seq[TRow] = ## executes the query and returns the whole result dataset. result = @[] for r in FastRows(db, query, args): result.add(r) iterator Rows*(db: TDbConn, query: TSqlQuery, - args: openarray[string]): TRow = + args: varargs[string]): TRow = ## same as `FastRows`, but slower and safe. for r in FastRows(db, query, args): yield r proc GetValue*(db: TDbConn, query: TSqlQuery, - args: openarray[string]): string = + args: varargs[string]): string = ## executes the query and returns the result dataset's the first column ## of the first row. Returns "" if the dataset contains no rows. var stmt = setupQuery(db, query, args) @@ -136,7 +136,7 @@ proc GetValue*(db: TDbConn, query: TSqlQuery, result = "" proc TryInsertID*(db: TDbConn, query: TSqlQuery, - args: openarray[string]): int64 = + args: varargs[string]): int64 = ## executes the query (typically "INSERT") and returns the ## generated ID for the row or -1 in case of an error. if tryExec(db, query, args): @@ -145,7 +145,7 @@ proc TryInsertID*(db: TDbConn, query: TSqlQuery, result = -1 proc InsertID*(db: TDbConn, query: TSqlQuery, - args: openArray[string]): int64 = + args: varargs[string]): int64 = ## executes the query (typically "INSERT") and returns the ## generated ID for the row. For Postgre this adds ## ``RETURNING id`` to the query, so it only works if your primary key is @@ -154,7 +154,7 @@ proc InsertID*(db: TDbConn, query: TSqlQuery, if result < 0: dbError(db) proc ExecAffectedRows*(db: TDbConn, query: TSqlQuery, - args: openArray[string]): int64 = + args: varargs[string]): int64 = ## executes the query (typically "UPDATE") and returns the ## number of affected rows. Exec(db, query, args) diff --git a/lib/pure/collections/intsets.nim b/lib/pure/collections/intsets.nim index c98dd5de1..fcaf7b212 100755 --- a/lib/pure/collections/intsets.nim +++ b/lib/pure/collections/intsets.nim @@ -161,17 +161,6 @@ proc assign*(dest: var TIntSet, src: TIntSet) = it = it.next -template dollarImpl(): stmt = - result = "{" - for key in items(s): - if result.len > 1: result.add(", ") - result.add($key) - result.add("}") - -proc `$`*(s: TIntSet): string = - ## The `$` operator for int sets. - dollarImpl() - iterator items*(s: TIntSet): int {.inline.} = ## iterates over any included element of `s`. var r = s.head @@ -190,6 +179,17 @@ iterator items*(s: TIntSet): int {.inline.} = inc(i) r = r.next +template dollarImpl(): stmt = + result = "{" + for key in items(s): + if result.len > 1: result.add(", ") + result.add($key) + result.add("}") + +proc `$`*(s: TIntSet): string = + ## The `$` operator for int sets. + dollarImpl() + when isMainModule: var x = initIntSet() x.incl(1) diff --git a/lib/pure/ftpclient.nim b/lib/pure/ftpclient.nim index 4cf25a3cb..d3ed80683 100644 --- a/lib/pure/ftpclient.nim +++ b/lib/pure/ftpclient.nim @@ -108,7 +108,7 @@ proc assertReply(received: TaintedString, expected: string) = "Expected reply '$1' got: $2" % [ expected, received.string]) -proc assertReply(received: TaintedString, expected: openarray[string]) = +proc assertReply(received: TaintedString, expected: varargs[string]) = for i in items(expected): if received.string.startsWith(i): return raise newException(EInvalidReply, diff --git a/lib/pure/pegs.nim b/lib/pure/pegs.nim index ff88c56b8..efa77199b 100755 --- a/lib/pure/pegs.nim +++ b/lib/pure/pegs.nim @@ -149,7 +149,7 @@ template multipleOp(k: TPegKind, localOpt: expr) = if result.len == 1: result = result.sons[0] -proc `/`*(a: openArray[TPeg]): TPeg {. +proc `/`*(a: varargs[TPeg]): TPeg {. nosideEffect, rtl, extern: "npegsOrderedChoice".} = ## constructs an ordered choice with the PEGs in `a` multipleOp(pkOrderedChoice, addChoice) @@ -166,7 +166,7 @@ proc addSequence(dest: var TPeg, elem: TPeg) = else: add(dest, elem) else: add(dest, elem) -proc sequence*(a: openArray[TPeg]): TPeg {. +proc sequence*(a: varargs[TPeg]): TPeg {. nosideEffect, rtl, extern: "npegs$1".} = ## constructs a sequence with all the PEGs from `a` multipleOp(pkSequence, addSequence) @@ -939,7 +939,7 @@ proc replace*(s: string, sub: TPeg, by = ""): string {. inc(i, x) add(result, substr(s, i)) -proc parallelReplace*(s: string, subs: openArray[ +proc parallelReplace*(s: string, subs: varargs[ tuple[pattern: TPeg, repl: string]]): string {. nosideEffect, rtl, extern: "npegs$1".} = ## Returns a modified copy of `s` with the substitutions in `subs` @@ -964,7 +964,7 @@ proc parallelReplace*(s: string, subs: openArray[ add(result, substr(s, i)) proc transformFile*(infile, outfile: string, - subs: openArray[tuple[pattern: TPeg, repl: string]]) {. + subs: varargs[tuple[pattern: TPeg, repl: string]]) {. rtl, extern: "npegs$1".} = ## reads in the file `infile`, performs a parallel replacement (calls ## `parallelReplace`) and writes back to `outfile`. Raises ``EIO`` if an diff --git a/lib/pure/strtabs.nim b/lib/pure/strtabs.nim index 2f3aa4ee3..09a243e97 100755 --- a/lib/pure/strtabs.nim +++ b/lib/pure/strtabs.nim @@ -151,7 +151,7 @@ proc newStringTable*(mode: TStringTableMode): PStringTable {. result.counter = 0 newSeq(result.data, startSize) -proc newStringTable*(keyValuePairs: openarray[string], +proc newStringTable*(keyValuePairs: varargs[string], mode: TStringTableMode): PStringTable {. rtl, extern: "nst$1WithPairs".} = ## creates a new string table with given key value pairs. @@ -164,7 +164,7 @@ proc newStringTable*(keyValuePairs: openarray[string], result[keyValuePairs[i]] = keyValuePairs[i + 1] inc(i, 2) -proc newStringTable*(keyValuePairs: openarray[tuple[key, val: string]], +proc newStringTable*(keyValuePairs: varargs[tuple[key, val: string]], mode: TStringTableMode = modeCaseSensitive): PStringTable {. rtl, extern: "nst$1WithTableConstr".} = ## creates a new string table with given key value pairs. diff --git a/lib/pure/strutils.nim b/lib/pure/strutils.nim index aaff0d151..a93c3d289 100755 --- a/lib/pure/strutils.nim +++ b/lib/pure/strutils.nim @@ -1112,6 +1112,13 @@ proc `%` *(formatstr, a: string): string {.noSideEffect, ## This is the same as ``formatstr % [a]``. result = newStringOfCap(formatstr.len + a.len) addf(result, formatstr, [a]) + +proc format*(formatstr: string, a: varargs[string, `$`]): string {.noSideEffect, + rtl, extern: "nsuFormatVarargs".} = + ## This is the same as ``formatstr % a`` except that it supports + ## auto stringification. + result = newStringOfCap(formatstr.len + a.len) + addf(result, formatstr, a) {.pop.} diff --git a/lib/system.nim b/lib/system.nim index f3e7c525a..2d2de8e98 100755 --- a/lib/system.nim +++ b/lib/system.nim @@ -141,13 +141,14 @@ proc low*[T](x: T): T {.magic: "Low", noSideEffect.} ## semantic rule, `x` may also be a type identifier. type - range*{.magic: "Range".} [T] ## Generic type to construct range types. + range*{.magic: "Range".}[T] ## Generic type to construct range types. array*{.magic: "Array".}[I, T] ## Generic type to construct ## fixed-length arrays. openarray*{.magic: "OpenArray".}[T] ## Generic type to construct open arrays. ## Open arrays are implemented as a ## pointer to the array data and a ## length field. + varargs*{.magic: "Varargs".}[T] ## Generic type to construct a varargs type. seq*{.magic: "Seq".}[T] ## Generic type to construct sequences. set*{.magic: "Set".}[T] ## Generic type to construct bit sets. @@ -347,7 +348,8 @@ proc newSeq*[T](s: var seq[T], len: int) {.magic: "NewSeq", noSideEffect.} ## This is equivalent to ``s = @[]; setlen(s, len)``, but more ## efficient since no reallocation is needed. -proc len*[T: openArray](x: T): int {.magic: "LengthOpenArray", noSideEffect.} +proc len*[TOpenArray: openArray|varargs](x: TOpenArray): int {. + magic: "LengthOpenArray", noSideEffect.} proc len*(x: string): int {.magic: "LengthStr", noSideEffect.} proc len*(x: cstring): int {.magic: "LengthStr", noSideEffect.} proc len*[I, T](x: array[I, T]): int {.magic: "LengthArray", noSideEffect.} @@ -1238,8 +1240,8 @@ proc min*(x, y: int32): int32 {.magic: "MinI", noSideEffect.} proc min*(x, y: int64): int64 {.magic: "MinI64", noSideEffect.} ## The minimum value of two integers. -proc min*[T](x: openarray[T]): T = - ## The minimum value of an openarray. +proc min*[T](x: varargs[T]): T = + ## The minimum value of `x`. result = x[0] for i in 1..high(x): result = min(result, x[i]) @@ -1250,8 +1252,8 @@ proc max*(x, y: int32): int32 {.magic: "MaxI", noSideEffect.} proc max*(x, y: int64): int64 {.magic: "MaxI64", noSideEffect.} ## The maximum value of two integers. -proc max*[T](x: openarray[T]): T = - ## The maximum value of an openarray. +proc max*[T](x: varargs[T]): T = + ## The maximum value of `x`. result = x[0] for i in 1..high(x): result = max(result, x[i]) @@ -1642,7 +1644,7 @@ else: proc add*(x: var cstring, y: cstring) {.magic: "AppendStrStr".} -proc echo*[Ty](x: openarray[Ty]) {.magic: "Echo", noSideEffect.} +proc echo*[T](x: varargs[T, `$`]) {.magic: "Echo", noSideEffect.} ## special built-in that takes a variable number of arguments. Each argument ## is converted to a string via ``$``, so it works for user-defined ## types that have an overloaded ``$`` operator. @@ -1812,7 +1814,7 @@ when not defined(EcmaScript) and not defined(NimrodVM): proc write*(f: TFile, b: Bool) proc write*(f: TFile, c: char) proc write*(f: TFile, c: cstring) - proc write*(f: TFile, a: openArray[string]) + proc write*(f: TFile, a: varargs[string, `$`]) ## Writes a value to the file `f`. May throw an IO exception. proc readLine*(f: TFile): TaintedString @@ -1831,7 +1833,7 @@ when not defined(EcmaScript) and not defined(NimrodVM): ## writes a value `x` to `f` and then writes "\n". ## May throw an IO exception. - proc writeln*[Ty](f: TFile, x: openArray[Ty]) {.inline.} + proc writeln*[Ty](f: TFile, x: varargs[Ty, `$`]) {.inline.} ## writes a value `x` to `f` and then writes "\n". ## May throw an IO exception. diff --git a/lib/system/sysio.nim b/lib/system/sysio.nim index 012e5d95a..fa41a83cb 100755 --- a/lib/system/sysio.nim +++ b/lib/system/sysio.nim @@ -86,7 +86,7 @@ proc write(f: TFile, r: float) = fprintf(f, "%g", r) proc write(f: TFile, r: biggestFloat) = fprintf(f, "%g", r) proc write(f: TFile, c: Char) = putc(c, f) -proc write(f: TFile, a: openArray[string]) = +proc write(f: TFile, a: varargs[string, `$`]) = for x in items(a): write(f, x) proc readAllBuffer(file: TFile): string = @@ -150,7 +150,7 @@ proc writeln[Ty](f: TFile, x: Ty) = write(f, x) write(f, "\n") -proc writeln[Ty](f: TFile, x: openArray[Ty]) = +proc writeln[Ty](f: TFile, x: varargs[Ty, `$`]) = for i in items(x): write(f, i) write(f, "\n") |