0d07716f |
1 | ;; Common Lisp bindings for GTK+ v2.0 |
2 | ;; Copyright (C) 1999-2000 Espen S. Johnsen <espejohn@online.no> |
3 | ;; |
4 | ;; This library is free software; you can redistribute it and/or |
5 | ;; modify it under the terms of the GNU Lesser General Public |
6 | ;; License as published by the Free Software Foundation; either |
7 | ;; version 2 of the License, or (at your option) any later version. |
8 | ;; |
9 | ;; This library is distributed in the hope that it will be useful, |
10 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | ;; Lesser General Public License for more details. |
13 | ;; |
14 | ;; You should have received a copy of the GNU Lesser General Public |
15 | ;; License along with this library; if not, write to the Free Software |
16 | ;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17 | |
e04b3c2a |
18 | ;; $Id: gutils.lisp,v 1.5 2001/05/04 16:54:35 espen Exp $ |
0d07716f |
19 | |
20 | |
21 | (in-package "KERNEL") |
22 | |
23 | (defun type-expand-1 (form) |
24 | (let ((def (cond ((symbolp form) |
25 | (info type expander form)) |
26 | ((and (consp form) (symbolp (car form))) |
27 | (info type expander (car form))) |
28 | (t nil)))) |
29 | (if def |
30 | (values (funcall def (if (consp form) form (list form))) t) |
31 | (values form nil)))) |
32 | |
e04b3c2a |
33 | (in-package "PCL") |
34 | |
35 | (defmethod finalize-inheritance ((class std-class)) |
36 | (update-cpl class (compute-class-precedence-list class)) |
37 | (update-slots class (compute-slots class)) |
38 | (update-gfs-of-class class) |
39 | (update-inits class (compute-default-initargs class)) |
40 | (update-make-instance-function-table class) |
41 | (dolist (sub (class-direct-subclasses class)) |
42 | (update-class sub))) |
43 | |
44 | (defun update-class (class &optional finalizep) |
45 | (declare (ignore finalizep)) |
46 | (unless (class-has-a-forward-referenced-superclass-p class) |
47 | (finalize-inheritance class))) |
0d07716f |
48 | |
49 | (in-package "GLIB") |
50 | |
51 | |
52 | (defun type-expand-to (type form) |
53 | (labels ((expand (form0) |
54 | (if (eq (first (mklist form0)) type) |
55 | form0 |
56 | (multiple-value-bind (expanded-form expanded-p) |
57 | (type-expand-1 form0) |
58 | (if expanded-p |
59 | (expand expanded-form) |
60 | (error "~A can not be expanded to ~A" form type)))))) |
61 | (expand form))) |
62 | |
63 | (defmacro with-gc-disabled (&body body) |
64 | (let ((gc-inhibit (make-symbol "GC-INHIBIT"))) |
65 | `(progn |
66 | (let ((,gc-inhibit lisp::*gc-inhibit*)) |
67 | (ext:gc-off) |
e04b3c2a |
68 | (unwind-protect |
0d07716f |
69 | ,@body |
70 | (unless ,gc-inhibit |
71 | (ext:gc-on))))))) |
72 | |
73 | (defun mklist (obj) |
74 | (if (atom obj) (list obj) obj)) |
75 | |
76 | (defun namep (obj) |
77 | (and (symbolp obj) (not (member obj '(t nil))))) |
78 | |
79 | (defun all-equal (&rest objects) |
80 | (or |
81 | (null objects) |
82 | (null (rest objects)) |
83 | (and |
84 | (equal (first objects) (second objects)) |
85 | (apply #'all-equal (rest objects))))) |
86 | |
87 | (defun neq (obj1 obj2) |
88 | (not (eq obj1 obj2))) |
89 | |
90 | (defmacro return-if (form) |
91 | (let ((result (make-symbol "RESULT"))) |
92 | `(let ((,result ,form)) |
93 | (when ,result |
94 | (return ,result))))) |
95 | |
96 | (defun make-pointer (address) |
97 | (int-sap address)) |
98 | |
99 | (defun null-pointer-p (pointer) |
100 | (zerop (sap-int pointer))) |
eef2c0f1 |
101 | |
b94247b5 |
102 | |
103 | (defmacro when-bind ((var expr) &body body) |
104 | `(let ((,var ,expr)) |
105 | (when ,var |
106 | ,@body))) |
107 | |
108 | |
109 | (defmacro assoc-ref (key alist &key (test #'eq)) |
110 | `(cdr (assoc ,key ,alist :test ,test))) |
111 | |
112 | |
113 | (defmacro assoc-lref (key alist &key (test #'eq)) |
114 | `(cadr (assoc ,key ,alist :test ,test))) |
115 | |
116 | |
117 | (defun assoc-rem (key alist &key (test #'eq)) |
118 | (remove-if #'(lambda (element) (funcall test key (car element))) alist)) |
119 | |
120 | |
121 | (defun assoc-delete (key alist &key (test #'eq)) |
122 | (delete-if #'(lambda (element) (funcall test key (car element))) alist)) |
5ab32e1f |
123 | |
124 | |
125 | (defun funcallable (object) |
126 | (if (consp object) |
127 | (fdefinition object) |
128 | object)) |
129 | |
eef2c0f1 |
130 | |
131 | (defun split-string (string delimiter) |
132 | (declare (simple-string string) (character delimiter)) |
133 | (check-type string string) |
134 | (check-type delimiter character) |
135 | (let ((pos (position delimiter string))) |
136 | (if (not pos) |
137 | (list string) |
138 | (cons |
139 | (subseq string 0 pos) |
140 | (split-string (subseq string (1+ pos)) delimiter))))) |
141 | |
142 | (defun split-string-if (string predicate) |
143 | (declare (simple-string string)) |
144 | (check-type string string) |
145 | (check-type predicate (or symbol function)) |
146 | (let ((pos (position-if predicate string :start 1))) |
147 | (if (not pos) |
148 | (list string) |
149 | (cons |
150 | (subseq string 0 pos) |
151 | (split-string-if (subseq string pos) predicate))))) |
152 | |
153 | (defun concatenate-strings (strings &optional delimiter) |
154 | (if (not (rest strings)) |
155 | (first strings) |
156 | (concatenate |
157 | 'string |
158 | (first strings) |
159 | (if delimiter (string delimiter) "") |
160 | (concatenate-strings (rest strings))))) |