Your SlideShare is downloading. ×
LISP: Type specifiers in lisp
Upcoming SlideShare
Loading in...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.

Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

LISP: Type specifiers in lisp


Published on

LISP: Type specifiers in lisp

LISP: Type specifiers in lisp

Published in: Technology, Sports
  • Be the first to comment

  • Be the first to like this

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

No notes for slide


  • 1. Type specifiers in Lisp
  • 2. Overview
    • Type specifier symbols, Lists
    • 3. Predicating Type specifies
    • 4. Type specifies:
    • 5. That Combine
    • 6. That specialize
    • 7. That abbreviate
    • 8. Defining new type specifies
    • 9. Type conversion function
    • 10. Type upgrading
  • The 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.
  • 11. Type specifier symbols
    Standard type specifier symbols are:
    array fixnum package simple-string
    atom float pathname simple-vector
    bignum function random-state single-float
    Bit hash-table ratio standard-char
    Bit -vector integer rational stream
    character keyword readtable string
    [common ] list sequence string char
    Compiled-function long-float short-float symbol
    complex nil signed-byte t
    cons null simple-array unsigned-byte
    Double-float number simple-bit-vector vector
  • 12. 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.
    • 13. 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)
  • 14. Predicating type specifies
    • 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. 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)))
  • 16. Type specifies that combine
    • The 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 that specialize
    • Some type specifier lists denote the specializations of the data types denoted by the symbols.
    • 18. Types can be of two different purposes:
    • 19. declaration( declaring to make array that elements will always be of type short-float permits optimization.)
    • 20. discrimination
  • Few valid list-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 abbreviate
    The 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) set of 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 type specifies
    New 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 deftype special 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 specifier
    Form constitutes the body of expander function
    Ex: (deftype mod (n) ‘ (integer 0 ( ,n)))
  • 27. Type conversion function
    The following function is used to convert an object to an equivalent object of the other type.
    Coerce object result-type
    The 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.
    (coerce '(a b c) ' vector)
    • #(A B C)
    • Some strings, symbols and integers may be converted into characters.
    (coerce "b" 'character)#
    • Any number can be converted into a complex number.
    (coerce 4.5s0 ‘complex)#c(4.5S0 0.0S0)
  • 28. Type upgrading
    Function syntax:
    Upgraded-element-type type
    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 tutorials
    Pick 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