]>
We have already seen in the last section ugTypesBasic several examples of types. Most of these examples had either no arguments (for example, Integer) or one argument (for example, Polynomial (Integer)). In this section we give details about writing arbitrary types. We then define modes and discuss how to write them. We conclude the section with a discussion on constructor abbreviations.
When might you need to write a type or mode? You need to do so when you declare variables.
You need to do so when you declare functions (See Section ugTypesDeclare ),
You need to do so when you convert an object from one type to another (See Section ugTypesConvert ).
You need to do so when you give computation target type information (See Section ugTypesPkgCall ).
A constructor with no arguments can be written either type:using parentheses with or without parentheses:using with types trailing opening and closing parentheses ``()''.
Boolean() is the same as Boolean
Integer() is the same as Integer
String() is the same as String
Void() is the same as Void
It is customary to omit the parentheses.
A constructor with one argument can frequently be type:using parentheses written with no parentheses:using with types parentheses. Types nest from right to left so that Complex Fraction Polynomial Integer is the same as Complex (Fraction (Polynomial (Integer))). You need to use parentheses to force the application of a constructor to the correct argument, but you need not use any more than is necessary to remove ambiguities.
Here are some guidelines for using parentheses (they are possibly slightly more restrictive than they need to be).
If the argument is an expression like then you must enclose the argument in parentheses.
If the type is to be used with package calling then you must enclose the argument in parentheses.
Alternatively, you can write the type without parentheses then enclose the whole type expression with parentheses.
If you supply computation target type information (See Section ugTypesPkgCall ) then you should enclose the argument in parentheses.
If the type itself has parentheses around it and we are not in the case of the first example above, then the parentheses can usually be omitted.
If the type is used in a declaration and the argument is a single-word type, integer or symbol, then the parentheses can usually be omitted.
If a constructor type:using parentheses has more than parentheses:using with types one argument, you must use parentheses. Some examples are
UnivariatePolynomial(x, Float)
MultivariatePolynomial([z,w,r], Complex Float)
SquareMatrix(3, Integer)
FactoredFunctions2(Integer,Fraction Integer)
A mode is a type that possibly is a question mark (?) or
contains one in an argument position. For example, the following are
all modes.
?
Polynomial ?
Matrix Polynomial ?
SquareMatrix(3,?)
Integer
OneDimensionalArray(Float)
As is evident from these examples, a mode is a type with a part that is not specified (indicated by a question mark). Only one ``?'' is allowed per mode and it must appear in the most deeply nested argument that is a type. Thus ?(Integer), Matrix(? (Polynomial)), SquareMatrix(?, Integer) (it requires a numeric argument) and SquareMatrix(?, ?) are all invalid. The question mark must take the place of a domain, not data. This rules out, for example, the two SquareMatrix expressions.
Modes can be used for declarations (See Section ugTypesDeclare ) and conversions (Section ugTypesConvert ). However, you cannot use a mode for package calling or giving target type information.
Every constructor has an abbreviation that abbreviation:constructor you can freely constructor:abbreviation substitute for the constructor name. In some cases, the abbreviation is nothing more than the capitalized version of the constructor name.
Aside from allowing types to be written more concisely, abbreviations are used by Axiom to name various system files for constructors (such as library filenames, test input files and example files). Here are some common abbreviations.
COMPLEX abbreviates Complex | DFLOAT abbreviates DoubleFloat |
EXPR abbreviates Expression | FLOAT abbreviates Float |
FRAC abbreviates Fraction | INT abbreviates Integer |
MATRIX abbreviates Matrix | NNI abbreviates NonNegativeInteger |
PI abbreviates PositiveInteger | POLY abbreviates Polynomial |
STRING abbreviates String | UP abbreviates UnivariatePolynomial |
You can combine both full constructor names and abbreviations in a type expression. Here are some types using abbreviations.
POLY INT | is the same as | Polynomial(INT) |
POLY(Integer) | is the same as | Polynomial(Integer) |
POLY(Integer) | is the same as | Polynomial(INT) |
FRAC(COMPLEX(INT)) | is the same as | Fraction Complex Integer |
FRAC(COMPLEX(INT)) | is the same as | FRAC(Complex Integer) |
There are several ways of finding the names of constructors and their abbreviations. For a specific constructor, use )abbreviation query. abbreviation You can also use the )what system command to see the names and abbreviations of constructors. what For more information about )what, see ugSysCmdwhat .
)abbreviation query can be abbreviated (no pun intended) to )abb q.
The )abbreviation query command lists the constructor name if you give the abbreviation. Issue )abb q if you want to see the names and abbreviations of all Axiom constructors.
Issue this to see all packages whose names contain the string ``ode''. what packages