Skip to content

Instantly share code, notes, and snippets.

@shawwn
Created September 9, 2018 11:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shawwn/e178e597cbf7f3682153e449f66335a0 to your computer and use it in GitHub Desktop.
Save shawwn/e178e597cbf7f3682153e449f66335a0 to your computer and use it in GitHub Desktop.
(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