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. However, at present it is
16 ;;; impossible to have more than one of these in the same image,
17 ;;; because of a vicious metacircle. Once the vicious metacircle is
18 ;;; dealt with, uncomment the test cases.
26 (defclass my-generic-function1 (standard-generic-function) ()
27 (:metaclass funcallable-standard-class))
29 (defmethod compute-discriminating-function ((gf my-generic-function1))
30 (let ((dfun (call-next-method)))
32 (1+ (apply dfun args)))))
35 (:generic-function-class my-generic-function1))
37 (defmethod foo (x) (+ x x))
39 (assert (= (foo 5) 11))
45 (defmethod compute-discriminating-function ((gf my-generic-function))
46 (let ((std (call-next-method)))
48 (print (list 'call-to-gf gf arg))
53 (defmethod compute-discriminating-function ((gf my-generic-function))
55 (cond (<some condition>
56 <store some info in the generic function>
57 (set-funcallable-instance-function
59 (compute-discriminating-function gf))
62 <call-a-method-of-gf>))))
68 ;;; from clisp's test suite
71 (defclass traced-generic-function (standard-generic-function)
73 (:metaclass clos:funcallable-standard-class))
74 (defvar *last-traced-arguments* nil)
75 (defvar *last-traced-values* nil)
76 (defmethod clos:compute-discriminating-function ((gf traced-generic-function)) (let ((orig-df (call-next-method))
77 (name (clos:generic-function-name gf)))
78 #'(lambda (&rest arguments)
80 (format *trace-output* "~%=> ~S arguments: ~:S" name arguments)
81 (setq *last-traced-arguments* arguments)
82 (let ((values (multiple-value-list (apply orig-df arguments))))
83 (format *trace-output* "~%<= ~S values: ~:S" name values)
84 (setq *last-traced-values* values)
85 (values-list values)))))
86 (defgeneric testgf15 (x) (:generic-function-class traced-generic-function)
87 (:method ((x number)) (values x (- x) (* x x) (/ x))))
89 (list *last-traced-arguments* *last-traced-values*))
91 ;;; also we might be in a position to run the "application example"
92 ;;; from mop.tst in clisp's test suite