[racket] Unreachable line reached
> However, after your email I can see that after (loop (read-line in))
> finishes <rest> is going to be executed. And this _has_ to be executed
> unless there was a return or exception in the function, but since we are in
> Racket and I am not playing with call/cc, <rest> will be executed no matter
> what.
>
> As you can see, I have been doing imperative languages for too long now.
Hi Paolo,
When I look at the program more closely, I think the structure of the
iteration might be improved with a "for" loop and the match library.
I'm trying to avoid let loops these days just because they remind me
too much of GOTO-sytle programming. :)
Here's my take on your snippet:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(for ([line (in-lines in)])
(match (string-split line ",")
[(list path modtime-str md5-str)
(define modtime (string->number (string-trim modtime-str)))
(define md5 (string->bytes/utf-8 (string-trim md5-str)))
(cond
[(or (not path) (not modtime) (not md5))
(printf "[2] read-cache fails, unexpected line in cache file:
~a, ignoring.~n" line)]
[else
(hash-set! (*cache*) path (cons modtime md5))])]
[else
(printf "[1] read-cache fails, unexpected line in cache file: ~a,
ignoring.~n" line)]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Good luck!