aboutsummaryrefslogtreecommitdiffstats
path: root/lib/csc/strings.csc
diff options
context:
space:
mode:
authorRose Hogenson <rhogenson@posteo.net>2023-05-01 07:56:42 -0700
committerRose Hogenson <rhogenson@posteo.net>2023-05-01 07:56:42 -0700
commita89d6c82e981fec7d6e4c975e083d2b9e04467ad (patch)
treed5445ceb797473dd45ac006c337d990e5dd6f0d4 /lib/csc/strings.csc
parent112ce5291da35e54c38c4ff1d7a2408a64a98e71 (diff)
downloadchromatopelma-a89d6c82e981fec7d6e4c975e083d2b9e04467ad.tar.zst
Rewrite most of the compiler.
This represents a major step back in terms of functionality, and amount of code. The latter I think constitutes a major win. Next steps are to reimplement syntax-rules, call/cc, and call-with-values.
Diffstat (limited to 'lib/csc/strings.csc')
-rw-r--r--lib/csc/strings.csc72
1 files changed, 0 insertions, 72 deletions
diff --git a/lib/csc/strings.csc b/lib/csc/strings.csc
deleted file mode 100644
index 373f9be..0000000
--- a/lib/csc/strings.csc
+++ /dev/null
@@ -1,72 +0,0 @@
-(define-library (csc strings)
- (export
- contains?
- has-prefix?
- index
- join
- last-index
- split
- str-quote)
- (import (scheme base)
- (only (scheme case-lambda) case-lambda)
- (only (scheme write) write)
- (only (csc list) intercalate)
- (only (csc loop)
- loop
- return))
- (begin
-
-
- (define (has-prefix? str prefix)
- (and (<= (string-length prefix) (string-length str))
- (string=? prefix (substring str 0 (string-length prefix)))))
-
-
- (define (str-quote s)
- (let ((out (open-output-string)))
- (write s out)
- (get-output-string out)))
-
-
- (define (index s substr)
- (loop for i from 0
- for s = s then (string-copy s 1)
- until (string=? "" s)
- if (has-prefix? s substr)
- return i
- finally (return -1)))
-
-
- (define (last-index s substr)
- (loop for i downfrom (- (string-length s) (string-length substr)) to 0
- if (has-prefix? (string-copy s i) substr)
- return i
- finally (return -1)))
-
-
- (define (contains? s substr)
- (if (string=? "" substr)
- #t
- (not (negative? (index s substr)))))
-
-
- (define (join sep strings)
- (apply string-append (intercalate sep strings)))
-
-
- (define split
- (case-lambda
- ((s sep n)
- (if (= 0 n)
- '()
- (loop for n = n then (- n 1)
- for s = s then (string-copy s (+ i (string-length sep)))
- for i = (let ((i (index s sep)))
- (if (or (negative? i)
- (= 1 n))
- (string-length s)
- i))
- collect (substring s 0 i)
- while (< i (string-length s)))))
- ((s sep)
- (split s sep -1))))))