; File: shapes.l ; date: 09/22/99 ; type: pcl (clos) ; author: kathi dutton ; eloboration: ; A progam which creates an object, specifically a rectangle. The ; rectangle can then be displayed. As well as calculating its area ; and perimeter. ;-------------------------------------------------------------------- ; enter clos ( in-package "pcl" ) ;-------------------------------------------------------------------- ; Define a shapes class ( defclass shapes () ( ( base :accessor shapes-base :initarg :base ) ( height :accessor shapes-height :initarg :height ) ) ) ;-------------------------------------------------------------------- ; Define a display method ( defmethod display ( ( r shapes ) ) ( princ "(" ) ( princ ( shapes-base r ) ) ( princ "," ) ( princ ( shapes-height r ) ) ( princ ")" ) ( terpri ) ) ;------------------------------------------------------------------- ; make an instance of a rectangle ( defmethod rect ( base height ) ( setf *shaprect* ( make-instance 'shapes :base base :height height ) ) ) ;------------------------------------------------------------------ ; Define method to calculate rectangle's area ( defmethod area () ( setf base ( shapes-base *shaprect* ) ) ( setf height ( shapes-height *shaprect* ) ) ( setf result (* base height)) ( princ "area " ) ( prin1 result ) ( terpri ) ) ) ;------------------------------------------------------------------- ; Define method to calculate rectangle's perimeter ( defmethod perimeter () ( setf base ( shapes-base *shaprect* ) ) ( setf height ( shapes-height *shaprect* ) ) ( setf result ( + ( * 2 base ) ( * 2 height ) ) ) ( princ "perimeter " ) ( prin1 result ) ( terpri ) ) )