forked from dmitryvk/sbcl-win32-threads
/
clos.impure.lisp
53 lines (46 loc) · 1.75 KB
/
clos.impure.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
;;;; miscellaneous side-effectful tests of CLOS
;;;; This software is part of the SBCL system. See the README file for
;;;; more information.
;;;;
;;;; While most of SBCL is derived from the CMU CL system, the test
;;;; files (like this one) were written from scratch after the fork
;;;; from CMU CL.
;;;;
;;;; This software is in the public domain and is provided with
;;;; absolutely no warranty. See the COPYING and CREDITS files for
;;;; more information.
(defpackage "FOO"
(:use "CL"))
(in-package "FOO")
;;;; It should be possible to do DEFGENERIC and DEFMETHOD referring to
;;;; structure types defined earlier in the file.
(defstruct struct-a x y)
(defstruct struct-b x y z)
(defmethod wiggle ((a struct-a))
(+ (struct-a-x a)
(struct-a-y a)))
(defgeneric jiggle ((arg t)))
(defmethod jiggle ((a struct-a))
(- (struct-a-x a)
(struct-a-y a)))
(defmethod jiggle ((b struct-b))
(- (struct-b-x b)
(struct-b-y b)
(struct-b-z b)))
(assert (= (wiggle (make-struct-a :x 6 :y 5))
(jiggle (make-struct-b :x 19 :y 6 :z 2))))
;;; Compiling DEFGENERIC should prevent "undefined function" style warnings
;;; from code within the same file.
(defgeneric gf-defined-in-this-file ((x number) (y number)))
(defun function-using-gf-defined-in-this-file (x y n)
(unless (minusp n)
(gf-defined-in-this-file x y)))
;;; Until Martin Atzmueller ported Pierre Mai's CMU CL fixes in
;;; sbcl-0.6.12.25, the implementation of NO-APPLICABLE-METHOD was
;;; broken in such a way that the code here would signal an error.
(defgeneric zut-n-a-m (a b c))
(defmethod no-applicable-method ((zut-n-a-m (eql #'zut-n-a-m)) &rest args)
(format t "~&No applicable method for ZUT-N-A-M ~S, yet.~%" args))
(zut-n-a-m 1 2 3)
;;;; success
(sb-ext:quit :unix-status 104)