aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--README.md25
-rw-r--r--examples.lisp13
2 files changed, 36 insertions, 2 deletions
diff --git a/README.md b/README.md
index 377a5ac..87767c4 100644
--- a/README.md
+++ b/README.md
@@ -64,7 +64,30 @@ apears at the end of the document, following the tutorial.
> (car (pick-out '(40) (fibs))) ;; 267914296
```
-
+
+### A Kind Of Grep
+
+``` lisp
+
+
+> (defmacro a-kind-of-grep (match-var key file &rest body)
+ `(for ,match-var (filter! (lambda (line) (search ,key line))
+ (file-lines ,file))
+ ,@body))
+
+;; look for export lines in my .bashrc
+
+> (let ((count 0))
+ (a-kind-of-grep line "export" "~/.bashrc"
+ (incf count)
+ (print line)))
+
+"export PATH=$HOME/.roswell/bin:$PATH"
+"export PATH=$HOME/.local/bin:$PATH"
+2
+
+```
+
## Tutorial
GTWIWTG is a tiny library for creating and using generators.
diff --git a/examples.lisp b/examples.lisp
index 83ba5c8..6d2f570 100644
--- a/examples.lisp
+++ b/examples.lisp
@@ -3,7 +3,8 @@
(:export
#:perms
#:all-primes
- #:fibs))
+ #:fibs
+ #:a-kind-of-grep))
(in-package :gtwiwtg.examples)
@@ -109,3 +110,13 @@ vector VEC, one at a time."
;; subperms))))
;;
;; which looks a little nicer but is less kind to the heap and to GC.
+
+;;; A kind of Grep ;;;
+
+(defmacro a-kind-of-grep (match-var key file &rest body)
+ `(for ,match-var (filter! (lambda (line) (search ,key line))
+ (file-lines ,file))
+ ,@body))
+
+
+;; find all export expressions in my bashrc file