From 5d895934d4a89bb2efafc0de8e2009d880c7cfe0 Mon Sep 17 00:00:00 2001 From: bptato Date: Fri, 23 Jun 2023 00:32:50 +0200 Subject: eprint: simplify --- src/utils/eprint.nim | 56 +++++++++++++++++++++------------------------------- 1 file changed, 23 insertions(+), 33 deletions(-) (limited to 'src') diff --git a/src/utils/eprint.nim b/src/utils/eprint.nim index fab56464..02072bc6 100644 --- a/src/utils/eprint.nim +++ b/src/utils/eprint.nim @@ -1,38 +1,28 @@ {.used.} -func eprint*(s: varargs[string, `$`]) = {.cast(noSideEffect), cast(tags: []), cast(raises: []).}: - var a = false - var o = "" - when nimVm: - for x in s: - if not a: - a = true - else: +func eprint*(s: varargs[string, `$`]) = + {.cast(noSideEffect), cast(tags: []), cast(raises: []).}: + var o = "" + for i in 0 ..< s.len: + if i != 0: o &= ' ' - o &= x - echo o - else: - for x in s: - if not a: - a = true - else: + o &= s[i] + when nimVm: + echo o + else: + o &= '\n' + stderr.write(o) + +func elog*(s: varargs[string, `$`]) = + {.cast(noSideEffect), cast(tags: []), cast(raises: []).}: + var f: File + if not open(f, "a", fmAppend): + return + var o = "" + for i in 0 ..< s.len: + if i != 0: o &= ' ' - o &= x + o &= s[i] o &= '\n' - stderr.write(o) - -func elog*(s: varargs[string, `$`]) = {.cast(noSideEffect), cast(tags: []), cast(raises: []).}: - var f: File - if not open(f, "a", fmAppend): - return - var a = false - var o = "" - for x in s: - if not a: - a = true - else: - o &= ' ' - o &= x - o &= '\n' - f.write(o) - close(f) + f.write(o) + close(f) -- cgit 1.4.1-2-gfad0