Created
September 9, 2018 11:25
-
-
Save shawwn/e178e597cbf7f3682153e449f66335a0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define aux (load "aux.l")) | |
(define count-indexed (name) | |
(let h ((get io 'open) name) | |
((get h 'seek) h "end" -8) | |
(with n (tonumber (be64dec ((get h 'read) h "*a"))) | |
((get h 'close) h)))) | |
(define count-rows (name) | |
(let h ((get io 'open) name) | |
(with i 0 | |
(while true | |
(define line ((get h 'read) h "*l")) | |
(unless line (break)) | |
(unless (or (= line "") (= line "\r")) | |
(inc i))) | |
((get h 'close) h)))) | |
(define count (name) | |
(if (file-exists? (cat name ".idx")) | |
(count-indexed (cat name ".idx")) | |
(count-rows name))) | |
(define name (at argv 1)) | |
(define n (count name)) | |
(dec n) ; skip the CSV header. | |
(print n) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment