Computer Science Fundamentals (CS153 2004S)
[Skip to Body]
Primary:
[Front Door]
[Current]
[Glance]
-
[Honesty]
[Instructions]
[Links]
[Search]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Readings]
[Reference]
Misc:
[Experiments in Java]
[Java API]
[Scheme Reference]
[Scheme Report]
[CS153 2003S]
[CS151 2003F]
[CS152 2000F]
[SamR]
Summary: In these exercises, you will explore a number of the s tandard Scheme procedures for handling characters and strings. You will also ex plore an application of these procedures for marking up text.
Contents:
Related Pages:
Useful Procedures and Notation:
#\ch
(character constants)
"string"
(string constants).
#\a
(lowercase a) ... #\z
(lowercase z);
#\A
(uppercase A) ... #\Z
(uppercase Z);
#\0
(zero) ... #\9
(nine);
#\space
(space);
#\newline
(newline);
and
#\?
(question mark).
char->integer
,
integer->char
,
char-downcase
, and
char-upcase
char?
,
char-alphabetic?
,
char-numeric?
,
char-lower-case?
,
char-upper-case?
,
char-whitespace?
string?
make-string
,
string
,
string-append
string-ref
,
substring
list->string
,
number->string
,
string->list
string-length
,
string<?
,
string<=?
,
string=?
,
string>=?
,
string>?
,
string-ci<?
,
string-ci<=?
,
string-ci=?
,
string-ci>=?
,
string-ci>?
Start DrScheme.
As you may recall, Scheme uses a collating sequence for the letters, assigning a sequence number to each letter. DrScheme uses the ASCII collating sequence.
a. Determine the ASCII collating-sequence numbers for the capital letter A and for the lower-case letter a.
b. Find out what ASCII character is in position 38 in the collating sequence.
c. Do the digit characters precede or follow the capital letters in the ASCII collating sequence?
d. If you were designing a character set, where in the collating sequence would you place the space character? Why?
e. What position does the space character occupy in ASCII?
In ASCII, the collating-sequence numbers of the control characters are 0
through 31 and 127. Define a predicate char-control?
that
returns #t
if its argument is a control character,
#f
otherwise.
Note: The char-control?
predicate takes a character, not an integer, as a parameter. (It need not verify the type of the parameter, but it should work with characters.)
a. Is the symbol 'hyperbola
a string?
b. Is the character #\A
a string?
c. Does the empty string, ""
, count as a string?
Suggest three ways of constructing the string "???"
-- one
using a call to make-string
, one a call to
string
, and one a call to list->string
.
Here are two opposing views about the relationship between
string-length
and string-ref
:
No matter what stringstr
is, provided that it's not the empty string,(string-ref str (string-length str))
will return the last character in the string.
No matter what stringstr
is,(string-ref str (string-length str))
is an error.
Which, if either, of these views is correct? Why?
Write a Scheme procedure, (tally-vowels str)
, that determines how many characters in str are vowels. (For this purpose, you should count only the ten characters #\a, #\e, #\i, #\o, #\u, #\A, #\E, #\I, #\O, and #\U as vowels.)
You may not convert str
to a list before counting.
(That is, you'll need to use string-ref
to look at the
individual characters.)
Write a procedure, (symbol-list->string los)
that converts a list of symbols to a string for that list of symbols. You may find the symbol->string
procedure helpful.
For example,
> (symbol-list->string (list 'a 'b 'c)) "(a b c)" > (symbol-list->string (list)) "()" > (symbol-list->string (list 'alpha 'bravo 'charlie)) "(alpha bravo charlie)"
Hint: Convert the elements of the list to a string using a kernel procedure and then add the parens.
Tuesday, 3 October 2000 [Samuel A. Rebelsky]
http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2000F/Labs/strings.html
.
Wednesday, 7 February 2001 [Samuel A. Rebelsky]
Sunday, 18 February 2001 [Samuel A. Rebelsky]
markup
based
on experience using it.
http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2001S/Labs/strings.html
.
Monday, 16 September 2002 [Samuel A. Rebelsky]
http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2002F/Labs/strings.html
.
Friday, 7 February 2003 [Samuel A. Rebelsky]
Monday, 10 February 2003 [Samuel A. Rebelsky]
char-control?
procedure.
http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2003S/Labs/strings.html
.
Monday, 10 February 2003 [Samuel A. Rebelsky]
mark
problem that takes advantage of
recursion and variable parameters (topics CS153 students should know
but CS151 students don't yet know).
http://www.cs.grinnell.edu/~rebelsky/Courses/CS153/2003S/Labs/strings.html
.
Sunday, 8 February 2004 [Samuel A. Rebelsky]
symbol-list->string
problem.
http://www.cs.grinnell.edu/~stone/courses/scheme/fall-2001/labs/strings.xhtml
.
http://www.cs.grinnell.edu/~rebelsky/Courses/CS153/2004S/Labs/strings.html
.
[Skip to Body]
Primary:
[Front Door]
[Current]
[Glance]
-
[Honesty]
[Instructions]
[Links]
[Search]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Readings]
[Reference]
Misc:
[Experiments in Java]
[Java API]
[Scheme Reference]
[Scheme Report]
[CS153 2003S]
[CS151 2003F]
[CS152 2000F]
[SamR]
Disclaimer:
I usually create these pages on the fly
, which means that I rarely
proofread them and they may contain bad grammar and incorrect details.
It also means that I tend to update them regularly (see the history for
more details). Feel free to contact me with any suggestions for changes.
This document was generated by
Siteweaver on Fri May 7 09:44:24 2004.
The source to the document was last modified on Mon Feb 9 10:36:45 2004.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS153/2004S/Labs/strings.html
.
You may wish to
validate this document's HTML
;
;
Check with Bobby