CoCoA:Shape

From ApCoCoAWiki
Revision as of 10:02, 24 October 2007 by XMLBot (talk | contribs) (pushing XML rev. 1.46, again)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Shape

extended list of types involved in an expression

Description

This function returns the extended list of types involved in the

expression E as outlined below:

<verbatim> Type(E) = LIST

 In this case, Shape(E) is the list whose i-th component is the type
 of  the i-th component of E.

Type(E) = MAT

 In this case, Shape(E) is a matrix with (i,j)-th entry equal to the
 type of the (i,j)-th entry of E.

Type(E) = RECORD

 In this case, Shape(E) is a record whose fields are the types of the
 fields of E.

</verbatim> Otherwise, Shape(E) is the type of E.

Example

  Use R ::= Q[x];
  L := [1,[1,<quotes>a</quotes>],x^2-x];
  Shape(L);
[INT, [INT, STRING], POLY]
-------------------------------
  R := Record[Name = <quotes>test</quotes>, Contents = L];
  Shape(R);
Record[Contents = [INT, [INT, STRING], POLY], Name = STRING]
-------------------------------
  It.Name;
STRING
-------------------------------

There are undocumented functions, IsSubShape and IsSubShapeOfSome, for determining if the shape of a CoCoA expression is a subshape of another. To see the code for these functions, enter <verbatim> Describe Function("$misc.IsSubShape"); Describe Function("$misc.IsSubShapeOfSome"); </verbatim>

Syntax

Shape(E:LIST):LIST (of TYPE)
Shape(E:MAT):MAT (of TYPE)
Shape(E:RECORD):RECORD (of TYPE)
Shape(E:OTHER):TYPE

where OTHER stands for a type which is not LIST, MAT, or RECORD.

Data Types

   <type>type</type>