1 ;;; calist.el --- Condition functions
3 ;; Copyright (C) 1998 MORIOKA Tomohiko.
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Keywords: condition, alist, tree
8 ;; This file is part of APEL (A Portable Emacs Library).
10 ;; This program is free software; you can redistribute it and/or
11 ;; modify it under the terms of the GNU General Public License as
12 ;; published by the Free Software Foundation; either version 2, or (at
13 ;; your option) any later version.
15 ;; This program is distributed in the hope that it will be useful, but
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ;; General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 (eval-when-compile (require 'cl))
29 (defun ctree-match-calist (rule-tree alist)
30 "Return matched condition-alist if ALIST matches RULE-TREE."
33 (let* ((type (car rule-tree))
34 (values (cdr rule-tree))
35 (k-value (assoc type alist)))
38 (let ((cell (car values)))
44 (cons (cons type (car cell)) alist))
45 (cons (cons type (car cell)) alist)
50 (ctree-match-calist (cdr cell) alist)
53 ((equal (car cell) (cdr k-value))
56 (ctree-match-calist (cdr cell) alist)
60 (setq values (cdr values))))
63 (defun calist-to-ctree (calist)
64 "Convert condition-alist CALIST to condition-tree."
66 (let* ((cell (car calist)))
68 (list (cons (cdr cell)
69 (calist-to-ctree (cdr calist))
72 (defun ctree-add-calist-strictly (ctree calist)
73 "Add condition CALIST to condition-tree CTREE without default clause."
74 (cond ((null calist) ctree)
76 (calist-to-ctree calist)
79 (let* ((type (car ctree))
81 (ret (assoc type calist)))
85 (let ((cell (car values)))
86 (if (equal (car cell)(cdr ret))
89 (ctree-add-calist-strictly
91 (delete ret (copy-alist calist)))
93 (setq values (cdr values)))
94 (setcdr ctree (cons (cons (cdr ret)
96 (delete ret (copy-alist calist))))
101 (let ((cell (car values)))
103 (ctree-add-calist-strictly (cdr cell) calist))
105 (setq values (cdr values))))
109 (defun ctree-add-calist-with-default (ctree calist)
110 "Add condition CALIST to condition-tree CTREE with default clause."
111 (cond ((null calist) ctree)
113 (let* ((cell (car calist))
118 (cons value (calist-to-ctree (cdr calist)))))
121 (let* ((type (car ctree))
123 (ret (assoc type calist)))
127 (let ((cell (car values)))
128 (if (equal (car cell)(cdr ret))
131 (ctree-add-calist-with-default
133 (delete ret (copy-alist calist)))
135 (setq values (cdr values)))
136 (setcdr ctree (list* '(t)
139 (delete ret (copy-alist calist))))
144 (let ((cell (car values)))
146 (ctree-add-calist-with-default (cdr cell) calist))
148 (setq values (cdr values)))
149 (let ((elt (cons t (calist-to-ctree calist))))
150 (or (member elt (cdr ctree))
151 (setcdr ctree (cons elt (cdr ctree)))
156 (defun ctree-set-calist-strictly (ctree-var calist)
157 "Set condition CALIST in CTREE-VAR without default clause."
159 (ctree-add-calist-strictly (symbol-value ctree-var) calist)))
161 (defun ctree-set-calist-with-default (ctree-var calist)
162 "Set condition CALIST to CTREE-VAR with default clause."
164 (ctree-add-calist-with-default (symbol-value ctree-var) calist)))
172 ;;; calist.el ends here