1 ;;;; miscellaneous side-effectful tests of the MOP
3 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; While most of SBCL is derived from the CMU CL system, the test
7 ;;;; files (like this one) were written from scratch after the fork
10 ;;;; This software is in the public domain and is provided with
11 ;;;; absolutely no warranty. See the COPYING and CREDITS files for
12 ;;;; more information.
14 ;;; This file contains tests for COMPUTE-DISCRIMINATING-FUNCTION on
15 ;;; subclasses of generic functions.
23 (defclass my-generic-function1
(standard-generic-function) ()
24 (:metaclass funcallable-standard-class
))
26 (defmethod compute-discriminating-function ((gf my-generic-function1
))
27 (let ((dfun (call-next-method)))
29 (1+ (apply dfun args
)))))
32 (:generic-function-class my-generic-function1
))
34 (defmethod foo (x) (+ x x
))
36 (assert (= (foo 5) 11))
40 (defclass my-generic-function-pcl1
(standard-generic-function) ()
41 (:metaclass funcallable-standard-class
))
43 (defmethod compute-discriminating-function ((gf my-generic-function-pcl1
))
44 (let ((std (call-next-method)))
46 (print (list 'call-to-gf gf arg
))
50 (:generic-function-class my-generic-function-pcl1
))
52 (defmethod pcl1 ((x integer
)) (1+ x
))
54 (let ((output (with-output-to-string (*standard-output
*)
56 (assert (search "(CALL-TO-GF #<MY-GENERIC-FUNCTION-PCL1 PCL1 (1)> 3)" output
)))
59 (defclass my-generic-function-pcl2
(standard-generic-function) ()
60 (:metaclass funcallable-standard-class
))
61 (defmethod compute-discriminating-function ((gf my-generic-function-pcl2
))
63 (cond (<some condition
>
64 <store some info in the generic function
>
65 (set-funcallable-instance-function
67 (compute-discriminating-function gf
))
70 <call-a-method-of-gf
>))))
73 ;;; from clisp's test suite
76 (defclass traced-generic-function
(standard-generic-function)
78 (:metaclass funcallable-standard-class
))
79 (defvar *last-traced-arguments
* nil
)
80 (defvar *last-traced-values
* nil
)
81 (defmethod compute-discriminating-function ((gf traced-generic-function
)) (let ((orig-df (call-next-method))
82 (name (generic-function-name gf
)))
83 #'(lambda (&rest arguments
)
84 (format *trace-output
* "~%=> ~S arguments: ~:S" name arguments
)
85 (setq *last-traced-arguments
* arguments
)
86 (let ((values (multiple-value-list (apply orig-df arguments
))))
87 (format *trace-output
* "~%<= ~S values: ~:S" name values
)
88 (setq *last-traced-values
* values
)
89 (values-list values
)))))
90 (defgeneric testgf15
(x) (:generic-function-class traced-generic-function
)
91 (:method
((x number
)) (values x
(- x
) (* x x
) (/ x
))))
93 (assert (equal (list *last-traced-arguments
* *last-traced-values
*)
94 '((5) (5 -
5 25 1/5)))))
96 ;;; also we might be in a position to run the "application example"
97 ;;; from mop.tst in clisp's test suite