This article is out of date. See iodb.org's recent version.
The Parenscript Object System (PSOS) is a facility for object-oriented programming in Parenscript using the same style and techniques as the Common Lisp Object System. It consists of a set of macros in lisp and a runtime environment in Parenscript.
Multiple inheritance, generic functions, and basic method combination are currently implemented.
1. Different classes of people
(defclass person () () (:documentation "Any old person.")) (defclass citizen (person) () (:documentation "A person who votes.")) (defclass politician (citizen) () (:documentation "A person in public office.")) (defgeneric discuss-environment (individual)) (defmethod discuss-environment ((individual citizen)) (alert "I don't know anything about the environment")) (defmethod discuss-enviornment ((individual politician)) (alert "The environment is an important issue, but so is the War on Terror.")) (dicuss-environment (new politician)) ; alerts "the environment is..."
2. An event-handling system
This is a practical example that demonstrates a way to use generic functions and classes to implement an event-handling system.
;;; Event Handling ;;; (defvar global-event-table (create)) (defclass event () ((origin) (description)) (:documentation "Primitive event class for event observation. Custom event classes are created that subclass the abstract event class. These are dispatched by calling (make-instance some-event-class (create :origin origin ...)).")) (defclass event-emitter () () (:documentation "Subclasses of this can emit events.")) (defun event-handler-fits? (handler ev) (return (is-subclass-of handler.event-class (class-of ev)))) (defmethod initialize-instance :after ((ev event)) (event-fired (get-origin ev) ev)) (defmethod register-event-handler ((on-obj event-emitter) event-class handler-func) (let ((obj-observers (defaultf on-obj.event-handlers (array)))) (obj-observers.push (create :func handler-func :event-class event-class)))) (defgeneric event-fired (within-obj ev) (:documentation "Called when an event was fired within the given object. For example, if a button is clicked within a page, then the event will eventually fire for the page object with the given event.")) (defmethod event-fired ((within-obj event-emitter) ev) (let ((handlers (and within-obj.event-handlers (within-obj.event-handlers.filter (lambda (handler) (return (event-handler-fits? handler ev))))))) (when handlers (dolist (handler handlers) (handler.func ev)))) (call-next-method)) (defmethod event-fired ((within-obj general-sail) ev) (call-next-method) (let ((parent (parent-sail within-obj))) (when parent (event-fired parent ev))))
The current source may be downloaded via SVN:
svn checkout http://suavescript.googlecode.com/svn/trunk/paren-psos paren-psos
The project is maintained by Red Daly (reddaly at gmail) and licensed under the GPL.
the suavescript project - the current home of PSOS