;;; -*- mode: Lisp; Syntax: Common-Lisp; -*- ;;; ;;; Copyright (c) 2009 by the authors. ;;; ;;; See LICENCE for details. (in-package :hu.dwim.dises.test) ;;;;;; ;;; Queue (defmacro source (inter-arrival-time &body forms) `(lambda () (with-call/cc (iter (progn ,@forms) (wait ,inter-arrival-time))))) (defmacro queue (size args &body forms) `(lambda ,args (with-call/cc ,@forms))) (defmacro sink (args &body forms) `(lambda ,args ,@forms)) (deftest test/queue () (run-with-new-simulator (bind ((i 0) (k 100) (s (sink (a) (format t "~%Got ~A at ~A" a (simulation-time-of *simulator*)))) (q (queue 10 (a) (funcall s a) (wait (exponential 10))))) (funcall (source (exponential 10) (funcall q (incf i)))) (funcall (source (exponential 20) (funcall q (decf k))))) (finish-at 100)))