anchor.diff:      :documentation "World's events.")))
   
   
  -(defmethod initialize-instance :after ((w world) &key)
  -  (push w (history-of w)))
  -
  -
  -(defmethod !transform ((dest world) (source world))
  -  (setf (events-of dest) (events-of source))
  -  (setf (history-of dest) (history-of source))
  -  dest)
  -
  -
  -(defmethod clone ((w world))
  -  (!transform (make-instance 'world :id (id-of w) :events nil) w))
  -
  -
  -(defmethod run :around ((w world) (ev event))
  -  (format t "~&~D " (time-of ev))
  -  (call-next-method))
  -
  -
  -(defmethod run ((w world) (ev event))
  -  (let* ((new-world (clone w))
  -	 (this (pop (events-of new-world))))
  -    (push new-world (history-of new-world))
  -    (assert (eql this ev) nil
  -	    "executing event should be the first in the event list.")
  -    (funcall (!action-of ev) new-world)
  -    new-world))
  +(defmethod schedule ((w world) (ev event))
  +  (assert (>= (time-of ev) (clock-of w)) nil
  +	  "Scheduling an event in the past.")
  +  (setf (events-of w)
  +	(sort (cons ev (events-of w))
  +	      #'< :key #'time-of)))
   
   
   (defmethod next ((w world))
  -  (run w (first (events-of w))))
  -
  -
  -(defmethod prev ((w world))
  -  (second (history-of w)))
  +  (with-accessors ((events events-of) (clock clock-of)) w
  +    (when (not (null events))
  +      (let ((ev (pop events)))
  +	(setf clock (time-of ev))
  +	(format t "~&~D " clock)
  +	(funcall (action-of ev) w)
  +	w))))
  
positive.code: (defpackage :org.altervista.rjack.desim
    (:nicknames :ds)
    (:use :common-lisp)
    (:export :!transform :clone :run :next :prev
  	   :identifiable :id-of
  	   :simulated :description-of
  	   :event :time-of :!action-of
  	   :world :hystory-of :events-of))
  
  
  (in-package :ds)
  
  
  (defgeneric !transform (dest source)
    (:documentation "Fill dest with some, all or none of the values from
    source."))
  
  
  (defgeneric clone (object)
    (:documentation "Return a shallow copy of object."))
  
  
  (defgeneric run (world event)
    (:documentation "Execute the action associated with event returning
    a new world, possibly different from the given one."))
  
  
  (defgeneric next (world)
    (:documentation "Return the next world, based on the given one."))
  
  
  (defgeneric prev (world)
    (:documentation "Return the previous world, relative to the given
    one."))
  
  
  (defclass identifiable ()
  
negative.code:     :type fixnum
      :documentation "When this event must be executed.")
  
     (action
      :initarg :action
      :initform (error "missing :action")
      :reader action-of
      :type function   ; FIXME: must fully specify signature.
      :documentation "Implements the behaviour of this event, taking the
      world as its only argument and modifying it.
  