Sha256: ca6c73cc9c055379a218b9c9c68bcb7821502095bbc5f7c9e1e2a082e1169ded
Contents?: true
Size: 966 Bytes
Versions: 180
Compression:
Stored size: 966 Bytes
Contents
#lang racket (provide grep-file) (define (grep-file f pattern) (with-input-from-file f (lambda () (for/list ([line (in-lines)] ;; Iterate over lines in file, lazily [line-number (in-naturals 1)] ;; Iterate over natural numbers, lazily #:when (regexp-match? pattern line)) (cons line-number line))))) ;; ============================================================================= ;; Code inside the "main" module is run in Dr.Racket or on the command-line, ;; but not when the file is included as a library. (module+ main (require racket/cmdline) (command-line #:program "racket-grep" #:args (pat-str . file*) (begin (define pattern (regexp pat-str)) (for ([f (in-list file*)]) (for ([num+str (in-list (grep-file f pattern))]) (printf "~a\n~a\n" f (make-string (string-length f) #\-)) (printf "~a : ~a\n" (car num+str) (cdr num+str)) (newline))))))
Version data entries
180 entries across 180 versions & 1 rubygems