Reference Additions/Corrections
char-alphabetic? char
Returns #t if the character char is in the range #\A to #\Z or #\a to #\z.
make-string k
Returns a new string with a length of k.
Examples:
1:=> (make-string 3)
; returns an empty string
1:=> (string-length (make-string 5))
5
1:=> (string-length (string-append "hello" (make-string 5)))
10
make-string k char
Returns a new string with a length of k filled with the character char.
Examples:
1:=> (make-string 3 #\a)
aaa
1:=> (string-append "hello" (make-string 5 #\space) "world")
hello world
string char
Returns a new string with a length of 1 filled with the character char.
This is equivalent to (make-string 1 char)
Examples:
1:=> (string #\b)
b
1:=> (string=? (string #\b) (make-string 1 #\b))
#t
string-ref string k
Returns the character located at index k in the string.
Examples:
1:=> (string-ref "hello" 0)
h
1:=> (string-ref "hello" 1)
e
1:=> (string? (string-ref "hello" 1))
#f
1:=> (char? (string-ref "hello" 1))
#t
string-set! string k char
Sets the character located at index k in the string to char. Returns #unspecified. This function destructively alters a string.
Examples:
; (define s "hello")
1:=> (string-set! s 1 #\a)
#unspecified
1:=> s
hallo
1:=> (string-set! s 0 #\')
#unspecified
1:=> s
'allo
A non-destructive version:
(define (string-set-a s k c)
(string-append (substring s 0 k)
(string c)
(substring s (+ k 1) (string-length s))))
Another non-destructive version:
(define (string-set-b s k c)
(let ((new-s (string-copy)))
(string-set! new-s k c)
new-s))
sqlite-map sqlite procedure string arg ...
This function can be used to convert returned SQL rows to lists or vectors.
The procedure is applied to each row of the SQL rows returned.
Examples:
Let's say we have a database full of people and for each person, a name and an age is stored. With sqlite-map
we can run a lambda that prints out a sentence stating the name and age of the person.
(sqlite-map *my-database*
(lambda (name age)
(print "My name is " name " and I am " age " years old."))
"SELECT name, age FROM people;")
Now let's say that our table, people, has another column added. Now each and every person has an address column. The previous example will still work because sqlite-map will drop the unused variables when calling the procedure. In the next example, we'll print out all three column values:
(sqlite-map *my-database*
(lambda (name age address)
(print "My name is " name ", I am " age
" years old, and I live at " address "."))
"SELECT name, age, address FROM people;")
Comments (0)
You don't have permission to comment on this page.