summaryrefslogtreecommitdiff
path: root/bs
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2022-07-23 22:24:34 -0400
committerBen Sima <ben@bsima.me>2022-07-23 22:31:34 -0400
commitf91d101dffb51c8eb207914833d1a5241149ae7b (patch)
treee0d8e3a036e377a93e84dc2a35c9994a511f3ca6 /bs
parent19dd1eef9d279aa468d4e179abad375d7271dc2a (diff)
Move comments to docstrings
Just spent an hour implementing my own doc system, just to find out this is built in to guile :(
Diffstat (limited to 'bs')
-rw-r--r--bs/re.scm23
-rw-r--r--bs/string.scm10
2 files changed, 16 insertions, 17 deletions
diff --git a/bs/re.scm b/bs/re.scm
index 926aae7..ec5b2ba 100644
--- a/bs/re.scm
+++ b/bs/re.scm
@@ -27,30 +27,29 @@
;; (define M regexp/newline)
;; (define MULTILINE regexp/newline)
- ;; Compile `pattern` into a regular expression object.
(define (compile pattern . flags)
+ "Compile `pattern` into a regular expression object."
(apply make-regexp (cons pattern flags)))
- ;; If zero or more characters at the beginning of `string` match the
- ;; regular expression `pattern`, return a corresponding match object.
+
(define (match string pattern)
+ "If zero or more characters at the beginning of `string` match the regular
+expression `pattern`, return a corresponding match object."
(regexp-exec pattern string))
- ;;
(define (group match-obj n)
(if match-obj
(match:substring match-obj n)
#f))
- ;; Return the string obtained by replacing the leftmost
- ;; non-overlapping occurrences of `pattern` in `string` by the
- ;; replacement `repl`. If the pattern isn’t found, string is returned
- ;; unchanged.
(define (sub string pattern repl)
+ "Return the string obtained by replacing the leftmost non-overlapping
+occurrences of `pattern` in `string` by the replacement `repl`. If the pattern
+isn’t found, string is returned unchanged."
(regexp-replace pattern string repl))
- ;; Scan through `string` looking for the first location where the
- ;; regular expression `pattern` produces a match, and return a
- ;; corresponding match object. Returns `#f` if no match is found.
(define (search string pattern)
- (regexp-exec pattern string)))
+ "Scan through `string` looking for the first location where the regular
+expression `pattern` produces a match, and return a corresponding match
+object. Returns `#f` if no match is found."
+ (string-match pattern string)))
diff --git a/bs/string.scm b/bs/string.scm
index 8839512..9fe794e 100644
--- a/bs/string.scm
+++ b/bs/string.scm
@@ -17,29 +17,29 @@
;; TODO: remove or port ice-9 dependency
(only (ice-9 ports) with-output-to-string))
- ;; Is `pre` a prefix of `s`?
(define (prefix? s pre)
+ "Is PRE a prefix of S?"
(string-prefix? pre s))
- ;; Is `suf` a suffix of `s`?
(define (suffix? s suf)
+ "Is SUF a suffix of S?"
(string-suffix? suf s))
- ;; Split `s` at `sep`
(define (split s 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)))))
- ;; Replace `match` in `s` with `char`
(define (replace-char s match 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)))
- ;; Replace `match` in `s` with `repl`
(define (replace s match 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.