From: JLUI

Subject: One question

Date: 1998-9-2 15:56

Hi, I'm new in Lisp and CLOS and I have one basic ( I supose )
question ( sorry ).
    I take the program below from Internet, and I don't know why it 
does not work. What is missing ? Can anybody help me ?
 
 
 
 (defclass point ()
 ((x :accessor x-coord :initarg :x)
  (y :accessor y-coord :initarg :y)))
 
 (defclass jLine ()
     ((point1 :type point :accessor p1 :initarg :p1)
      (point2 :type point :accessor p2 :initarg :p2)))
 
 (defclass jPolygon ()
     ((number-of-sides :type integer :accessor number-of-sides
       :initarg :number-of-sides)
      (sides :type list :accessor sides :initarg :sides
       :documentation "set of jLine segments")))
 
 (defmethod jLine-length ((l jLine))
    (let ((delta-x (- (x-coord (p1 l)) (x-coord (p2 l))))
          (delta-y (- (y-coord (p1 l)) (y-coord (p2 l)))))
       (sqrt (+ (* delta-x delta-x) (* delta-y delta-y)))))
             
 (defmethod perimeter ((p jPolygon))
    (reduce #'+ (mapcar #'jLine-length (sides p))))
 
 (setf pt1 (make-instance 'point :x 0 :y 0))
 (setf pt2 (make-instance 'point :x 0 :y 5))
 (setf pt3 (make-instance 'point :x 5 :y 5))
 (setf pt4 (make-instance 'point :x 5 :y 0))
 (setf l1 (make-instance 'jLine :p1 pt1 :p2 pt2))
 (setf l2 (make-instance 'jLine :p1 pt2 :p2 pt3))
 (setf l3 (make-instance 'jLine :p1 pt3 :p2 pt4))
 (setf l4 (make-instance 'jLine :p1 pt4 :p2 pt1))
 (setf poly1 (make-instance 'jPolygon))
 
 (setf (sides poly1) '(l1 l2 l3 l4))
 (setf (number-of-sides poly1) 4)
 
 (perimeter poly1)
 
 
Thank you.
 
Jose Luiz Cunha