comparison lisp/tl/tl-atype.el @ 155:43dd3413c7c7 r20-3b4

Import from CVS: tag r20-3b4
author cvs
date Mon, 13 Aug 2007 09:39:39 +0200
parents c0c698873ce1
children
comparison
equal deleted inserted replaced
154:94141801dd7e 155:43dd3413c7c7
1 ;;; tl-atype.el --- atype functions 1 ;;; tl-atype.el --- atype functions
2 2
3 ;; Copyright (C) 1994,1995,1996 Free Software Foundation, Inc. 3 ;; Copyright (C) 1994,1995,1996 Free Software Foundation, Inc.
4 ;; Copyright (C) 1997 MORIOKA Tomohiko
4 5
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp> 6 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Version: $Id: tl-atype.el,v 1.2 1996/12/28 21:03:09 steve Exp $ 7 ;; Version: $Id: tl-atype.el,v 1.3 1997/06/06 00:57:42 steve Exp $
7 ;; Keywords: atype 8 ;; Keywords: atype
8 9
9 ;; This file is part of tl (Tiny Library). 10 ;; This file is part of XEmacs.
10 11
11 ;; This program is free software; you can redistribute it and/or 12 ;; This program is free software; you can redistribute it and/or
12 ;; modify it under the terms of the GNU General Public License as 13 ;; modify it under the terms of the GNU General Public License as
13 ;; published by the Free Software Foundation; either version 2, or (at 14 ;; published by the Free Software Foundation; either version 2, or (at
14 ;; your option) any later version. 15 ;; your option) any later version.
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, 24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA. 25 ;; Boston, MA 02111-1307, USA.
25 26
26 ;;; Code: 27 ;;; Code:
27 28
28 (require 'emu)
29 (require 'tl-str)
30 (require 'tl-list) 29 (require 'tl-list)
30 (require 'atype)
31 31
32 32
33 ;;; @ field 33 ;;; @ field
34 ;;; 34 ;;;
35 35
51 (setq r (cdr r)) 51 (setq r (cdr r))
52 )) 52 ))
53 c)) 53 c))
54 54
55 55
56 ;;; @ field unifier
57 ;;;
58
59 (defun field-unifier-for-default (a b)
60 (let ((ret
61 (cond ((equal a b) a)
62 ((null (cdr b)) a)
63 ((null (cdr a)) b)
64 )))
65 (if ret
66 (list nil ret nil)
67 )))
68
69 (defun field-unify (a b)
70 (let ((sym (symbol-concat "field-unifier-for-" (car a))))
71 (if (not (fboundp sym))
72 (setq sym (function field-unifier-for-default))
73 )
74 (funcall sym a b)
75 ))
76
77
78 ;;; @ type unifier
79 ;;;
80
81 (defun assoc-unify (class instance)
82 (catch 'tag
83 (let ((cla (copy-alist class))
84 (ins (copy-alist instance))
85 (r class)
86 cell aret ret prev rest)
87 (while r
88 (setq cell (car r))
89 (setq aret (fetch-field (car cell) ins))
90 (if aret
91 (if (setq ret (field-unify cell aret))
92 (progn
93 (if (car ret)
94 (setq prev (put-field (car (car ret))
95 (cdr (car ret))
96 prev))
97 )
98 (if (nth 2 ret)
99 (setq rest (put-field (car (nth 2 ret))
100 (cdr (nth 2 ret))
101 rest))
102 )
103 (setq cla (put-field (car cell)(cdr (nth 1 ret)) cla))
104 (setq ins (delete-field (car cell) ins))
105 )
106 (throw 'tag nil)
107 ))
108 (setq r (cdr r))
109 )
110 (setq r (copy-alist ins))
111 (while r
112 (setq cell (car r))
113 (setq aret (fetch-field (car cell) cla))
114 (if aret
115 (if (setq ret (field-unify cell aret))
116 (progn
117 (if (car ret)
118 (setq prev (put-field (car (car ret))
119 (cdr (car ret))
120 prev))
121 )
122 (if (nth 2 ret)
123 (setq rest (put-field (car (nth 2 ret))
124 (cdr (nth 2 ret))
125 rest))
126 )
127 (setq cla (delete-field (car cell) cla))
128 (setq ins (put-field (car cell)(cdr (nth 1 ret)) ins))
129 )
130 (throw 'tag nil)
131 ))
132 (setq r (cdr r))
133 )
134 (list prev (append cla ins) rest)
135 )))
136
137 (defun get-unified-alist (db al)
138 (let ((r db) ret)
139 (catch 'tag
140 (while r
141 (if (setq ret (nth 1 (assoc-unify (car r) al)))
142 (throw 'tag ret)
143 )
144 (setq r (cdr r))
145 ))))
146
147 (defun delete-atype (atl al)
148 (let* ((r atl) ret oal)
149 (setq oal
150 (catch 'tag
151 (while r
152 (if (setq ret (nth 1 (assoc-unify (car r) al)))
153 (throw 'tag (car r))
154 )
155 (setq r (cdr r))
156 )))
157 (delete oal atl)
158 ))
159
160 (defun remove-atype (sym al)
161 (and (boundp sym)
162 (set sym (delete-atype (eval sym) al))
163 ))
164
165 (defun replace-atype (atl old-al new-al)
166 (let* ((r atl) ret oal)
167 (if (catch 'tag
168 (while r
169 (if (setq ret (nth 1 (assoc-unify (car r) old-al)))
170 (throw 'tag (rplaca r new-al))
171 )
172 (setq r (cdr r))
173 ))
174 atl)))
175
176 (defun set-atype (sym al &rest options)
177 (if (null (boundp sym))
178 (set sym al)
179 (let* ((replacement (memq 'replacement options))
180 (ignore-fields (car (cdr (memq 'ignore options))))
181 (remove (or (car (cdr (memq 'remove options)))
182 (let ((ral (copy-alist al)))
183 (mapcar (function
184 (lambda (type)
185 (setq ral (del-alist type ral))
186 ))
187 ignore-fields)
188 ral)))
189 )
190 (set sym
191 (or (if replacement
192 (replace-atype (eval sym) remove al)
193 )
194 (cons al
195 (delete-atype (eval sym) remove)
196 )
197 )))))
198
199
200 ;;; @ end 56 ;;; @ end
201 ;;; 57 ;;;
202 58
203 (provide 'tl-atype) 59 (provide 'tl-atype)
204 60