diff options
Diffstat (limited to 'lib/system.nim')
-rwxr-xr-x | lib/system.nim | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/lib/system.nim b/lib/system.nim index daf0c5423..c786e8355 100755 --- a/lib/system.nim +++ b/lib/system.nim @@ -1213,14 +1213,14 @@ iterator fieldPairs*(x, y: tuple[]): tuple[a, b: expr] {. ## in the loop body. proc `==`*[T: tuple](x, y: T): bool = - ## generic ``==`` operator that is lifted from the components + ## generic ``==`` operator for tuples that is lifted from the components ## of `x` and `y`. for a, b in fields(x, y): if a != b: return false return true proc `<=`*[T: tuple](x, y: T): bool = - ## generic ``<=`` operator that is lifted from the components + ## generic ``<=`` operator for tuples that is lifted from the components ## of `x` and `y`. This implementation uses `cmp`. for a, b in fields(x, y): var c = cmp(a, b) @@ -1229,7 +1229,7 @@ proc `<=`*[T: tuple](x, y: T): bool = return true proc `<`*[T: tuple](x, y: T): bool = - ## generic ``<`` operator that is lifted from the components + ## generic ``<`` operator for tuples that is lifted from the components ## of `x` and `y`. This implementation uses `cmp`. for a, b in fields(x, y): var c = cmp(a, b) @@ -1238,7 +1238,8 @@ proc `<`*[T: tuple](x, y: T): bool = return false proc `$`*[T: tuple](x: T): string = - ## generic ``$`` operator that is lifted from the components of `x`. + ## generic ``$`` operator for tuples that is lifted from the components + ## of `x`. result = "(" for name, value in fieldPairs(x): if result.len > 1: result.add(", ") @@ -1476,15 +1477,22 @@ when not defined(EcmaScript) and not defined(NimrodVM): ## Opens a file named `filename` with given `mode`. ## ## Default mode is readonly. Returns true iff the file could be opened. - ## This throws no exception if the file could not be opened. The reason is - ## that the programmer needs to provide an appropriate error message - ## anyway. + ## This throws no exception if the file could not be opened. proc Open*(f: var TFile, filehandle: TFileHandle, mode: TFileMode = fmRead): Bool ## Creates a ``TFile`` from a `filehandle` with given `mode`. ## ## Default mode is readonly. Returns true iff the file could be opened. + + proc Open*(filename: string, + mode: TFileMode = fmRead, bufSize: int = -1): TFile = + ## Opens a file named `filename` with given `mode`. + ## + ## Default mode is readonly. Raises an ``IO`` exception if the file + ## could not be opened. + if not open(result, filename, mode, bufSize): + raise newException(EIO, "cannot open: " & filename) proc reopen*(f: TFile, filename: string, mode: TFileMode = fmRead): bool ## reopens the file `f` with given `filename` and `mode`. This @@ -1581,10 +1589,7 @@ when not defined(EcmaScript) and not defined(NimrodVM): iterator lines*(filename: string): string = ## Iterate over any line in the file named `filename`. ## If the file does not exist `EIO` is raised. - var - f: TFile - if not open(f, filename): - raise newException(EIO, "cannot open: " & filename) + var f = open(filename) var res = "" while not endOfFile(f): rawReadLine(f, res) |