#!/bin/sh
string=? ; exec mzscheme -g -l core.ss -r $0 "$@"

; <course> = (listof <block>)
; <block>  = (list block-title <week> ...)
; <week>   = (list title lab-title (listof lecture))

(define course
  '(
    ("Functional Design"
      ( "Basic Scheme, Basic Design Recipes" "Editing, (Hand) Evaluating with DrScheme, Design Recipe (Outline)"
; 25 Jan
	 (
	  "What is Computation? What is Programming? Processing Numbers"
	  "Processing Intervals (Conditionals)"
	  "Processing Lists of Fixed Length (Structures)"
	  ))
      ( "Simple Recursive Recipes" "How to Use Design Recipes, define-struct"
; 1 Feb
	 (
	  "Processing Lists of Arbitrary Length" 
	  "Design Recipes"                 
	  "Rules I: Syntax and Evaluation" 
	  ))
      ( "Complex Recursive Recipes" "Developing Recursive Functions with Recipe"
; 8 Feb 
	 (
	  "Programs that Construct Lists"
	  "Processing Family Trees"
	  "Different Family Trees; Natural Numbers"
	  ))
      ( "Programs Composition" "Practice with Deep Recursion [S-expression]"
; 15 Feb 
	 ; "Sorting: Merge vs Insert, More on Complexity, "
	 (
	  "Files and Directories"
	  "More on Files; Functions that Process Two Complex Arguments"
	  "The Scope of Things and LOCAL"
	  ))) 

    ("Functional Abstraction"
      ( "Abstraction, Functions as Values" "Practice with Deep Recursion [S-expression]"
; 22 Feb 
	 (
	  "Insertion Sort and Functional Abstraction"
	  "Practice with Using Functional Abstractions"
	  "Data Abstraction, Contracts with Variables"
	  ))
      ( "More on Functions; Generative Recursion" "Abstraction and Iterators"
; 1 Mar
	 (
	  "Functions from Functions"
	  "Mathematical First-Class Functions; Editing Programs"	  
	  "Quick Sort; Sierpinski"
	  )))

; 8 Mar : recess

    ("Generative Recursion, Accumulation"      
      ( "Generate and Recur" "LAMBDA and more iterators"
; 15 Mar      
	 ("Searching a Root: Iterative, Binary, and Newton"
	  "More Roots; The Recipe"
	  "Termination"
	  ))

;;; ------------------------------------------------------------------------------------------

      ( "Backtracking and Accumulators" "GCD; The Nature of Numbers"
; 22 Mar 
	 (
	  "Gaussian Elimination"
	  "Graphs and Backtracking"
	  "Accumulators: Making Change, Planning a Route"
	  ))

      ( "More on Accumulators" "---"
; 29 Mar
	 ("Accumulator Style"
	  "What are Accumulators? Iteration."
	  "--- Easter Break ---"
	 )))
    ("Imperative Program Design" 
      ("Functions and their History" "Simple Vectors"
; Apr 5
	 ("State of Real-World Objects"
	  "Graphs with Cycles"
	  "Vectors: Building and Reducing"
	  )))

    ( "Inside the Machine, Programming the Machine" 
       ( "A Model of the Real Machine" "Loops; Interacting with the JAM2000"
; Apr 12 
	  (
	   "How the Man in the Machine Really Works"
	   "Simple Machine-Level Programs"
	   "Modeling a Machine"
	   ))
       ( "Programming the Machine"  "Translating from Simple Scheme to C"
; Apr 19 
	  (
	   "Plain Assembly Language"
	   "C-style Assembly Language"
	   "Implementing Simple Scheme Functions in C"
	   )))

    ("What is Computer Science?"
      ( "Many Levels of Abstraction"  "Core C: Practice"
; Apr 26
	 (
	  "Marx and Hegel: From Scheme to the Machine and back"
	  "Assembly vs C vs Scheme: Who manages what?"
	  "The Halting Problem"
	  )))
    ))

(require "../aux.ss")
(define LAST-LECTURE (max-numbered-file))
(define OUTPUT "schedule.html")

; Apr 30: last day of class    

(define (course? S)
  (local ((define (block? S)
	    (if (>= (length S) 2)
		(and 
		  (string? (first S))
		  (andmap week? (rest S)))
		(error 'check "not a block ~s~n" S)))

	  (define (week? S)
	    (if (= (length S) 3)
		(and (string? (first S))
		  (string? (second S))
		  (andmap lecture? (third S)))
		(error 'week "not a week ~s" S)))
	  (define lecture? string?))
    (andmap block? S)))

(define title "{\Large An Introduction to Programming and Computing}}")
	      
(define (course-text course)
  (local ((define (block-text block)
	    (printf "~a~n" (first block))
	    (for-each week-text (rest block)))

	  (define (week-text week)
	    (printf "  Topic: ~a  [Lab topic: ~a]~n" (first week) (second week))
	    (for-each lecture-text (third week)))

	  (define (lecture-text lecture)
	    (printf "    ~a~n" lecture)))
    (for-each block-text course)))

(define (course-html course)
  (local ((define (block-html block)
	    (printf LINE)
	    (printf BLOCK (first block))
	    (for-each week-html (rest block)))

	  (define week-no 0)
	  (define (week-html week)
	    (set! week-no (+ week-no 1))
	    (printf WEEK week-no (first week) (second week))
	    (for-each lecture-html (third week))
	    (printf EOFWEEK))

	  (define lecture-no 0)
	  (define (lecture-html lecture)
	    (set! lecture-no (+ lecture-no 1))
	    (printf LECTURE
	      (if (<= lecture-no LAST-LECTURE)
		  (format NUMBER-FORMAT lecture-no lecture-no)
		  (format NO-NUMBER-FORMAT lecture-no))
	      lecture)))
    (display PREFIX) (newline)
    (for-each block-html course)
    (display POSTFIX) (newline)))

(define LECTURE "    <tr><td align=right width=10>~a</td><td> ~a<td></tr>~n")
(define NUMBER-FORMAT "<a href=~a.shtml>~a</a>")
(define NO-NUMBER-FORMAT "~a")

(define PREFIX "
<html>
<!-- generated by a MzScheme script # edit the source instead -->
<title>210 Sample Schedule</title>
<body bgcolor=\"#ffffff\">
<center><h2>210 Sample Schedule</h2></center>
")

(define TODAY (read-line (car (process "date"))))

(define POSTFIX (format "
<br><br><br>
<table width=100%>
<tr>
<td align=left>Matthias Felleisen</td>
<td align=right>
<small>This page was generated on ~a.</small>
</td>
</tr>
</table>

</body>
</html>
" (read-line (car (process "date")))))

(define LINE "~n")

(define BLOCK "
<br><br><br>
<table width=100% align=left><tr bgcolor=green><td><font size=+2 color=white>~a</font></td></tr></table>
<br><br><br>
")

(define WEEK "
  <p><table border=0 CELLPADDING=3 cellspacing=1>
     <tr><td>&nbsp;</td><td><strong>Week ~a: ~a</strong> [Lab topic: ~a]</td></tr>
")

(define EOFWEEK "  </table>~n")

;; GO: 

(when (file-exists? OUTPUT)
  (delete-file OUTPUT))
(define oport (open-output-file OUTPUT))
(current-output-port oport)

(course-html course)
