Fundamentals of CS I (CS151 2001S) : Outlines
[Current]
[Discussions]
[Glance]
[Honesty]
[Instructions]
[Links]
[News]
[Search]
[Syllabus]
Primary
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Quizzes]
[Readings]
[Reference]
Sets
[Blackboard]
[Scheme Report]
[SamR's Schedule]
[Rebelsky/Fall 2000]
[Walker/Fall2000]
[Stone/Spring2000]
Links
Back to Merge Sort. On to Discussion of Exam2.
Held Friday, April 27, 2001
Summary
Today we consider how the various things we've learned this semester can be put together to build a simple Web service.
Notes
http://www.cs.grinnell.edu/~rebelsky/Scheme/plans.ss.
Overview
program.cgi
<form action="http://www.cs.grinnell.edu/~rebelsky/plans.cgi"
method="get">
...
</form>
#!/bin/bash /home/rebelsky/bin/schemeweb plans.ss
page that generates a string that represents
an HTML page
(define page
(lambda ()
(make-page
(head "Example")
(body (paragraph "An Example")))))
http://www.cs.grinnell.edu/~heckr/Finger/.
(lookup account),
that will look up someone's plan entry.
lookup, and displays the result.
lookup in a DrScheme window.
cannedresult.
define at the
beginning of the program.
(define plans-dir "/home/rebelsky/Web/SchemePlans/") (define cgi-script "http://www.cs.grinnell.edu/~rebelsky/Scheme/plans.cgi") (define administrator-email "rebelsky@grinnell.edu")
(define read-plans
(lambda ()
(let* ((port (open-input-file plans-file))
(plans (read port)))
(close-input-port port)
plans)))
(define write-plans
(lambda (newplans)
; Bye bye old plans!
(delete-file plans-file)
; We can only write to a port, so open one
(let ((port (open-output-file plans-file)))
; Write the new plans in one lump.
(write newplans port)
; Put in a newline to be nice.
(newline port)
; That's it, we're done.
(close-output-port port))))
databasefile should be writeable by everyone. You set this in a shell window.
chmod a+w plans
chmod a+w PlansDir
search to find the matching plan.
Return it.
(define lookup-plan
(lambda (account plans)
(search (lambda (entry) (equal? (car entry) account))
plans)))
#t or #f.
#t or #f
and whose remaining elements are notes about success or
failure.
(define add-plan
(lambda (plan plans)
; Get the old plan
(let ((oldplan (get-plan (car plan) plans)))
; If the user already has a plan ...
(if oldplan
; Give up, it's not legal to add a new one.
(list #f "You cannot add an account that already exists.")
; Otherwise ...
(begin
; Update the plans file.
(write-plans (cons plan plans))
; Return the appropriate result.
(list #t))))))
(define finish-creation-page
(lambda (plans account password email fullname plan)
(let ((result (add-plan
(list account password email fullname plan)
plans)))
(if (car result)
(make-page
(head (string-append "[Plans] Added: " account))
(body (string-append
(plans-intro (string-append "Added entry for " account))
(plan->html (list account password email fullname plan))
"
"
(string #\newline)
(standard-buttons account password))))
(error-page (string-append "Creation error: " (cadr result))
(login-code))))))
Friday, 12 January 2001
Friday, 28 April 2001
Back to Merge Sort. On to Discussion of Exam2.
[Current]
[Discussions]
[Glance]
[Honesty]
[Instructions]
[Links]
[News]
[Search]
[Syllabus]
Primary
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Quizzes]
[Readings]
[Reference]
Sets
[Blackboard]
[Scheme Report]
[SamR's Schedule]
[Rebelsky/Fall 2000]
[Walker/Fall2000]
[Stone/Spring2000]
Links
Disclaimer: I usually create these pages on the fly. This means that they are rarely proofread and may contain bad grammar and incorrect details. It also means that I may update them regularly (see the history for more details). Feel free to contact me with any suggestions for changes.
This page was generated by Siteweaver on Wed May 5 12:15:13 2004.
This page may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2001S/outline.48.html.
You may validate
this page's HTML.
The source was last modified Fri Apr 27 08:50:54 2001.