• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
LISP: Type specifiers in lisp
 

LISP: Type specifiers in lisp

on

  • 919 views

LISP: Type specifiers in lisp

LISP: Type specifiers in lisp

Statistics

Views

Total Views
919
Views on SlideShare
915
Embed Views
4

Actions

Likes
0
Downloads
0
Comments
0

2 Embeds 4

http://dataminingtools.net 2
http://www.dataminingtools.net 2

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    LISP: Type specifiers in lisp LISP: Type specifiers in lisp Presentation Transcript

    • Type specifiers in Lisp
    • Overview
      • Type specifier symbols, Lists
      • Predicating Type specifies
      • Type specifies:
      • That Combine
      • That specialize
      • That abbreviate
      • Defining new type specifies
      • Type conversion function
      • 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.
    • 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
    • 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 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.
      • 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 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.
    • 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.)
      • 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.
    • (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)
    • (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.
      • 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.
    • (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.
    • 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.
      • 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)))
    • 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.
      Ex:
      (coerce '(a b c) ' vector)
      • #(A B C)
      • Some strings, symbols and integers may be converted into characters.
      Ex:
      (coerce "b" 'character)#
      • Any number can be converted into a complex number.
      Ex:
      (coerce 4.5s0 ‘complex)#c(4.5S0 0.0S0)
    • 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 www.dataminingtools.net