Computer Science Fundamentals (CS153 2003S)
[Skip to Body]
Primary:
[Front Door]
[Current]
[Glance]
-
[EC]
[Honesty]
[Instructions]
[Links]
[Search]
[Syllabus]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Lab Writeups]
[Outlines]
[Readings]
[Reference]
ECA:
[About]
[Grades]
[Quizzes]
[Submit Work]
[Change Password]
[Reset Password]
Misc:
[Experiments in Java]
[Scheme Reference]
[Scheme Report]
[CS153 2002S (Walker)]
[CS151 2003S (Rebelsky)]
[CS152 2000F (Rebelsky)]
[SamR]
Contents:
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>?
a. If you have not done so already, you may want to skim the reading on characters and the reading on strings.
b. 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 that char-control?
takes a character, not
an integer, as a parameter.
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 procedure, (heading level text)
that generates a string that contains a string for an HTML heading of
the appropriate level. For example,
> (heading 2 "Exercise 6") "<h2>Exercise 6</h2>" > (heading 4 "History") "<h4>History</h4>"
You may find it useful to use the procedures
number->string
and
string-append
.
Note that you can check special characters in your output by using
(display exp)
, which shows exp without
the quotation marks and with the special control characters (such as
newline) as the character the represent, rather than a special control
sequence.
a. Write a procedure, (markup tag text)
that
surrounds text with the given tag. For example.
> (markup "p" "Hi There") "<p>Hi There</p>" > (markup "strong" "Wicked Neat!") "<strong>Wicked Neat!</strong>"
b. Use markup
, string-append
, and any other
procedures you deem appropriate to generate the following HTML:
<p> Sam says <q>Scheme is <strong>Wicked Neat!</strong></q> </p>
Note that you may want to use the character #\newline
for
new lines.
d. Write a (paragraph text)
procedure using
markup
a. Write a variant of markup
,
(mark tag attribute-list text)
,
that surrounds text with the appropriate tags and
includes an appropriate set of attributes in the opening tag.
The attribute parameter should be a list of lists. The
car of each component list is a string that gives an attribute name. The
cdr of each component list is a string that gives a value.
For example,
> (mark "a" '(("href" "http://www.cs.grinnell.edu")) "CS") "<a href=\"http://www.cs.grinnell.edu\">CS</a>" > (mark "p" null "Hello.") "<p>Hello</p>"
b. Extend mark
so that it can take an arbitrary number of
parameters. It should concatenate together all the parameters after
attribute-list before surrounding them with the appropriate tag.
c. Why might you use Scheme rather than a text editor to build a Web page?
Use markup
to implement the following procedures, each of
which takes one argument (some text) and generates HTML for appropriately
formatted text.
a. bold
b. strong
c. emphasize
Using the previous procedures, write a procedure, page
,
of no arguments
that builds a simple HTML page of your choice. Your procedure will
begin
(define page (lambda () instructions-for-building-the-page)))
You can call the procedure with (page)
.
Write a procedure, (rant-page subject)
, that
builds an HTML page that rants non-specifically about subject.
For example, if subject were days in which the temperature
is less than zero degrees Fahrenheit
the body of the page might read
I hate days in which the temperature is less than zero degrees Fahrenheit. You probably hate days in which the temperature is less than zero degrees Fahrenheit, too.
Similarly, if subject were malicious computers
, the page
might read
I hate malicious computers. You probably hate malicious computers, too.
You may instead make the page say nice things, if you would prefer.
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
.
[Skip to Body]
Primary:
[Front Door]
[Current]
[Glance]
-
[EC]
[Honesty]
[Instructions]
[Links]
[Search]
[Syllabus]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Lab Writeups]
[Outlines]
[Readings]
[Reference]
ECA:
[About]
[Grades]
[Quizzes]
[Submit Work]
[Change Password]
[Reset Password]
Misc:
[Experiments in Java]
[Scheme Reference]
[Scheme Report]
[CS153 2002S (Walker)]
[CS151 2003S (Rebelsky)]
[CS152 2000F (Rebelsky)]
[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 Tue May 6 09:20:03 2003.
The source to the document was last modified on Mon Feb 10 09:56:41 2003.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS153/2003S/Labs/strings.html
.
You may wish to
validate this document's HTML
;
;
Check with Bobby