Skip to content

Instantly share code, notes, and snippets.

@b4284
Last active June 3, 2020 16:19
Show Gist options
  • Save b4284/99df42d9dd99c5306aa44266cae83925 to your computer and use it in GitHub Desktop.
Save b4284/99df42d9dd99c5306aa44266cae83925 to your computer and use it in GitHub Desktop.
(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