vegashacker / leftparen

An easy way to make web apps (in PLT Scheme)

This URL has Read+Write access

leftparen / loc.scm
100644 23 lines (17 sloc) 0.679 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
;; how much code have you written?
#lang scheme/base
 
(require "util.scm")
 
(provide loc)
 
;; counts all lines except for comment lines and blank lines
(define (loc #:comment-chars (comment-chars (list #\;)) . filenames)
  (fold + 0
        (map (lambda (filename)
               (file-line-fold
                (lambda (line-str total-loc)
                  (let ((trimmed (string-trim-both line-str #\space)))
                    (cond ((string=? trimmed "") total-loc)
                          ((memq (string-ref trimmed 0) comment-chars) total-loc)
                          (else (+ 1 total-loc)))))
                0
                filename))
             filenames)))