about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-06-23 00:32:50 +0200
committerbptato <nincsnevem662@gmail.com>2023-06-23 00:36:09 +0200
commit5d895934d4a89bb2efafc0de8e2009d880c7cfe0 (patch)
tree10034287ce1f25a6c3decc4099cab2ae040c7fef
parent06a2f55dbcc67b731d1140d41af98ba316ecf5d6 (diff)
downloadchawan-5d895934d4a89bb2efafc0de8e2009d880c7cfe0.tar.gz
eprint: simplify
-rw-r--r--src/utils/eprint.nim56
1 files changed, 23 insertions, 33 deletions
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)