diff options
-rw-r--r-- | ps01_grep/ps01_bnewbold.txt | 18 | ||||
-rw-r--r-- | ps01_grep/ps01_work.scm | 45 |
2 files changed, 55 insertions, 8 deletions
diff --git a/ps01_grep/ps01_bnewbold.txt b/ps01_grep/ps01_bnewbold.txt index 52979e7..8968157 100644 --- a/ps01_grep/ps01_bnewbold.txt +++ b/ps01_grep/ps01_bnewbold.txt @@ -174,7 +174,7 @@ c) (not, uh, fully tested...) (let ((choose-grep (lambda (x) (cond ((string? x) x) - ((list? x) (car x)))))) + ((list? x) ((car x))))))) (apply string-append (map choose-grep exprs)))) (r-grep:seq "a" "b" '("grep" "egrep")) @@ -184,7 +184,7 @@ c) (not, uh, fully tested...) (let ((choose-egrep (lambda (x) (cond ((string? x) x) - ((list? x) (cadr x)))))) + ((list? x) ((cadr x))))))) (apply string-append (map choose-egrep exprs)))) #| test: @@ -340,6 +340,20 @@ c) (not, uh, fully tested...) (r:grep-like "grep" '("-E") ((cadr expr)) filename) (r:grep-like "egrep" '() ((cadr expr)) filename))) +#| final tests: +(r:seq (r:repeat 2 3 (r:quote "cat")) (r:+ (r:quote "dog"))) +;Value: (#[compound-procedure 18] #[compound-procedure 19]) +((car (r:seq (r:repeat 2 3 (r:quote "cat")) (r:+ (r:quote "dog"))))) +;Value: "\\(cat\\)\\{2,3\\}\\(dog\\)\\{1,\\}" +((cadr (r:seq (r:repeat 2 3 (r:quote "cat")) (r:+ (r:quote "dog"))))) +;Value: "(cat){2,3}(dog){1,}" + (pp (r:grep (r:seq (r:repeat 2 3 (r:quote "cat")) (r:+ (r:quote "dog"))) "tests.txt")) +; ("[10]. catcatdogdog" "[12]. catcatcatdogdogdog") +(pp (r:egrep (r:seq (r:repeat 2 3 (r:quote "cat")) (r:+ (r:quote "dog"))) + "tests.txt")) +; ("[10]. catcatdogdog" "[12]. catcatcatdogdogdog") + +|# diff --git a/ps01_grep/ps01_work.scm b/ps01_grep/ps01_work.scm index 7338f20..a38cc9c 100644 --- a/ps01_grep/ps01_work.scm +++ b/ps01_grep/ps01_work.scm @@ -155,17 +155,14 @@ (let ((choose-grep (lambda (x) (cond ((string? x) x) - ((list? x) (car x)))))) + ((list? x) ((car x))))))) (apply string-append (map choose-grep exprs)))) -(r-grep:seq "a" "b" '("grep" "egrep")) -; abgrep - (define (r-egrep:seq . exprs) (let ((choose-egrep (lambda (x) (cond ((string? x) x) - ((list? x) (cadr x)))))) + ((list? x) ((cadr x))))))) (apply string-append (map choose-egrep exprs)))) #| test: @@ -284,6 +281,30 @@ (cons (lambda () (r-grep:repeat min max expr)) (cons (lambda () (r-egrep:repeat min max expr)) '()))) +#| tests: +(r-grep:repeat 1 3 "d") +;Value: "\\(d\\)\\{1,3\\}" +(r-egrep:repeat 1 3 "d") +;Value: "(d){1,3}" +((car (r:repeat 2 2 "asdf"))) +;Value: "\\(asdf\\)\\{2\\}" +((cadr (r:repeat 2 2 "asdf"))) +;Value: "(asdf){2}" + +((cadr (r:repeat 3 #f "asdf"))) +;Value: "(asdf){3,}" + +(r:+ "asdf") +;Value: (#[compound-procedure 21] #[compound-procedure 22]) +((car (r:+ "asdf"))) +;Value: "\\(asdf\\)\\{1,\\}" + +((car (r:+ (r:+ (r:quote "a"))))) +;Value: "\\(\\(a\\)\\{1,\\}\\)\\{1,\\}" + +((car (r:seq (r:quote "a")))) +|# + (define (r-grep:subexp . exprs) (string-append "\\(" (apply string-append (map (lambda (x) @@ -321,10 +342,22 @@ (r:grep-like "grep" '("-E") ((cadr expr)) filename) (r:grep-like "egrep" '() ((cadr expr)) filename))) +#| final tests: +(r:seq (r:repeat 2 3 (r:quote "cat")) (r:+ (r:quote "dog"))) +;Value: (#[compound-procedure 18] #[compound-procedure 19]) +((car (r:seq (r:repeat 2 3 (r:quote "cat")) (r:+ (r:quote "dog"))))) +;Value: "\\(cat\\)\\{2,3\\}\\(dog\\)\\{1,\\}" +((cadr (r:seq (r:repeat 2 3 (r:quote "cat")) (r:+ (r:quote "dog"))))) +;Value: "(cat){2,3}(dog){1,}" + (pp (r:grep (r:seq (r:repeat 2 3 (r:quote "cat")) (r:+ (r:quote "dog"))) "tests.txt")) +; ("[10]. catcatdogdog" "[12]. catcatcatdogdogdog") +(pp (r:egrep (r:seq (r:repeat 2 3 (r:quote "cat")) (r:+ (r:quote "dog"))) + "tests.txt")) +; ("[10]. catcatdogdog" "[12]. catcatcatdogdogdog") - +|# |