summaryrefslogtreecommitdiff
path: root/bs
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2022-11-29 13:50:41 -0500
committerBen Sima <ben@bsima.me>2022-11-29 13:50:41 -0500
commit28b99fa065b2b20c24a51c1f73d501191afbd1a7 (patch)
tree03a33555b875761fc62671d8b39d43e0062e2253 /bs
parent5db3bb98b3dae955049f76d67f59b95c41f91cd8 (diff)
Trivial scheme cleanups
Diffstat (limited to 'bs')
-rw-r--r--bs/re.scm4
-rw-r--r--bs/string.scm45
2 files changed, 27 insertions, 22 deletions
diff --git a/bs/re.scm b/bs/re.scm
index ec5b2ba..46cfa9e 100644
--- a/bs/re.scm
+++ b/bs/re.scm
@@ -1,4 +1,4 @@
-(library (bs re (0))
+(library (bs re)
;; Similar to Python's `re` module. One big difference is that the
;; string object to be searched is always the first argument to a
@@ -16,6 +16,7 @@
;; TODO: make `match` and `search` do different things
(export match group sub search compile
+ EXTENDED
;; I IGNORECASE M MULTILINE
)
(import (rnrs base)
@@ -26,6 +27,7 @@
;; (define IGNORECASE regexp/icase)
;; (define M regexp/newline)
;; (define MULTILINE regexp/newline)
+ (define EXTENDED 'regexp/extended)
(define (compile pattern . flags)
"Compile `pattern` into a regular expression object."
diff --git a/bs/string.scm b/bs/string.scm
index 58f86a0..b1ad256 100644
--- a/bs/string.scm
+++ b/bs/string.scm
@@ -1,45 +1,45 @@
-(library (bs string (0))
+(library (bs string)
(export
replace replace-char to-string str capitalize split
- strip lstrip rstrip prefix? suffix?)
+ strip lstrip rstrip prefix? suffix? drop)
(import
- (rnrs base)
- (only (rnrs control) case-lambda)
- (only (rnrs io simple) display)
- (only (srfi srfi-13)
- string-trim string-trim-both string-trim-right
- string-prefix? string-suffix? string-upcase string-concatenate
- string-drop string-take string-contains substring/shared string-null? string-fold
- string-tokenize)
- (only (srfi srfi-14)
- string->char-set char-set-complement char-set)
- (only (srfi srfi-28) format)
- ;; TODO: port ice-9 dependency or replace with (scheme something)
- (only (ice-9 ports) with-output-to-string))
+ (rnrs base)
+ (only (rnrs control) case-lambda)
+ (only (rnrs io simple) display)
+ (only (srfi srfi-13)
+ string-trim string-trim-both string-trim-right
+ string-prefix? string-suffix? string-upcase string-concatenate
+ string-drop string-take string-contains substring/shared string-null? string-fold
+ string-tokenize)
+ (only (srfi srfi-14)
+ string->char-set char-set-complement char-set)
+ (only (srfi srfi-28) format)
+ ;; TODO: port ice-9 dependency or replace with (scheme something)
+ (only (ice-9 ports) with-output-to-string))
(define (prefix? s pre)
- "Is PRE a prefix of S?"
+ #;"Is PRE a prefix of S?"
(string-prefix? pre s))
(define (suffix? s suf)
- "Is SUF a suffix of S?"
+ #;"Is SUF a suffix of S?"
(string-suffix? suf s))
(define (split s sep)
- "Split S at SEP"
+ #;"Split S at SEP"
;; this is still wrong. it splits on any of the "sep" characters
;; instead of all of them
(string-tokenize s (char-set-complement (apply char-set (string->list sep)))))
(define (replace-char s match char)
- "Replace MATCH in S with CHAR"
+ #;"Replace MATCH in S with CHAR"
(let ((f (lambda (a b)
(let ((next-char (if (eq? a match) char a)))
(string-concatenate (list b (string next-char)))))))
(string-fold f "" s)))
(define (replace s match repl)
- "Replace MATCH in S with REPL"
+ #;"Replace MATCH in S with REPL"
;; based on string-replace-substring By A. Wingo in
;; https://lists.gnu.org/archive/html/guile-devel/2014-03/msg00058.html
;; also in string-replace-substring guix:guix/utils.scm.
@@ -79,4 +79,7 @@
(string-trim s char))
(define (rstrip s char)
- (string-trim-right s char )))
+ (string-trim-right s char))
+
+ (define (drop s num)
+ (string-drop s num)))