I cannot figure this one out. When I remove let size = s.readInt64()
from the following proc, the .exe seems to terminate before it reaches the end. It is declared but not used! Its gotta go!
proc load(fn: string): Alternating =
var s = newFileStream(fn, fmRead)
let size = s.readInt64() #WITHOUT THIS LINE THE .exe doesn't execute ExitTerminal()
result = newSeq[(float, int)]()
while not s.atEnd:
let element = (s.readFloat64.float, s.readInt64.int)
result.add(element)
s.close()
Below is the entire program. The file type is .dat
and I suppose it is binary. It is created in the program. I compiled with -d:release
Nim version 0.18.0 and minGW compiler
import streams
type
Alternating = seq[(float, int)]
proc store(fn: string, data: Alternating) =
var s = newFileStream(fn, fmWrite)
s.write(data.len)
for x in data:
s.write(x[0])
s.write(x[1])
s.close()
proc load(fn: string): Alternating =
var s = newFileStream(fn, fmRead)
let size = s.readInt64() #WITHOUT THIS LINE THE .exe doesn't execute ExitTerminal()
result = newSeq[(float, int)]()
while not s.atEnd:
let element = (s.readFloat64.float, s.readInt64.int)
result.add(element)
s.close()
let data = @[(1.0, 1), (2.0, 2)]
store("tmp.dat", data)
let dataLoaded = load("tmp.dat")
echo dataLoaded
### EXIT PROCEDURE FROM TERMINAL PROGRAM
proc ExitTerminal: bool =
echo "Exit Application"
echo "(y/n)"
while true:
case readline(stdin)
of "y", "Y", "yes", "Yes": return true
of "n", "N", "no", "No": return false
else: echo "Please be clear: yes or no"
if ExitTerminal() == false: discard ExitTerminal()