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