Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defclass standard-point ()
- ((x :initform 0 :initarg :x)
- (y :initform 0 :initarg :y)))
- (defgeneric distance-origin (point))
- (defmethod distance-origin ((point1 standard-point))
- (when (and (slot-exists-p point1 'x) (slot-exists-p point1 'y))
- (sqrt (+ (expt (sb-mop:standard-instance-access point1 0) 2)
- (expt (sb-mop:standard-instance-access point1 1) 2)))))
- (defgeneric distance (point1 &optional point2))
- (defmethod distance (point1 &optional point2))
- (defmethod distance ((point1 standard-point) &optional point2)
- (when (and (slot-exists-p point1 'x) (slot-exists-p point1 'y))
- (sqrt (+ (expt (sb-mop:standard-instance-access point1 0) 2)
- (expt (sb-mop:standard-instance-access point1 1) 2)))))
- (defmethod distance ((point1 standard-point) &optional (point2 standard-point))
- (when (and (slot-exists-p point1 'x) (slot-exists-p point1 'y)
- (slot-exists-p point2 'x) (slot-exists-p point2 'y))
- (sqrt (+ (expt (- (sb-mop:standard-instance-access point2 0) (sb-mop:standard-instance-access point1 0)) 2)
- (expt (- (sb-mop:standard-instance-access point2 1) (sb-mop:standard-instance-access point1 1)) 2)))))
- (defvar p1 (make-instance 'standard-point :x -3 :y 5))
- (defvar p2 (make-instance 'standard-point :x 7 :y -1))
- (defun test ()
- (distance p2 p1))
- (test)
- ; in: DEFMETHOD DISTANCE (T)
- ; (DEFMETHOD DISTANCE (POINT1 &OPTIONAL POINT2))
- ; --> LET* SB-INT:NAMED-LAMBDA
- ; ==>
- ; #'(SB-INT:NAMED-LAMBDA (SB-PCL::FAST-METHOD DISTANCE (T))
- ; (SB-PCL::.PV. SB-PCL::.NEXT-METHOD-CALL. POINT1 &OPTIONAL POINT2)
- ; (DECLARE (IGNORABLE SB-PCL::.PV. SB-PCL::.NEXT-METHOD-CALL.)
- ; (DISABLE-PACKAGE-LOCKS SB-PCL::PV-ENV-ENVIRONMENT))
- ; (DECLARE (SB-PCL::%PARAMETER POINT1))
- ; (DECLARE (TYPE T POINT1))
- ; (DECLARE (IGNORABLE POINT1))
- ; (SYMBOL-MACROLET ((SB-PCL::PV-ENV-ENVIRONMENT SB-PCL::DEFAULT))
- ; (SB-PCL::FAST-LEXICAL-METHOD-FUNCTIONS ((POINT1)
- ; SB-PCL::.NEXT-METHOD-CALL.
- ; (POINT1) NIL
- ; :CALL-NEXT-METHOD-P NIL :SETQ-P
- ; NIL :PARAMETERS-SETQD NIL
- ; :METHOD-CELL (#:METHOD-CELL)
- ; ...)
- ; (LOCALLY
- ; (DECLARE #)
- ; (SYMBOL-MACROLET #
- ; #
- ; #)))))
- ;
- ; caught STYLE-WARNING:
- ; The variable POINT2 is defined but never used.
- ;
- ; compilation unit finished
- ; caught 1 STYLE-WARNING condition
- ; file: /home/oleo/lisp/clos/packages-and-classes/standard-slot-order.lisp
- ; in: DEFMETHOD DISTANCE (STANDARD-POINT)
- ; (DEFMETHOD DISTANCE ((POINT1 STANDARD-POINT) &OPTIONAL POINT2)
- ; (WHEN (AND (SLOT-EXISTS-P POINT1 'X) (SLOT-EXISTS-P POINT1 'Y))
- ; (SQRT (+ (EXPT # 2) (EXPT # 2)))))
- ; --> LET* SB-INT:NAMED-LAMBDA
- ; ==>
- ; #'(SB-INT:NAMED-LAMBDA (SB-PCL::FAST-METHOD DISTANCE (STANDARD-POINT))
- ; (SB-PCL::.PV. SB-PCL::.NEXT-METHOD-CALL. POINT1 &OPTIONAL POINT2)
- ; (DECLARE (IGNORABLE SB-PCL::.PV. SB-PCL::.NEXT-METHOD-CALL.)
- ; (DISABLE-PACKAGE-LOCKS SB-PCL::PV-ENV-ENVIRONMENT))
- ; (DECLARE (SB-PCL::%PARAMETER POINT1))
- ; (DECLARE (IGNORABLE POINT1))
- ; (SYMBOL-MACROLET ((SB-PCL::PV-ENV-ENVIRONMENT SB-PCL::DEFAULT))
- ; (SB-PCL::FAST-LEXICAL-METHOD-FUNCTIONS ((POINT1)
- ; SB-PCL::.NEXT-METHOD-CALL.
- ; (POINT1) NIL
- ; :CALL-NEXT-METHOD-P NIL :SETQ-P
- ; NIL :PARAMETERS-SETQD NIL
- ; :METHOD-CELL (#:METHOD-CELL)
- ; ...)
- ; (DECLARE (SB-PCL::%CLASS POINT1 STANDARD-POINT))
- ; (LOCALLY
- ; (DECLARE #)
- ; (SYMBOL-MACROLET #
- ; #
- ; #)))))
- ;
- ; caught STYLE-WARNING:
- ; The variable POINT2 is defined but never used.
- ;
- ; compilation unit finished
- ; caught 1 STYLE-WARNING condition
- ; file: /home/oleo/lisp/clos/packages-and-classes/standard-slot-order.lisp
- ; in: DEFMETHOD DISTANCE (STANDARD-POINT)
- ; (DEFMETHOD DISTANCE
- ; ((POINT1 STANDARD-POINT) &OPTIONAL (POINT2 STANDARD-POINT))
- ; (WHEN
- ; (AND (SLOT-EXISTS-P POINT1 'X) (SLOT-EXISTS-P POINT1 'Y)
- ; (SLOT-EXISTS-P POINT2 'X) (SLOT-EXISTS-P POINT2 'Y))
- ; (SQRT (+ (EXPT # 2) (EXPT # 2)))))
- ; --> LET* SB-INT:NAMED-LAMBDA FUNCTION
- ; ==>
- ; (LET ((#:G1 STANDARD-POINT))
- ; (LOCALLY
- ; (DECLARE (MUFFLE-CONDITIONS CODE-DELETION-NOTE))
- ; (SB-C::%FUNCALL #'(FAST-METHOD DISTANCE (STANDARD-POINT)) SB-PCL::.PV.
- ; SB-PCL::.NEXT-METHOD-CALL. POINT1 #:G1)))
- ;
- ; caught WARNING:
- ; undefined variable: COMMON-LISP-USER::STANDARD-POINT
- ;
- ; compilation unit finished
- ; Undefined variable:
- ; STANDARD-POINT
- ; caught 1 WARNING condition
- T
- *
- * (distance p1)
- debugger invoked on a UNBOUND-VARIABLE in thread
- #<THREAD "main thread" RUNNING {1000560083}>:
- The variable STANDARD-POINT is unbound.
- Type HELP for debugger help, or (SB-EXT:EXIT) to exit from SBCL.
- restarts (invokable by number or by possibly-abbreviated name):
- 0: [CONTINUE ] Retry using STANDARD-POINT.
- 1: [USE-VALUE ] Use specified value.
- 2: [STORE-VALUE] Set specified value and use it.
- 3: [ABORT ] Exit debugger, returning to top level.
- ((:METHOD DISTANCE (STANDARD-POINT)) #<STANDARD-POINT {1001AB66F3}>) [fast-method,optional]
- source: (DEFMETHOD DISTANCE
- ((POINT1 STANDARD-POINT)
- &OPTIONAL (POINT2 STANDARD-POINT))
- (WHEN
- (AND (SLOT-EXISTS-P POINT1 'X) (SLOT-EXISTS-P POINT1 'Y)
- (SLOT-EXISTS-P POINT2 'X) (SLOT-EXISTS-P POINT2 'Y))
- (SQRT (+ (EXPT (- # #) 2) (EXPT (- # #) 2)))))
- 0]
Add Comment
Please, Sign In to add comment