;;; Commands to help build HTML files for courses. ;;; ;;; Author: Samuel A. Rebelsky ;;; Version: 1.1 of October 2000 ;;; ;;; History ;;; Monday, 9 October 2000 ;;; Created ;;; Tuesday, 10 October 2000 ;;; Added all courses constant ;;; Added math courses ;;; Fixed bug in lookup-course-by-number ;;; Added lookup-courses-by-department ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Required helper files. (load "cs-courses.ss") (load "math-courses.ss") (load "html.ss") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Constants (define all-courses (append cs-courses math-courses)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Utilities ;;; Look up a course by number ;;; Parameters: ;;; The number of the course (e.g. "CSC151") ;;; A list of courses ;;; Produces: ;;; The corresponding course, if there is one. ;;; #f, otherwise ;;; Preconditions: ;;; The list of courses is in the appropriate format. (define lookup-course-by-number (lambda (num courses) (cond ((null? courses) #f) ((equal? num (cadar courses)) (car courses)) (else (lookup-course-by-number num (cdr courses)))))) ;;; Look up all the courses in a department. ;;; Parameters: ;;; The department abbreviation (e.g., "CSC", "MAT", "ANT") ;;; A list of courses in the appropriate form. ;;; Produces: ;;; A list of matching courses. ;;; The empty list, if no courses are in the lsit. (define lookup-courses-by-dept (lambda (dept courses) (if (null? courses) null (let ((remaining-courses (lookup-courses-by-dept dept (cdr courses))) (course (car courses))) (if (equal? dept (substring (cadr course) 0 3)) (cons course remaining-courses) remaining-courses))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Techniques for displaying individual courses ;;; (course->html course) ;;; Converts information on a course to HTML. See cs-courses.ss ;;; for more information on the format of a course. ;;; Pre: The course is in the given format. ;;; Post: Returns a string of the appropriate form. The string ;;; ends with a carriage return. (define course->html (lambda (course) (let ((dept (list-ref course 0)) (num (list-ref course 1)) (name (list-ref course 2)) (nick (list-ref course 3)) (desc (list-ref course 4))) (string-append (html-paragraph (string-append (html-bold num) " " (html-italic (string-append name " (" nick ")")) return "
" dept)) return (html-block desc) return)))) ;;; (courses->html list-of-courses) ;;; Converts a list of information on a courses to HTML. ;;; See cs-courses.ss for more information on the format of a course. ;;; Pre: The courses are given in the given format. ;;; Post: Returns a string of the appropriate form. The string ;;; ends with a carriage return. (define courses->html (lambda (list-of-courses) (cond ((null? list-of-courses) "") (else (string-append (course->html (car list-of-courses)) (courses->html (cdr list-of-courses))))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Tests (define html1 (course->html (car cs-courses))) (define htmlall (courses->html cs-courses)) (define cspage (lambda () (html-document "Courses in Computer Science" (string-append (html-head "Cool Computing Courses" 1) (courses->html cs-courses)))))