diff options
author | Araq <rumpf_a@web.de> | 2012-08-16 16:30:13 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2012-08-16 16:30:13 +0200 |
commit | d37fe6e0a5cc414c24dbff485ee656cc6f16eed8 (patch) | |
tree | 74e3faa868d278c4cb0ca749b939c02502b7db7b | |
parent | bbae747f02a67e36411b0d0168ebac4912ef7555 (diff) | |
download | Nim-d37fe6e0a5cc414c24dbff485ee656cc6f16eed8.tar.gz |
stdlib uses more of varargs
-rwxr-xr-x | lib/pure/strutils.nim | 2 | ||||
-rw-r--r-- | lib/pure/subexes.nim | 11 | ||||
-rwxr-xr-x | todo.txt | 3 | ||||
-rwxr-xr-x | web/news.txt | 2 |
4 files changed, 14 insertions, 4 deletions
diff --git a/lib/pure/strutils.nim b/lib/pure/strutils.nim index a93c3d289..2509bf689 100755 --- a/lib/pure/strutils.nim +++ b/lib/pure/strutils.nim @@ -1015,7 +1015,7 @@ proc findNormalized(x: string, inArray: openarray[string]): int = proc invalidFormatString() {.noinline.} = raise newException(EInvalidValue, "invalid format string") -proc addf*(s: var string, formatstr: string, a: openarray[string]) {. +proc addf*(s: var string, formatstr: string, a: varargs[string, `$`]) {. noSideEffect, rtl, extern: "nsuAddf".} = ## The same as ``add(s, formatstr % a)``, but more efficient. const PatternChars = {'a'..'z', 'A'..'Z', '0'..'9', '\128'..'\255', '_'} diff --git a/lib/pure/subexes.nim b/lib/pure/subexes.nim index 7ab5d1ad3..3e5e36b38 100644 --- a/lib/pure/subexes.nim +++ b/lib/pure/subexes.nim @@ -297,7 +297,7 @@ proc subex*(s: string): TSubex = ## no syntax checking but this may change in later versions. result = TSubex(s) -proc addf*(s: var string, formatstr: TSubex, a: openarray[string]) {. +proc addf*(s: var string, formatstr: TSubex, a: varargs[string, `$`]) {. noSideEffect, rtl, extern: "nfrmtAddf".} = ## The same as ``add(s, formatstr % a)``, but more efficient. var p: TFormatParser @@ -326,6 +326,15 @@ proc `%` *(formatstr: TSubex, a: string): string {.noSideEffect, result = newStringOfCap(formatstr.string.len + a.len) addf(result, formatstr, [a]) +proc format*(formatstr: TSubex, a: varargs[string, `$`]): string {.noSideEffect, + rtl, extern: "nfrmtFormatVarargs".} = + ## The `substitution`:idx: operator performs string substitutions in + ## `formatstr` and returns a modified `formatstr`. This is often called + ## `string interpolation`:idx:. + ## + result = newStringOfCap(formatstr.string.len + a.len shl 4) + addf(result, formatstr, a) + {.pop.} when isMainModule: diff --git a/todo.txt b/todo.txt index c3064a331..0a88dcd83 100755 --- a/todo.txt +++ b/todo.txt @@ -3,6 +3,7 @@ version 0.9.0 - implement "closure tuple consists of a single 'ref'" optimization - implement for loop transformation for first class iterators +- make templates hygienic by default: 'gensym', 'inject' pragmas - implicit deref for parameter matching - ``final`` should be the default for objects @@ -41,8 +42,6 @@ version 0.9.XX - ``hoist`` pragma for loop hoisting - document destructors; don't work yet when used as expression - make use of ``tyIter`` to fix the implicit items/pairs issue -- make templates hygienic by default: try to gensym() everything in the 'block' - of a template; find a better solution for gensym instead of `*ident` - introduce 'callsite' magic and make macros and templates the same - better support for macros that rewrite procs - macros need access to types and symbols diff --git a/web/news.txt b/web/news.txt index 69003601c..91c47a3d1 100755 --- a/web/news.txt +++ b/web/news.txt @@ -63,6 +63,8 @@ Library Additions only support fixed length arrays). - Added ``system.compiles`` which can be used to check whether a type supports some operation. +- Added ``strutils.format``, ``subexes.format`` which use the + new ``varargs`` type. Changes affecting backwards compatibility |