The following naive proc generates an internal error
/usr/lib/nim/system/io.nim(911, 10) Error: internal error: proc has no result symbol
No stack traceback available
To create a stacktrace, rerun compilation with './koch temp c <file>', see https://nim-lang.github.io/Nim/intern.html#debugging-the-compiler for details
import os, strutils
var Inp = stdin
proc Read(Input:File) =
for L in Input.lines.strip :
echo L
Read(stdin)
By the way, is there a means to strip the input lines directly instead of
var LS = L.strip
nim --version
Nim Compiler Version 1.5.1 [Linux: amd64]
Compiled at 2020-11-18
Copyright (c) 2006-2020 by Andreas Rumpf
git hash: 5ccfc8ccdc4b57506e5d61dcae69e902260cfd6e
active boot switches: -d:release
Many thanks for a hint, HelmutThe problem is that you called strip on iterator.
import strutils
proc read(input: File) =
for line in input.lines:
echo line.strip
read(stdin)
This should be considered as a bug in compiler, you may report it on github.
You should report the error on the Nim github. In this case you are applying a proc/iterator strip to the lines iterator which is not valid. You probably want this instead which compiles fine:
import os, strutils
proc read(input: File) =
for line in input.lines:
echo line.strip
read(stdin)
I am not sure what you mean by stripping "more directly". You could write a wrapper iterator, strippedLines whose usage would be:
for line in stdin.strippedLines: echo line
I think it would probably be a good exercise for you to write that yourself, though. :-)@cblake I'd need some help with this iterator wrapper. I have tried
import os, strutils
iterator stripped[T](orig:iterator : T) : T =
for l in orig.lines :
yield l.strip
proc Read(Input:File) =
for L in stripped(Input) :
echo L
Read(stdin)
but get
Error: type mismatch: got <File> but expected one of: iterator strippedT: T first type mismatch at position: 1 required type for orig: iterator (): T{.closure.} but expression 'Input' is of type: File
expression: stripped(Input)
like this?
import os, strutils
iterator stripped(fh: File): string =
for line in fh.lines :
yield line.strip
proc read(input: File) =
for line in stripped(input) :
echo line
read(stdin)