Function frequency: Difference between revisions
Content added Content deleted
(Created draft task) |
(Added PicoLisp) |
||
Line 4: | Line 4: | ||
This is a static analysis: The question is not how often each function is |
This is a static analysis: The question is not how often each function is |
||
actually executed at runtime, but how often it is used by the programmer. |
actually executed at runtime, but how often it is used by the programmer. |
||
=={{header|PicoLisp}}== |
|||
<lang PicoLisp>(let Freq NIL |
|||
(for "L" (filter pair (extract getd (all))) |
|||
(for "F" |
|||
(filter atom |
|||
(fish '((X) (or (circ? X) (getd X))) |
|||
"L" ) ) |
|||
(accu 'Freq "F" 1) ) ) |
|||
(for X (head 10 (flip (by cdr sort Freq))) |
|||
(tab (-7 4) (car X) (cdr X)) ) )</lang> |
|||
Output: |
|||
<pre>quote 310 |
|||
car 236 |
|||
cdr 181 |
|||
setq 148 |
|||
let 136 |
|||
if 127 |
|||
and 124 |
|||
cons 110 |
|||
cadr 80 |
|||
or 76</pre> |
Revision as of 07:36, 2 November 2011
Function frequency is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
Display - for a program or runtime environment (whatever suites the style of your language) - the top ten most frequently occurring functions.
This is a static analysis: The question is not how often each function is actually executed at runtime, but how often it is used by the programmer.
PicoLisp
<lang PicoLisp>(let Freq NIL
(for "L" (filter pair (extract getd (all))) (for "F" (filter atom (fish '((X) (or (circ? X) (getd X))) "L" ) ) (accu 'Freq "F" 1) ) ) (for X (head 10 (flip (by cdr sort Freq))) (tab (-7 4) (car X) (cdr X)) ) )</lang>
Output:
quote 310 car 236 cdr 181 setq 148 let 136 if 127 and 124 cons 110 cadr 80 or 76