-
Notifications
You must be signed in to change notification settings - Fork 0
/
word-uppercase.scm
69 lines (62 loc) · 2.45 KB
/
word-uppercase.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
;;================================================================================;;
;;Developer: Roberto Cella ;;
;;Contact me via mail: rob.uniud@gmail.com ;;
;;Follow me on Twitter: www.twitter.com/rob93c ;;
;;================================================================================;;
(define word-uppercase ; val: string
(lambda (word) ; word: string
(cond ((blank? word)
"")
((lowercase? (first-letter word))
(string-append
(string (lowercase->uppercase (first-letter word)))
(word-uppercase (tail word))))
((char=? (string-ref word 0) #\space)
(string-append
" "
(word-uppercase (tail word))))
(else ; if uppercase
(string-append
(string (first-letter word))
(word-uppercase (tail word))
))
)
)
)
(define first-letter ; val: char
(lambda (word) ; word: string
(string-ref word 0)
)
)
(define tail ; val: string
(lambda (word) ; word: string
(substring word 1 (string-length word))
)
)
(define blank? ; val: boolean
(lambda (word) ; word: string
(cond ((= (string-length word) 0)
true)
(else false))
)
)
(define uppercase ; val: char
(lambda (lett) ; lett: char
(integer->char (- (char->integer lett) 32))
)
)
(define lowercase->uppercase ; val: char
(lambda (lett) ; lett: char
(if (lowercase? lett)
(uppercase lett)
(string lett)
)
)
)
(define lowercase? ; val: boolean
(lambda (lett) ; lett: char
(if (>= (char->integer lett) 97)
true
false)
)
)