2.4.3 Strings
Some string functions can be found in the section on Sequences as well.
x : t |
This function will coerce a value to a list of characters.
Examples: |
> (make-character-list "hello") |
() |
x : (or (stringp x) (symbolp x) (characterp x)) |
Uses coerce to convert the input into a string.
Examples: |
> (string "abc") |
"abc" |
> (string 'abc) |
"ABC" |
> (string #\a) |
"a" |
> (string 123) |
() |
x : (stringp x) |
y : (stringp y) |
Concatenates two strings together.
Examples: |
> (string-append "ab" "cd") |
"abcd" |
> (string-append 'ab "cd") |
/Volumes/Maldis/Users/cce/plt/research/dracula/release/src/l |
anguage/primitive-procedures/acl2-prims-scheme.scm:38:28: |
Dracula program broke the contract (case-> (-> |
(symbols ’string ’list) any) (->* ((symbols ’string |
’list)) (or/c (listof string?) (listof |
(listof any/c))) any)) on here; expected <(or/c (listof |
string?) (listof (listof any/c)))>, given: (ab "cd") |
> (string-append 5 "ab") |
/Volumes/Maldis/Users/cce/plt/research/dracula/release/src/l |
anguage/primitive-procedures/acl2-prims-scheme.scm:38:28: |
Dracula program broke the contract (case-> (-> |
(symbols ’string ’list) any) (->* ((symbols ’string |
’list)) (or/c (listof string?) (listof |
(listof any/c))) any)) on here; expected <(or/c (listof |
string?) (listof (listof any/c)))>, given: (5 "ab") |
str : (and (stringp str) (standard-char-listp (coerce str 'list))) |
Converts the characters in str to lowercase.
Examples: |
> (string-downcase "ABCdef") |
"abcdef" |
> (string-downcase 'ABCdef) |
string-downcase: expects argument of type <string>; given |
ABCdef |
> (string-downcase 12345) |
string-downcase: expects argument of type <string>; given |
12345 |
x : (and (stringp x) (standard-char-listp (coerce x 'list))) |
y : (and (stringp y) (standard-char-listp (coerce y 'list))) |
Compares two strings to see if they are equal.
Examples: |
> (string-equal "ab" "cd") |
() |
> (string-equal "ab" "ab") |
t |
str : (and (stringp str) (standard-char-listp (coerce str 'list))) |
Converts the characters in str to uppercase.
Examples: |
> (string-upcase "ABCdef") |
"ABCDEF" |
> (string-upcase 'ABCdef) |
string-upcase: expects argument of type <string>; given |
ABCdef |
> (string-upcase 12345) |
string-upcase: expects argument of type <string>; given |
12345 |
x : (stringp x) |
y : (stringp y) |
Compares the two strings for lexicographical ordering. Returns non-nil if and only if x precedes y lexicographically. When non-nil, the number returned is the first position at which the strings differ.
Examples: |
> (string< "ab" "cd") |
0 |
> (string< "ab" "abc") |
2 |
> (string< 'symbol "string") |
/Volumes/Maldis/Users/cce/plt/research/dracula/release/src/l |
anguage/checking-proc.scm:36:21: Dracula program broke the |
contract (-> string? string? any) on here; expected |
<string?>, given: symbol |
x : (stringp x) |
y : (stringp y) |
Compares the two strings for lexicographical ordering. Returns non-nil if and only if x precedes y lexicographically. If they differ, the number returned is the first position at which the strings differ. Otherwise, the number returned is their common length.
Examples: |
> (string<= "ab" "cd") |
0 |
> (string<= "ab" "ab") |
2 |
> (string<= 'symbol "string") |
/Volumes/Maldis/Users/cce/plt/research/dracula/release/src/l |
anguage/checking-proc.scm:36:21: Dracula program broke the |
contract (-> string? string? any) on here; expected |
<string?>, given: symbol |
x : (stringp x) |
y : (stringp y) |
Compares the two strings for lexicographical ordering. Returns non-nil if and only if y precedes x lexicographically. When non-nil, the number returned is the first position at which the strings differ.
Examples: |
> (string> "ab" "cd") |
() |
> (string> "ab" "ab") |
() |
> (string> "ba" "ab") |
0 |
> (string> 'symbol "string") |
/Volumes/Maldis/Users/cce/plt/research/dracula/release/src/l |
anguage/checking-proc.scm:36:21: Dracula program broke the |
contract (-> string? string? any) on here; expected |
<string?>, given: symbol |
x : (stringp x) |
y : (stringp y) |
Compares the two strings for lexicographical ordering. Returns non-nil if and only if y precedes x lexicographically. If they differ, the number returned is the first position at which the strings differ. Otherwise, the number returned is their common length.
Examples: |
> (string>= "ab" "cd") |
() |
> (string>= "ab" "ab") |
2 |
> (string>= "ba" "ab") |
0 |
> (string>= 'symbol "string") |
/Volumes/Maldis/Users/cce/plt/research/dracula/release/src/l |
anguage/checking-proc.scm:36:21: Dracula program broke the |
contract (-> string? string? any) on here; expected |
<string?>, given: symbol |
x : t |
Determines whether x is a string.
Examples: |
> (stringp "abcd") |
t |
> (stringp nil) |
() |