(fn indentation [line] (case (line:find "[^ ]") start (- start 1)))

(fn normalize [line tab-width] (line:gsub "\t" (string.rep " " tab-width)))

(fn mean [counts]
  (/ (accumulate [sum 0 _ x (ipairs counts)] (+ sum x)) (length counts)))

(fn count [f]
  (mean (icollect [line (f:lines)] (indentation (normalize line 4)))))

(local means [])

(each [_ filename (ipairs arg)]
  (case (io.open filename)
    f (let [mean (count f)]
        (table.insert means mean)
        (print filename (string.format "%0.2f" mean))
        (f:close))
    _ (io.stderr:write (: "file not found: %s\n" :format filename))))

(print "Mean of means:" (string.format "%0.2f" (mean means)))

Generated by Phil Hagelberg using scpaste at Tue Jan 6 09:30:33 2026. PST. (original)