aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--README.md31
-rw-r--r--examples.lisp7
2 files changed, 19 insertions, 19 deletions
diff --git a/README.md b/README.md
index 7cc05c9..46d7787 100644
--- a/README.md
+++ b/README.md
@@ -69,22 +69,23 @@ apears at the end of the document, following the tutorial.
``` lisp
+> (defun grepper (pattern file)
+ (filter! (lambda (idx-line) (search pattern (second idx-line)))
+ (zip! (range) (file-lines file))))
-> (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
+
+> (for (idx line) (grepper "defun" "/home/colony/projects/gtwiwtg/examples.lisp")
+ (format t "~4a: ~a~%" idx line))
+
+
+12 : (defun prime-p (n)
+19 : (defun all-primes ()
+37 : (defun fibs ()
+52 : (defun fill-and-insert (idx elem vec buffer)
+69 : (defun thread-through (elem vec)
+86 : (defun perms (vec)
+104 : ;; (defun perms (vec)
+115 : (defun grepper (pattern file)
```
diff --git a/examples.lisp b/examples.lisp
index 6d2f570..221c78e 100644
--- a/examples.lisp
+++ b/examples.lisp
@@ -113,10 +113,9 @@ vector VEC, one at a time."
;;; 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))
+(defun grepper (pattern file)
+ (filter! (lambda (idx-line) (search pattern (second idx-line)))
+ (zip! (range) (file-lines file))))
;; find all export expressions in my bashrc file