This commit was generated by cvs2svn to compensate for changes in r509,
[elisp/tm.git] / tl-list.el
index 5353029..4c2a538 100644 (file)
@@ -1,9 +1,12 @@
 ;;;
-;;; $Id: tl-list.el,v 1.0 1994/09/15 20:42:29 morioka Exp $
+;;; $Id: tl-list.el,v 2.5 1994/12/27 01:49:41 morioka Exp $
 ;;;
 
 (provide 'tl-list)
 
+(require 'tl-str)
+
+
 ;;; @ list
 ;;;
 
           x))))
 
 
+(defun nth-prev (n ls)
+  "Return elements of LS until N - 1 th. [tl-list.el]"
+  (butlast ls (- (length ls) n))
+  )
+
+(defun except-nth (n ls)
+  "Return elements of LS except N th. [tl-list.el]"
+  (append (nth-prev n ls) (nthcdr (+ 1 n) ls))
+  )
+
+(defun last-element (ls)
+  "Return last element. [tl-list.el]"
+  (car (last ls))
+  )
+
+
+;;; @ set
+;;;
+(fset 'is-member 'member)
+
+
 ;;; @ alist
 ;;;
 
@@ -64,16 +88,42 @@ return new alist whose car is the new pair and cdr is <ALIST>.
          )
        alist))))
 
+(defun set-alist (sym item value)
+  (if (not (boundp sym))
+      (set sym nil)
+    )
+  (set sym (put-alist item value (eval sym)))
+  )
 
+      
 ;;; @ field
 ;;;
 
 (defun fetch-field (key alist)
-  (assoc key alist)) 
+  (assoc key alist)
+  )
+
+(defun fetch-field-value (key alist)
+  (cdr (assoc key alist))
+  )
 
 (fset 'put-field 'put-alist)
 (fset 'delete-field 'del-alist)
 
+(defun put-fields (tp c)
+  (catch 'tag
+    (let ((r tp) f ret)
+      (while r
+       (setq f (car r))
+       (if (not (if (setq ret (fetch-field (car f) c))
+                    (equal (cdr ret)(cdr f))
+                  (setq c (cons f c))
+                  ))
+           (throw 'tag 'error))
+       (setq r (cdr r))
+       ))
+    c))
+
 
 ;;; @ field unifier
 ;;;
@@ -155,3 +205,21 @@ return new alist whose car is the new pair and cdr is <ALIST>.
        )
       (list prev (append cla ins) rest)
       )))
+
+(defun get-unified-alist (db al)
+  (let ((r db) ret)
+    (catch 'tag
+      (while r
+       (if (setq ret (nth 1 (assoc-unify (car r) al)))
+           (throw 'tag ret)
+         )
+       (setq r (cdr r))
+       ))))
+
+(defun set-atype (sym al)
+  (if (null (boundp sym))
+      (set sym al)
+    (let ((ret (get-unified-alist (eval sym) al)))
+      (if (not (equal ret al))
+         (set sym (cons al (eval sym)))
+       ))))