Type specifiers in Lisp
OverviewType specifier symbols, Lists
 Predicating Type specifies
 Type specifies:
That Combine
That specialize
That abbreviate
 Defining new type specifies
 Type conversion function
 Type upgradingThe common Lisp system maps the space classes into the Common Lisp type space.Every class that has a common name has a corresponding type with the same name.The proper name of every class is a valid type specifier.In addition, every class object is a valid class specifier.
Type specifier symbolsStandard type specifier symbols are:array fixnum package simple-stringatom float pathname simple-vectorbignum function random-state single-floatBit hash-table ratio standard-charBit -vector integer rational streamcharacter keyword readtable string[common ] list sequence string charCompiled-function long-float short-float symbolcomplex nil signed-byte tcons null simple-array unsigned-byteDouble-float number simple-bit-vector vector
Type specifier Lists If the Type specifier is a list, the car of the list is a symbol, and the rest of the list is the subsidiary type information.
 The unspecified subsidiary items are indicated using the *Ex: To completely specify the vector type, one must mention the type of the elements and length of the vector( vector float 100) to leave the length part unspecified use(vector float *) To leave the element type unspecified use( vector * 100)
Predicating type specifiesA type specifier (satisfies predicate-name) denotes the set of all objects that satisfy the predicate named by the predicate-name, which must be a symbol whose global function definition is a one-argument predicate.
The call (typep x ‘ (satisfies p)) assigns p to x and returns t if true and returns nil if the result is false.Ex: (deftype string-char() ' (and character (satisfies string-char-p))) STRING-CHAR
Type specifies that combineThe following type specifier type defines a type in terms of other types or objects.(member object1 object2 ….)This denotes the set containing those objects named, an object is of this type if and only if it is eql to those specified objects. (not type) denotes the set of all objects that are not in the specified type.(and type1 type2 ….) denotes the intersection of the specified objects.(or type1 type2 ….) denotes the union of the specified types.
Type specifies that specialize Some type specifier lists denote the specializations of the data types denoted by the symbols.
 Types can be of two different purposes:
 declaration( declaring to make array that elements will always be of type short-float permits optimization.)

LISP: Type specifiers in lisp

  • 1.
  • 2.
  • 3.
  • 4.
    Typespecifies:
  • 5.
  • 6.
  • 7.
  • 8.
    Defining newtype specifies
  • 9.
  • 10.
    Type upgradingThecommon Lisp system maps the space classes into the Common Lisp type space.Every class that has a common name has a corresponding type with the same name.The proper name of every class is a valid type specifier.In addition, every class object is a valid class specifier.
  • 11.
    Type specifier symbolsStandardtype specifier symbols are:array fixnum package simple-stringatom float pathname simple-vectorbignum function random-state single-floatBit hash-table ratio standard-charBit -vector integer rational streamcharacter keyword readtable string[common ] list sequence string charCompiled-function long-float short-float symbolcomplex nil signed-byte tcons null simple-array unsigned-byteDouble-float number simple-bit-vector vector
  • 12.
    Type specifier ListsIf the Type specifier is a list, the car of the list is a symbol, and the rest of the list is the subsidiary type information.
  • 13.
    The unspecifiedsubsidiary items are indicated using the *Ex: To completely specify the vector type, one must mention the type of the elements and length of the vector( vector float 100) to leave the length part unspecified use(vector float *) To leave the element type unspecified use( vector * 100)
  • 14.
    Predicating type specifiesAtype specifier (satisfies predicate-name) denotes the set of all objects that satisfy the predicate named by the predicate-name, which must be a symbol whose global function definition is a one-argument predicate.
  • 15.
    The call (typep x ‘ (satisfies p)) assigns p to x and returns t if true and returns nil if the result is false.Ex: (deftype string-char() ' (and character (satisfies string-char-p))) STRING-CHAR
  • 16.
    Type specifies thatcombineThe following type specifier type defines a type in terms of other types or objects.(member object1 object2 ….)This denotes the set containing those objects named, an object is of this type if and only if it is eql to those specified objects. (not type) denotes the set of all objects that are not in the specified type.(and type1 type2 ….) denotes the intersection of the specified objects.(or type1 type2 ….) denotes the union of the specified types.
  • 17.
    Type specifies thatspecialize Some type specifier lists denote the specializations of the data types denoted by the symbols.
  • 18.
    Types canbe of two different purposes:
  • 19.
    declaration( declaring to make array that elements will always be of type short-float permits optimization.)
  • 20.
    discrimination Few validlist-format names(array element-name dimensions) set of specialized arrays whose elements are all members of type element-type and whose dimensions match dimensions.Element type must be a valid type specifier or unspecified, dimensions may be the number of dimensions or it may be the list representing the length of each dimension.Ex: (array integer 3)  3-dimensional array integers. (array integer(* * *))  3-dimensional array of integers.
  • 21.
    (vector element-type size) set of one dimensional arrays whose elements are of type element type and whose length is eq ti size.Ex: (vector *5) vector of length 5 ( vector double-float) floating-point numbers.(simple-vector size)  specifies that the elements are of simple general vectors.(complex type1)  every element of this type is a complex number whose real part and imaginary part are each of type type1)
  • 22.
    (function (arg1-type, arg2-type,….)value-type) each element is a function that accepts the arguments of the types specified by the argj-type forms and returns a value that is a member of the type specialized by the value-type.(values value1-type, value2-type,….)This type specifier is extremely restricted, it is used to special individual types when multiple values are restricted.
  • 23.
    the &optional,&rest, &key markers may appear in the value-type list.Type specifies That abbreviateThe following are some of the type specifies that are used as abbreviations in Common Lisp.(integer low high)used to denote integers between low and high.(float low high) used to denote floating point numbers between low and high.(mod n)the set of non-negative integers less than n(single-byte s) set of integers that can be represented in 2’s compliment form.
  • 24.
    (unsigned-byte s) setof non-negative integers that can be represented in a byte of s bits.(string size) set of strings of indicated size.(base-string size) set of base strings of indicated size(bit-vector size)set of bit-vectors of indicated size.
  • 25.
    Defining new typespecifiesNew type specifies can come in two ways: defining the new structure type with defstruct automatically causes the name of the structure to be a new type specifier symbol.
  • 26.
    the deftypespecial form can be used to define new type-specifier abbreviations.Syntax: deftype name lambda-list [{declaration}* | doc-string ] {form}* [macro]Name is the symbol that identifies the type specifierForm constitutes the body of expander functionEx: (deftype mod (n) ‘ (integer 0 ( ,n)))
  • 27.
    Type conversion functionThefollowing function is used to convert an object to an equivalent object of the other type.Coerce object result-typeThe result-type must be a type specifier.A sequence type is converted into another sequence type provided the new sequence contains all the actual elements of the old sequence.Ex:(coerce '(a b c) ' vector)#(A B C)Some strings, symbols and integers may be converted into characters.Ex:(coerce "b" 'character)#\bAny number can be converted into a complex number.Ex:(coerce 4.5s0 ‘complex)#c(4.5S0 0.0S0)
  • 28.
    Type upgradingFunction syntax:Upgraded-element-typetypeA type specifier is returned indicating the element type of the most specialized array representation capable of holding items of the specified argument type. The manner in which an array element type is being upgraded depends only on the element type.upgraded array element type is defined as:(defun upgraded-array-element-type (type) (array-element-type ( make-array 0 :element–type type ))) Upgraded-complex-part-type type a type specifier is returned indicating the element type of the most specialized complex number representation capable of having the parts of the specified arguments type.Visit more self help tutorialsPick a tutorial of your choice and browse through it at your own pace.The tutorials section is free, self-guiding and will not involve any additional support.Visit us at www.dataminingtools.net