2 ;;; $Id: tl-list.el,v 2.0 1994/11/08 11:14:20 morioka Exp $
14 "Returns the last element in the list <LIST>.
15 [mol's Common Lisp emulating function]"
16 (nthcdr (- (length list) 1) list)
19 (defun butlast (x &optional n)
20 "Returns a copy of LIST with the last N elements removed.
21 [tl-list.el: imported from cl.el]"
22 (if (and n (<= n 0)) x
23 (nbutlast (copy-sequence x) n)))
25 (defun nbutlast (x &optional n)
26 "Modifies LIST to remove the last N elements.
27 [tl-list.el: imported from cl.el]"
32 (if (> n 0) (setcdr (nthcdr (- (1- m) n) x) nil))
39 (defun put-alist (item value alist)
40 "If there is a pair whose car is <ITEM>, replace its cdr by <VALUE>.
41 If there is not such pair, create new pair (<ITEM> . <VALUE>) and
42 return new alist whose car is the new pair and cdr is <ALIST>.
43 [mol's ELIS emulating function]"
44 (if (assoc item alist)
46 (rplacd (assoc item alist) value)
48 (cons (cons item value) alist)
51 (defun del-alist (item alist)
52 "If there is a pair whose key is <ITEM>, delete it from <ALIST>.
53 [mol's ELIS emulating function]"
54 (if (equal item (car (car alist)))
61 (if (equal item (car (car r)))
70 (defun set-alist (sym item value)
71 (if (not (boundp sym))
74 (set sym (put-alist item value (eval sym)))
81 (defun fetch-field (key alist)
84 (fset 'put-field 'put-alist)
85 (fset 'delete-field 'del-alist)
91 (defun field-unifier-for-default (a b)
101 (defun field-unify (a b)
102 (let ((sym (symbol-concat "field-unifier-for-" (car a))))
103 (if (not (fboundp sym))
104 (setq sym (function field-unifier-for-default))
113 (defun assoc-unify (class instance)
115 (let ((cla (copy-alist class))
116 (ins (copy-alist instance))
118 cell aret ret prev rest)
121 (setq aret (fetch-field (car cell) ins))
123 (if (setq ret (field-unify cell aret))
126 (setq prev (put-field (car (car ret))
131 (setq rest (put-field (car (nth 2 ret))
135 (setq cla (put-field (car cell)(cdr (nth 1 ret)) cla))
136 (setq ins (delete-field (car cell) ins))
142 (setq r (copy-alist ins))
145 (setq aret (fetch-field (car cell) cla))
147 (if (setq ret (field-unify cell aret))
150 (setq prev (put-field (car (car ret))
155 (setq rest (put-field (car (nth 2 ret))
159 (setq cla (delete-field (car cell) cla))
160 (setq ins (put-field (car cell)(cdr (nth 1 ret)) ins))
166 (list prev (append cla ins) rest)
169 (defun get-unified-alist (db al)
173 (if (setq ret (nth 1 (assoc-unify (car r) al)))
179 (defun set-atype (sym al)
180 (if (null (boundp sym))
182 (let ((ret (get-unified-alist (eval sym) al)))
183 (if (not (equal ret al))
184 (set sym (cons al (eval sym)))