next up previous contents
Next: EXTERNAL and Unification Macros Up: Types in Unification Previous: Typed Constituents: the FSET

    
Procedural Types

Procedural types are defined by a name and a special unification method, optionally a syntax checker function can be declared. The unification method actually defines a partial order over the elements of the type.

          

(DEFINE-PROCEDURAL-TYPE <name> <function> :syntax <checker> :copier <copier>)

Declares <name> to be a special attribute, whose value can only be interpreted by <function>.

The special types are considered `atomic' types (unifier cannot access to components from outside).

The unification procedure must be deterministic (no backtracking allowed) and must be a real `unification' procedure: that is, the type must be a lattice (or partial order).

<FUNCTION> must be a function of 3 args: the vals to unify and the path where the result is to be located in the total fd. It must return :fail if unification fails, otherwise, it must return a valid object of type <type>.

NOTE: <FUNCTION> must be such that NIL is always acceptable as an argument and is always neutral, ie, (<FUNCTION> x nil) = x. NOTE: <FUNCTION> must be such that (<FUNCTION> x x) = x

<CHECKER> must be a function of 1 arg: It must return either True if the object is a syntactically correct element of <TYPE>, otherwise, it must return 2 values: NIL and a string describing the correct syntax of <TYPE>.

<COPIER> must be a function of 1 arg: it must copy an object of <TYPE> that has no cons in common with its argument. By default, COPY-TREE is used.

NOTE: (<COPIER> x) = (<FUNCTION> x nil)

The following example shows one use of procedural types:

          

;; Unification of 2 numbers is the max: order is the total order of ;; arithmetic (which is also a partial order!)

(defun unify-numbers (n1 n2 &optional path) (max n1 n2))

(define-procedural-type 'num 'unify-numbers :syntax 'numberp)

> (u '((num 1)) '((num 2))) ((num 2))

> (u '((num 1)) '((num 0))) ((num 1))

;; Only values of the attribute num can be unified together... ;; a and num are not compatible! > (u '((num {a})) nil) :fail


next up previous contents
Next: EXTERNAL and Unification Macros Up: Types in Unification Previous: Typed Constituents: the FSET
Michael Elhadad - elhadad@cs.bgu.ac.il