added scheme/string, include it in the scheme language, put string-append* in there, tested, documented
svn: r9356
This commit is contained in:
parent
7b682783db
commit
0b7bdfe92c
|
@ -10,6 +10,7 @@
|
||||||
scheme/tcp
|
scheme/tcp
|
||||||
scheme/udp
|
scheme/udp
|
||||||
scheme/list
|
scheme/list
|
||||||
|
scheme/string
|
||||||
scheme/function
|
scheme/function
|
||||||
scheme/path
|
scheme/path
|
||||||
scheme/file
|
scheme/file
|
||||||
|
@ -32,6 +33,7 @@
|
||||||
scheme/tcp
|
scheme/tcp
|
||||||
scheme/udp
|
scheme/udp
|
||||||
scheme/list
|
scheme/list
|
||||||
|
scheme/string
|
||||||
scheme/function
|
scheme/function
|
||||||
scheme/path
|
scheme/path
|
||||||
scheme/file
|
scheme/file
|
||||||
|
|
7
collects/scheme/string.ss
Normal file
7
collects/scheme/string.ss
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
#lang scheme/base
|
||||||
|
|
||||||
|
(provide string-append*)
|
||||||
|
|
||||||
|
(define string-append*
|
||||||
|
(case-lambda [(strs) (apply string-append strs)] ; optimize common case
|
||||||
|
[(str . strss) (apply string-append (apply list* str strss))]))
|
|
@ -529,6 +529,7 @@ must merely start with a chain of at least @scheme[pos] pairs.
|
||||||
|
|
||||||
@defproc*[([(append* [lst list?] ... [lsts (listof list?)]) list?]
|
@defproc*[([(append* [lst list?] ... [lsts (listof list?)]) list?]
|
||||||
[(append* [lst list?] ... [lsts list?]) any/c])]{
|
[(append* [lst list?] ... [lsts list?]) any/c])]{
|
||||||
|
@; Note: this is exactly the same description as the one for string-append*
|
||||||
|
|
||||||
Like @scheme[append], but the last argument is used as a list of
|
Like @scheme[append], but the last argument is used as a list of
|
||||||
arguments for @scheme[append], so @scheme[(append* x ... xs)] is the
|
arguments for @scheme[append], so @scheme[(append* x ... xs)] is the
|
||||||
|
|
|
@ -359,3 +359,24 @@ allocated string).}
|
||||||
@scheme[string-downcase], but using locale-specific case-conversion
|
@scheme[string-downcase], but using locale-specific case-conversion
|
||||||
rules based the value of @scheme[current-locale].
|
rules based the value of @scheme[current-locale].
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@; ----------------------------------------
|
||||||
|
@section{Additional String Functions}
|
||||||
|
|
||||||
|
@note-lib[scheme/string]
|
||||||
|
@(define string-eval (make-base-eval))
|
||||||
|
@interaction-eval[#:eval string-eval (require scheme/string)]
|
||||||
|
|
||||||
|
@defproc[(string-append* [str string?] ... [strs (listof string?)]) string?]{
|
||||||
|
@; Note: this is exactly the same description as the one for append*
|
||||||
|
|
||||||
|
Like @scheme[string-append], but the last argument is used as a list of
|
||||||
|
arguments for @scheme[string-append], so @scheme[(string-append* x ... xs)] is the
|
||||||
|
same as @scheme[(apply string-append x ... xs)]. In other words, the
|
||||||
|
relationship between @scheme[string-append] and @scheme[string-append*] is similar
|
||||||
|
to the one between @scheme[list] and @scheme[list*].
|
||||||
|
|
||||||
|
@examples[#:eval string-eval
|
||||||
|
(string-append* (cdr (append* (map (lambda (x) (list ", " x))
|
||||||
|
'("Alpha" "Beta" "Gamma")))))
|
||||||
|
]}
|
||||||
|
|
|
@ -172,6 +172,14 @@
|
||||||
|
|
||||||
;; ---------- append* ----------
|
;; ---------- append* ----------
|
||||||
(let ()
|
(let ()
|
||||||
|
(test '() append* '())
|
||||||
|
(test '() append* '(()))
|
||||||
|
(test '() append* '(() ()))
|
||||||
|
(test '(0 1 2 3) append* '((0 1 2 3)))
|
||||||
|
(test '(0 1 2 3) append* '(0 1 2 3) '())
|
||||||
|
(test '(0 1 2 3) append* '(0 1 2 3) '(()))
|
||||||
|
(test '(0 1 2 3) append* '(0 1 2 3) '(() ()))
|
||||||
|
(test '(0 1 2 3) append* '(0 1) '((2) (3)))
|
||||||
(test '(0 1 0 2 0 3) append* (map (lambda (x) (list 0 x)) '(1 2 3)))
|
(test '(0 1 0 2 0 3) append* (map (lambda (x) (list 0 x)) '(1 2 3)))
|
||||||
(test '(1 2 3 4 5 6 7 8 9) append* '(1 2 3) '(4 5) '((6 7 8) (9))))
|
(test '(1 2 3 4 5 6 7 8 9) append* '(1 2 3) '(4 5) '((6 7 8) (9))))
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,9 @@
|
||||||
|
|
||||||
(Section 'string)
|
(Section 'string)
|
||||||
|
|
||||||
;; to add when this library is there: (require scheme/string)
|
(require scheme/string)
|
||||||
|
|
||||||
|
;; ---------- real->decimal-string ----------
|
||||||
(test "0." real->decimal-string 0 0)
|
(test "0." real->decimal-string 0 0)
|
||||||
(test "0." real->decimal-string 0.0 0)
|
(test "0." real->decimal-string 0.0 0)
|
||||||
(test "1." real->decimal-string 0.6 0)
|
(test "1." real->decimal-string 0.6 0)
|
||||||
|
@ -19,8 +20,10 @@
|
||||||
(test "-1.20" real->decimal-string -1.2)
|
(test "-1.20" real->decimal-string -1.2)
|
||||||
(test "1.00" real->decimal-string 0.99999999999)
|
(test "1.00" real->decimal-string 0.99999999999)
|
||||||
(test "-1.00" real->decimal-string -0.99999999999)
|
(test "-1.00" real->decimal-string -0.99999999999)
|
||||||
(test "1999999999999999859514578049071102439861518336.00" real->decimal-string 2e45)
|
(test "1999999999999999859514578049071102439861518336.00"
|
||||||
|
real->decimal-string 2e45)
|
||||||
|
|
||||||
|
;; ---------- regexp-quote ----------
|
||||||
(let ([s (list->string
|
(let ([s (list->string
|
||||||
(let loop ([i 0])
|
(let loop ([i 0])
|
||||||
(if (= i 256)
|
(if (= i 256)
|
||||||
|
@ -31,6 +34,7 @@
|
||||||
regexp-replace
|
regexp-replace
|
||||||
(regexp-quote s) s (regexp-replace-quote (string-append "!" s "!"))))
|
(regexp-quote s) s (regexp-replace-quote (string-append "!" s "!"))))
|
||||||
|
|
||||||
|
;; ---------- regexp-match* ----------
|
||||||
(test '("a" "b" "c") regexp-match* "[abc]" "here's a buck")
|
(test '("a" "b" "c") regexp-match* "[abc]" "here's a buck")
|
||||||
(test '("b" "c") regexp-match* "[abc]" "here's a buck" 8)
|
(test '("b" "c") regexp-match* "[abc]" "here's a buck" 8)
|
||||||
(test '("a") regexp-match* "[abc]" "here's a buck" 0 8)
|
(test '("a") regexp-match* "[abc]" "here's a buck" 0 8)
|
||||||
|
@ -56,6 +60,7 @@
|
||||||
(test '(#"a" #"b" #"c") regexp-match* "[abc]" s 0 #f)
|
(test '(#"a" #"b" #"c") regexp-match* "[abc]" s 0 #f)
|
||||||
(test eof read-char s))
|
(test eof read-char s))
|
||||||
|
|
||||||
|
;; ---------- regexp-match-positions* ----------
|
||||||
(test '((7 . 8) (9 . 10) (11 . 12))
|
(test '((7 . 8) (9 . 10) (11 . 12))
|
||||||
regexp-match-positions* "[abc]" "here's a buck")
|
regexp-match-positions* "[abc]" "here's a buck")
|
||||||
(test '((9 . 10) (11 . 12))
|
(test '((9 . 10) (11 . 12))
|
||||||
|
@ -76,6 +81,7 @@
|
||||||
(test '((7 . 8) (9 . 10) (11 . 12)) regexp-match-positions* "[abc]" s 0 #f)
|
(test '((7 . 8) (9 . 10) (11 . 12)) regexp-match-positions* "[abc]" s 0 #f)
|
||||||
(test eof read-char s))
|
(test eof read-char s))
|
||||||
|
|
||||||
|
;; ---------- regexp-match-peek-positions* ----------
|
||||||
(let ([s (open-input-string "here's a buck")])
|
(let ([s (open-input-string "here's a buck")])
|
||||||
(test '((7 . 8) (9 . 10) (11 . 12))
|
(test '((7 . 8) (9 . 10) (11 . 12))
|
||||||
regexp-match-peek-positions*
|
regexp-match-peek-positions*
|
||||||
|
@ -90,6 +96,7 @@
|
||||||
(test "here's a buck"
|
(test "here's a buck"
|
||||||
read-string 50 s))
|
read-string 50 s))
|
||||||
|
|
||||||
|
;; ---------- regexp-split ----------
|
||||||
(test '("here's " " " "u" "k") regexp-split "[abc]" "here's a buck")
|
(test '("here's " " " "u" "k") regexp-split "[abc]" "here's a buck")
|
||||||
(test '(" " "u" "k") regexp-split "[abc]" "here's a buck" 8)
|
(test '(" " "u" "k") regexp-split "[abc]" "here's a buck" 8)
|
||||||
(test '("" "u" "k") regexp-split "[abc]" "here's a buck" 9)
|
(test '("" "u" "k") regexp-split "[abc]" "here's a buck" 9)
|
||||||
|
@ -126,4 +133,15 @@
|
||||||
;; this doesn't work (like in Emacs) because ^ matches the start pos
|
;; this doesn't work (like in Emacs) because ^ matches the start pos
|
||||||
;; (test '("" "foo bar") regexp-split #rx"^" "foo bar")
|
;; (test '("" "foo bar") regexp-split #rx"^" "foo bar")
|
||||||
|
|
||||||
|
;; ---------- string-append* ----------
|
||||||
|
(let ()
|
||||||
|
(test "" string-append* '())
|
||||||
|
(test "" string-append* '(""))
|
||||||
|
(test "" string-append* '("" ""))
|
||||||
|
(test "0123456789" string-append* '("0123456789"))
|
||||||
|
(test "0123456789" string-append* "0123456789" '())
|
||||||
|
(test "0123456789" string-append* "0123456789" '(""))
|
||||||
|
(test "0123456789" string-append* "0123456789" '("" ""))
|
||||||
|
(test "0123456789" string-append* "01234567" '("8" "9")))
|
||||||
|
|
||||||
(report-errs)
|
(report-errs)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user