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

Lambda calculus, Type theory, Formal semantics, Program analysis

    Prev     Next     All lectures        Code

Doctor's Office Simulation

The following is added to initialize state for simulation. A user just needs to create a list of doctors' names and a list of patients' names to use it. Event times for sick events (the only ones at the outset of the simulation) are created by a "random" number generator which is implemented below as the function rand. Add the code below to that of the previous slides and run like this:
  prompt> res5
  ;Value: 
  (eventq: 
    ((event: time-to-sick-for-patient jacky is 5) 
     (event: time-to-sick-for-patient joe is 8) 
     (event: time-to-sick-for-patient jim is 134) 
     (event: time-to-sick-for-patient jorry is 138) 
     (event: time-to-sick-for-patient john is 162) 
     (event: time-to-sick-for-patient jane is 277) 
     (event: stop-event: 300))
   patientq: () 
   doctorq: 
    ((doctor: lisa *unassigned*) 
     (doctor: lory *unassigned*) 
     (doctor: larry *unassigned*)))
Here is the code to add:
(define rand (lambda (n) (modulo (* 13711 n) 313)))

(define initializer
  (lambda (pat-lst doc-lst)
    (letrec 
      ((add-patients 
	(lambda (lst state time)
	  (if (null? lst)
	      state
	      (add-patients 
	        (cdr lst)
	        (state 'pat-sick-evt (patient-maker (car lst) time) time)
	        (rand time)))))
       (add-doctors
	(lambda (lst state)
	  (if (null? lst)
	      state
	      (add-doctors 
                (cdr lst)
                (state 'doctor-enters-pool (doctor-maker (car lst))))))))
      (let* 
        ((state 
           (state-maker (queue-maker '()) (queue-maker '()) (queue-maker '())))
	 (time (rand 23))
	 (state (add-doctors doc-lst state))
	 (state (add-patients pat-lst state time))
	 (state (state 'stop-event)))
	state))))

(define pat-lst '(John Jim Jane Jacky Joe Jorry))
(define doc-lst '(Lisa Lory Larry))
(define res5 ((initializer pat-lst doc-lst) 'show))