From d909520e1068ca4837187f91a8c475c31f937758 Mon Sep 17 00:00:00 2001 From: Joseph Nuthalapati Date: Sat, 9 Feb 2019 00:30:35 +0530 Subject: [PATCH] tag_find: Racket implementation (non-recursive) Signed-off-by: Joseph Nuthalapati --- tag_find/README.md | 1 + tag_find/tag-find.rkt | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 tag_find/tag-find.rkt diff --git a/tag_find/README.md b/tag_find/README.md index b6edcee..36f45b4 100644 --- a/tag_find/README.md +++ b/tag_find/README.md @@ -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 index 0000000..faf6662 --- /dev/null +++ b/tag_find/tag-find.rkt @@ -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) -- 2.43.0