Term
Die Klassen für Terme bilden folgende Hierarchie:
- Term (Copyable Unifiable)
- Structure
- TermList
- ConstantOrVariable
- Constant
- Variable
Das wird durch diese Anweisungen erreicht.
(defclass term (copyable unifiable))
(defclass term-list (term))
(defclass structure (term))
(defclass constant-or-variable (term))
(defclass constant (constant-or-variable))
(defclass variable (constant-or-variable))
Eine Termliste enthält eine Liste von Termen.
(defmethod initialize ((this term-list) elements)
(every-is-a? term elements)
(progn
(.= this elements elements)
(freeze this)))
Eine Struktur enthält eine Konstante oder eine Variable und eine Termliste.
(defmethod initialize ((this structure) (head constant-or-variable) (tail term-list))
t
(progn
(.= this head head)
(.= this tail tail)
(freeze this)))
Eine Konstante enthält einen Wert.
(defmethod initialize ((this constant) value)
t
(progn
(.= this value value)
(freeze this)))
Eine Variable enthält einen Namen und einen Namensraum.
(defmethod initialize ((this variable) name namespace)
(symbol? name)
(progn
(.= this name name)
(.= this namespace namespace)
(.= this value nil)
this))
Variablen können Werte besitzen.
(defmethod value-of ((this constant))
t
(. this value))
(defmethod get-value ((this variable))
t
(. this value))
(defmethod set-value ((this variable) (value term))
t
(.= this value value))
(defmethod unset-value ((this variable))
t
(.= this value nil))
Die folgenden Funktionen dienen der Umwandlung der Listendarstellung von Termen in die Instanzdarstellung.
(defproc to-structure (source)
(new structure
(to-constant-or-variable (first source))
(to-term-list (rest source))))
(defproc to-constant-or-variable (source)
(if
(is-variable-name? source)
(freeze (new variable source nil))
(new constant source)))
(defproc is-variable-name? (source)
(and
(symbol? source)
(let
((first-char (substring (write-to-string source) 1 1)))
(search-string first-char "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 1))))
(defproc to-term-list (source)
(new term-list (mapcar to-term source)))
(defproc to-term (source)
(cond
((null? source) (new constant nil))
((list? source) (to-structure source))
(t (to-constant-or-variable source))))
Die Methoden to-list dienen der Umwandlung der Instanzdarstellung von Termen in deren Listendarstellung.
(defmethod to-list ((this structure))
t
(cons
(to-list (. this head))
(to-list (. this tail))))
(defmethod to-list ((this term-list))
t
(map-with to-list (. this elements)))
(defmethod to-list ((this constant))
t
(. this value))
(defmethod to-list ((this variable))
t
(. this name))
- Term (Copyable Unifiable)
- Structure
- TermList
- ConstantOrVariable
- Constant
- Variable
Das wird durch diese Anweisungen erreicht.
(defclass term (copyable unifiable))
(defclass term-list (term))
(defclass structure (term))
(defclass constant-or-variable (term))
(defclass constant (constant-or-variable))
(defclass variable (constant-or-variable))
Eine Termliste enthält eine Liste von Termen.
(defmethod initialize ((this term-list) elements)
(every-is-a? term elements)
(progn
(.= this elements elements)
(freeze this)))
Eine Struktur enthält eine Konstante oder eine Variable und eine Termliste.
(defmethod initialize ((this structure) (head constant-or-variable) (tail term-list))
t
(progn
(.= this head head)
(.= this tail tail)
(freeze this)))
Eine Konstante enthält einen Wert.
(defmethod initialize ((this constant) value)
t
(progn
(.= this value value)
(freeze this)))
Eine Variable enthält einen Namen und einen Namensraum.
(defmethod initialize ((this variable) name namespace)
(symbol? name)
(progn
(.= this name name)
(.= this namespace namespace)
(.= this value nil)
this))
Variablen können Werte besitzen.
(defmethod value-of ((this constant))
t
(. this value))
(defmethod get-value ((this variable))
t
(. this value))
(defmethod set-value ((this variable) (value term))
t
(.= this value value))
(defmethod unset-value ((this variable))
t
(.= this value nil))
Die folgenden Funktionen dienen der Umwandlung der Listendarstellung von Termen in die Instanzdarstellung.
(defproc to-structure (source)
(new structure
(to-constant-or-variable (first source))
(to-term-list (rest source))))
(defproc to-constant-or-variable (source)
(if
(is-variable-name? source)
(freeze (new variable source nil))
(new constant source)))
(defproc is-variable-name? (source)
(and
(symbol? source)
(let
((first-char (substring (write-to-string source) 1 1)))
(search-string first-char "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 1))))
(defproc to-term-list (source)
(new term-list (mapcar to-term source)))
(defproc to-term (source)
(cond
((null? source) (new constant nil))
((list? source) (to-structure source))
(t (to-constant-or-variable source))))
Die Methoden to-list dienen der Umwandlung der Instanzdarstellung von Termen in deren Listendarstellung.
(defmethod to-list ((this structure))
t
(cons
(to-list (. this head))
(to-list (. this tail))))
(defmethod to-list ((this term-list))
t
(map-with to-list (. this elements)))
(defmethod to-list ((this constant))
t
(. this value))
(defmethod to-list ((this variable))
t
(. this name))