Exercises in this lecture   Go to the notes, in which this exercise belongs -- Keyboard shortcut: 'u'   Alphabetic index   Course home   

Exercise solution 1
Time tables


(define laml-dir "c:/programs/laml/")

(load (string-append laml-dir "laml.scm"))
(laml-style "simple-xhtml1.0-transitional-validating")
; (lib-load "xhtml1.0-convenience.scm")

; (fake-startup-parameters "tt.laml" "c:/users/kurt/temp/")

(define current-xml-language 'xhtml10-transitional)
(define laml-generation-meta (meta 'name "Generator" 'content "LAML"))
(define meta-props (list 'http-equiv "Content-Type" 'content "text/html; charset=iso-8859-1"))
(define html-props (list 'xmlns "http://www.w3.org/1999/xhtml"))

; Insert the LAML template "Processing Options" here
; if you need variations in the LAML processing

(define stations
  (list "Cottbus" "Spremsberg" "Weisswasser" "Horka" "Görlitz"))

; The number of minute in between stations
(define minutes
  (list 22 12 26 18))

; The similar number of seconds
(define seconds
  (map (lambda (s) (* s 60)) (list 22 12 26 18)))

; Accumulated number of seconds
(define (accumulate-seconds lst)
  (accumulate-list-helper lst 0 '()))

(define (accumulate-list-helper lst sum-until-now res)
  (cond ((null? lst) (reverse res))
        (else (accumulate-list-helper 
                 (cdr lst)
                 (+ sum-until-now (car lst))
                 (cons (+ (car lst) sum-until-now)
                       res))))) 

; Make a time table with a single start time
(define (time-table-1 station-list second-list start-time)
 (table 'border "0"
   (map (lambda (st sec)
          (tr (td (b st)) (td (actual-hour-minute (+ sec start-time)))))
        station-list (cons 0 second-list))))

; Make a time table with a list of start times
(define (time-table-n station-list second-list start-time-list)
 (table 'border "0"
   (map (lambda (st sec)
          (tr (td (b st)) 
              (map (lambda (st) (td (actual-hour-minute (+ sec st)))) start-time-list)))
        station-list (cons 0 second-list))))

; Nice rendering of the time of second count (like (current-time)).
(define (actual-hour-minute sc)
 (let ((dt (time-decode sc)))
  (string-append 
     (as-string (hour-of-time dt))
     ":"
     (if (< (minute-of-time dt) 10) "0" "")
     (as-string (minute-of-time dt)))))


(write-html '(pp prolog)
 (html html-props
  (head 
   (meta meta-props) laml-generation-meta
   (title "Time" (em "Tables") ))
  (body 
    (time-table-1 stations (accumulate-seconds seconds) (current-time))
      
  )
 )

)


(end-laml)