0.6.12.24:
[sbcl.git] / tests / pcl.impure.lisp
1 ;;;; miscellaneous side-effectful tests of CLOS
2
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
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
8 ;;;; from CMU CL.
9 ;;;; 
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.
13
14 (defpackage "FOO"
15   (:use "CL"))
16 (in-package "FOO")
17 \f
18 ;;;; It should be possible to do DEFGENERIC and DEFMETHOD referring to
19 ;;;; structure types defined earlier in the file.
20
21 (defstruct struct-a x y)
22 (defstruct struct-b x y z)
23
24 (defmethod wiggle ((a struct-a))
25   (+ (struct-a-x a)
26      (struct-a-y a)))
27 (defgeneric jiggle ((arg t)))
28 (defmethod jiggle ((a struct-a))
29   (- (struct-a-x a)
30      (struct-a-y a)))
31 (defmethod jiggle ((b struct-b))
32   (- (struct-b-x b)
33      (struct-b-y b)
34      (struct-b-z b)))
35
36 (assert (= (wiggle (make-struct-a :x 6 :y 5))
37            (jiggle (make-struct-b :x 19 :y 6 :z 2))))
38 \f
39 ;;; Compiling DEFGENERIC should prevent "undefined function" style warnings
40 ;;; from code within the same file.
41
42 (defgeneric gf-defined-in-this-file ((x number) (y number)))
43 (defun function-using-gf-defined-in-this-file (x y n)
44   (unless (minusp n)
45     (gf-defined-in-this-file x y)))
46 \f
47 ;;;; success
48
49 (sb-ext:quit :unix-status 104)