Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.

Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.

Like this presentation? Why not share!

5,640 views

5,446 views

5,446 views

Published on

LISP:Predicates in lisp

No Downloads

Total views

5,640

On SlideShare

0

From Embeds

0

Number of Embeds

10

Shares

0

Downloads

0

Comments

0

Likes

1

No embeds

No notes for slide

- 1. Predicates in Lisp<br />
- 2. Predicates<br />A predicate is a function used to test for some condition involving its arguments and returns nil if the condition is false, or some non-nil value if the condition is true.<br />Name of the predicates in CL usually ends with p.<br />Ex: numberp, standard-char-p etc.<br />
- 3. overview<br />Logical values<br />Data Type predicates<br />General Type Predicates<br />Specific data type predicates<br />Equality predicates<br />Logical operators<br />
- 4. Logical values<br />The names nil and t are constants in Lisp<br />This object represents logical false value and also the empty list.<br />It can also be written as ()<br />The values of nil and t are not permitted to be changed.<br />Data type predicates:<br />using data type predicates one can determine<br /> whether or not it belongs to a given type, or one <br /> can compare two type specifies.<br />
- 5. General Type predicates<br />Syntax:<br />typep object type<br />Typep is the predicate that is true if the object is of type type false otherwise.<br />Subtypep type1 type2<br /><ul><li>This predicate returns T if type1 is a subtype of type1 else it returns nil.</li></ul>Ex: (subtypep t t) returns T<br />
- 6. Subtypep are supposed to return a second value of nil unless one or both of its arguments involves satisfies and, or, not or member.<br />Subtypep should signal an error when one or both of its arguments involves values or the list form of the function type specifier<br />Subtypep must always return the two values t and t in the case where its arguments, after expansion of specifies defined by deftype are equal.<br />(subtypep ‘(array A) ‘ (array B)) is true if and only if (upgraded-array-element-type ‘A) is the same type as (upgraded-array-element-type ‘ b)<br />(subtypep ‘ (complex A) ‘ (complex B)) is true if and only if (upgraded-complex-part-type ‘A) and (upgraded-complex-part-type ‘B) is of same type.<br />
- 7. Specific data type predicates<br />The following data types test for specific individual data types.<br />null object returns true if the argument is () or false otherwise.<br />symbolp object returns true if the argument is a symbol else returns false<br />atom object is true if the argument is not cons otherwise its false.<br />consp object is true if the argument is a cons, false otherwise<br />listp objectis true if the argument is a cons or an empty list (), false otherwise<br />Numberp object is T if the argument is any kind of number<br />
- 8. Rationalp object is T if the argument is a rational number false otherwise<br />Similarly we have floatp, charaterp, vectorp, stringp, complexp, simple-bit-vector-p, simple-string-vector-p, arrayp etc.<br />packagep object is T if its argument is a package and otherwise is false<br />functionp object is T if its arguments are suitable for applying to arguments, using for ex the funccall or apply function and otherwise is false<br />Compiled-function-p object is T if its argument is any compiled code object and otherwise is false<br />Commonp object is T if its argument is any standard CL data type, and otherwise is false<br />
- 9. Equality predicates<br />Cl provides these predicates to test for the equality of the two objects: eq, eql, equal, equalp <br />eq x y is true if and only if x and y are the same identical objects.<br />Ex: (eq ‘g ‘h) false<br /> (eq 3 3)true<br /> (eq “hi” “HI”) false<br />Eql x y is true if the arguments are eq, or of there are numbers of the same type with the same value, or if there are character objects that represent the same character<br />
- 10. equal x yis true if the arguments are structurally similar objects. (isomorphic objects)<br />Ex: (equal #B #B) true<br /> (equal “FOO” “FOO”) true<br />equalp x y is true if the two objects are equal, and if and only if they are eq that is, the same identical object.<br /> two hash tables are considered the same by equalp if and only if they satisfy the following four conditions:<br /><ul><li>They must be of the same kind ( equivalent :test arguments must be given to make hash-table when the two hash-tables are created.
- 11. They must have the same number of entries.
- 12. For every entry(key1, value1) in one hash table there must be the corresponding entry(key2, value2) in the other hash table.
- 13. For every entry(key1, value1) in one hash table and its corresponding entry(key2, value2) in the other , such that key1 and key2 are the same, equalp must be true of value1 and value2.</li></li></ul><li>Logical operators<br />CL provides three operators as Boolean value: and, or, and not<br />Ex: not y<br /><ul><li>Returns t if y is nil else returns nil.</li></ul>And returns t if the condition is true else NIL.<br />Ex: (and form1, form2,…)<br /><ul><li>Evaluates each form one at the time from left to right. If at least one form returns a nil, the evaluation is stopped by returning a nil.</li></ul>Ex: (and (< 1 2)<br /> (< 3 4)<br /> (princ “true”))<br />true<br /> “true”<br />
- 14. Or operator returns NIL for false conditions and true conditions return non-nil characters<br />(or form1,form2,…..)<br /><ul><li>Performs or operation the forms one by one from left to right. It is true if at least one of the forms are true </li></ul>Ex; (or (< 3 1)<br /> (> 2 1))<br /> T<br />
- 15. 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 />

No public clipboards found for this slide

Be the first to comment