CL Unification: Class ARRAY-TEMPLATE
 

Class ARRAY-TEMPLATE

Package:

COMMON-LISP.EXTENSIONS.DATA-AND-CONTROL-FLOW.UNIFICATION

Class Precedence List:

ARRAY-TEMPLATE, TYPE-TEMPLATE, TEMPLATE, STANDARD-OBJECT, T.

Known Subclasses:

VECTOR-TEMPLATE.

Slots:

None.

Description:

The ARRAY-TEMPLATE class denotes those object that are used to unify against an ARRAY.

Template Syntax:

  #T(array <shape-template>)
  

  #T(<CL array type specifier> <shape-template>)
  

  #T(array ([* | <CL type specifier>] [<dimension sped>]) <shape-template>)
  

Where <shape-template> can be:

  <shape-template> ::= <sequence-template>
                   |   <destructuring template lambda list>
                   |   (<shape-template>)
  

The ARRAY-TEMPLATE syntax denotes an ARRAY object. An ARRAY-TEMPLATE must be unified against an ARRAY object. The elements of the array must be unified against the <shape-template>. Each row of the array is unified recursively against each element of the <shape-template>.

Examples:

  cl-prompt> (setf e (unify #(0 1 42 3 4 5) #T(array (0 1 ?x 3 4 5))))
  #<ENVIRONMENT xxx>
  
  cl-prompt> (find-variable-value '?x e)
  42

  cl-prompt> (setq e (unify #(0 1 42 3 4 5)  #T(array (0 1 "FOO" 3 4 5))))
  --> Error: UNIFICATION-FAILURE

  cl-prompt> (setq e (unify #2A((0 1 42) (3 4 5)) #T(array ((0 1 ?x) (3 4 5)))))
  #<ENVIRONMENT xxx>

  cl-prompt> (find-variable-value '?x e)
  42

  cl-prompt> (setq e (unify #2A(("foo" "bar" 42) (3 4 5)) #T(array ((_ _ ?x) (3 4 5)))))
  #<ENVIRONMENT xxx>

  cl-prompt> (find-variable-value '?x e)
  42

  cl-prompt> (setq e (unify #2A(("foo" "bar" 42) (3 4 5)) #T(array (#T(vector _ &rest ?x) (3 4 5)))))
  #<ENVIRONMENT xxx>

  cl-prompt> (find-variable-value '?x e)
  #("bar" 42)
  

Affected By:

None.

Exceptional Situations:

Unifying an ARRAY-TEMPLATE against a non-ARRAY object results in an UNIFICATION-FAILURE error being signaled.

See Also:

UNIFY

Notes:

Syntax Note

The ARRAY-TEMPLATE syntax tries to be easy to use, at the cost of being overloaded. There is no actual need to have the separate forms (array (fixnum) ...) and ((array fixnum) ...).

In a future release they may be conflated. For the time being they are kept separate as it is unclear which would be better to provide.

Elements Unification

It would be nice to have the possibility to unify against slices of the array. Alas, this seems non trivial to get right, and it is left as a future extension of the semantics of <shape-template>.

ARRAY Structural Properties

There is no way to "unify" against structural properties of vectors like fill pointers and displacements.