LISP: Type specifiers in lisp

4,019 views
3,888 views

Published on

LISP: Type specifiers in lisp

Published in: Technology, Sports
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
4,019
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

LISP: Type specifiers in lisp

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

×