/code.arc

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