20-CS-4003-001 Organization of Programming Languages Fall 2018
Object Oriented Style

Lambda calculus, Type theory, Formal semantics, Program analysis

    Prev     Next     All lectures        Code

Doctor's Office Simulation

;; Events -
;; event types are inferred: 
;;   time-to-sick = doctor is null, patient is not null
;;   time-to-release = doctor and patient are not null
;;   stop-event = doctor and patient are both null
;; subclasses timed-object
(define event-maker
  (lambda (patient doctor time)
    (let ((timed-object (timed-object-maker time)))
      (lambda msg
	(case (1st msg)
              (if (null? patient)
                  (list 'stop-event time)
                  (if (null? doctor)
                      (list 'time-to-sick-for-patient: 
                        (patient 'name) 'is time)
                      (list 'time-to-release-for-pairing
                        (patient 'name) 'and (doctor 'name)
                        'is time)))))
	    (if (null? patient)
	        (if (null? doctor)
	  ('get-patient patient)
	  ('get-doctor doctor)
	  (else (apply timed-object msg)))))))

(define res3
      (event-maker (patient-maker 'John 0) '() 12))
      (event-maker (patient-maker 'Jill 0) '() 26))
      (event-maker (patient-maker 'Jack 0) '() 9))
      (event-maker (patient-maker 'Joan 22) 
                   (doctor-maker 'Jerry) 24))
     (event5 (event-maker '() '() 100))
     (eventQ (queue-maker '()))
     (eventQ (eventQ 'insert event1))
     (eventQ (eventQ 'insert event2))
     (eventQ (eventQ 'insert event3))
     (eventQ (eventQ 'insert event4))
     (eventQ (eventQ 'insert event5)))
    (list 'event-queue: (eventQ 'show))))
 -  The simulation will execute on discrete events. Each event has a time when it occurs. Events occur in increasing order of time, hence they are stored in a priority queue and subclass the timed-object class. Add the code to the left to code of the previous slides and execute the following after loading:
  prompt> res3
   ((event: time-to-sick-for-patient jack is 9)
    (event: time-to-sick-for-patient john is 12) 
    (event: time-to-release-pairing joan and jerry is 24) 
    (event: time-to-sick-for-patient jill is 26) 
    (event: stop-event: 100)))