tag_find: Racket implementation (non-recursive)
authorJoseph Nuthalapati <njoseph@thoughtworks.com>
Fri, 8 Feb 2019 19:00:35 +0000 (00:30 +0530)
committerJoseph Nuthalapati <njoseph@thoughtworks.com>
Fri, 8 Feb 2019 19:03:34 +0000 (00:33 +0530)
Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
tag_find/README.md
tag_find/tag-find.rkt [new file with mode: 0644]

index b6edcee2f398b9bb0955a2c0277250486dd79b13..36f45b4b53570c77e8d93d429ad6e8c3430578dc 100644 (file)
@@ -9,6 +9,7 @@ Languages used:
 * [Rust](https://rust-lang.org)
 * [Go](https://golang.org)
 * [Joker](https://joker-lang.org)
+* [Racket](https://racket-lang.org)
 
 ## Disclaimer
 The implementations are written with hardly 3 hours of experience with each language and will perform poorly. Use at your own risk if you want to.
diff --git a/tag_find/tag-find.rkt b/tag_find/tag-find.rkt
new file mode 100644 (file)
index 0000000..faf6662
--- /dev/null
@@ -0,0 +1,28 @@
+#lang racket
+
+(define tag "tag")
+
+(define start-sequence "#+")
+
+(define tag-match? ( lambda (line)
+  (and (string-prefix? line start-sequence)
+       (string-contains? line tag))))
+
+;; TODO Make recursive
+(define files
+ (filter file-exists? (directory-list)))
+
+(define (find-file files)
+  (when (not (empty? files))
+    (define file (first files))
+    (define (find-line lines)
+      (when (not (empty? lines))
+        (if (tag-match? (first lines))
+            (displayln file)
+            (find-line (rest lines)))
+        ))
+    (find-line (file->lines file))
+    (find-file (rest files))
+  ))
+
+(find-file files)