Initial revision
[sbcl.git] / tests / pcl.impure.lisp
1 (defpackage "FOO"
2   (:use "CL"))
3 (in-package "FOO")
4 \f
5 ;;;; It should be possible to do DEFGENERIC and DEFMETHOD referring to
6 ;;;; structure types defined earlier in the file.
7
8 (defstruct struct-a x y)
9 (defstruct struct-b x y z)
10
11 (defmethod wiggle ((a struct-a))
12   (+ (struct-a-x a)
13      (struct-a-y a)))
14 (defgeneric jiggle ((arg t)))
15 (defmethod jiggle ((a struct-a))
16   (- (struct-a-x a)
17      (struct-a-y a)))
18 (defmethod jiggle ((b struct-b))
19   (- (struct-b-x b)
20      (struct-b-y b)
21      (struct-b-z b)))
22
23 (assert (= (wiggle (make-struct-a :x 6 :y 5))
24            (jiggle (make-struct-b :x 19 :y 6 :z 2))))
25 \f
26 ;;; Compiling DEFGENERIC should prevent "undefined function" style warnings
27 ;;; from code within the same file.
28
29 (defgeneric gf-defined-in-this-file ((x number) (y number)))
30 (defun function-using-gf-defined-in-this-file (x y n)
31   (unless (minusp n)
32     (gf-defined-in-this-file x y)))