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 simple tests for
15 ;;; SET-FUNCALLABLE-INSTANCE-FUNCTION on FUNCALLABLE-INSTANCEs
18 ;;; from Justin Dubs on comp.lang.lisp
21 (:metaclass sb-mop
:funcallable-standard-class
))
25 (defmethod initialize-instance :after
((fn fn
) &rest initargs
&key
27 (declare (ignore initargs
))
28 (sb-mop:set-funcallable-instance-function fn
33 (let ((fun (make-instance 'fn
)))
34 (assert (= (funcall fun
42) 43))
35 (assert (eq *fn
* fun
)))
37 ;;; from Tony Martinez sbcl-devel
39 ((number :initarg
:start
:accessor counter
))
40 (:metaclass sb-pcl
::funcallable-standard-class
))
42 (defun make-counter (&key
(start 0))
43 (let ((instance (make-instance 'counter
:start start
)))
44 (sb-mop:set-funcallable-instance-function
46 ;; When run, this function doesn't print the instance, but (what
47 ;; I think is) itself.
48 (lambda () (print instance
)))
51 (defparameter *counter
* (make-counter :start
666))
53 (assert (eq (funcall *counter
*) *counter
*))