/code.arc
Unknown | 61 lines | 48 code | 13 blank | 0 comment | 0 complexity | 1be36717a4151f833e4b7e0ed6756c25 MD5 | raw file
1; Code analysis. Spun off 21 Dec 07. 2 3; Ought to do more of this in Arc. One of the biggest advantages 4; of Lisp is messing with code. 5 6(def codelines (file) 7 (w/infile in file 8 (summing test 9 (whilet line (readline in) 10 (test (aand (find nonwhite line) (isnt it #\;))))))) 11 12(def codeflat (file) 13 (len (flat (readall (infile file))))) 14 15(def codetree (file) 16 (treewise + (fn (x) 1) (readall (infile file)))) 17 18(def code-density (file) 19 (/ (codetree file) (codelines file))) 20 21(def tokcount (files) 22 (let counts (table) 23 (each f files 24 (each token (flat (readall (infile f))) 25 (++ (counts token 0)))) 26 counts)) 27 28(def common-tokens (files) 29 (let counts (tokcount files) 30 (let ranking nil 31 (maptable (fn (k v) 32 (unless (nonop k) 33 (insort (compare > cadr) (list k v) ranking))) 34 counts) 35 ranking))) 36 37(def nonop (x) 38 (in x 'quote 'unquote 'quasiquote 'unquote-splicing)) 39 40(def common-operators (files) 41 (keep [and (isa (car _) 'sym) (bound (car _))] (common-tokens files))) 42 43(def top40 (xs) 44 (map prn (firstn 40 xs)) 45 t) 46 47(def space-eaters (files) 48 (let counts (tokcount files) 49 (let ranking nil 50 (maptable (fn (k v) 51 (when (and (isa k 'sym) (bound k)) 52 (insort (compare > [* (len (string (car _))) 53 (cadr _)]) 54 (list k v (* (len (string k)) v)) 55 ranking))) 56 counts) 57 ranking))) 58 59;(top40 (space-eaters allfiles*)) 60 61(mac flatlen args `(len (flat ',args)))