Last active
June 3, 2020 16:19
-
-
Save b4284/99df42d9dd99c5306aa44266cae83925 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(import (ice-9 regex) | |
(ice-9 rdelim)) | |
(define (grep ps . fns) | |
(define re (make-regexp ps)) | |
(define (grep-int p r) | |
(let ((l (read-line p))) | |
(if (not (eof-object? l)) | |
(begin | |
(if (regexp-match? (regexp-exec r l)) | |
(begin | |
(display l) | |
(newline))) | |
(grep-int p r))))) | |
(if (null? fns) | |
(grep-int (current-input-port) re) | |
(for-each | |
(lambda (fn) | |
(call-with-input-file fn | |
(lambda (p) (grep-int p re)))) | |
fns))) | |
(define (main args) | |
(apply grep (cdr args))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment