Page 70 - DCAP310_INTRODUCTION_TO_ARTIFICIAL_INTELLIGENCE_AND_EXPERT_SYSTEMS
P. 70

Introduction to Artificial Intelligence & Expert Systems




                    Notes          There are two basic types of predicates in LISP: Data-type predicates and equality predicates.
                                   Data-type predicates take one argument and determine whether or not that argument qualifies
                                   as the specified datatype. Here are some examples:
                                     > (numberp 5)
                                     T
                                     > (numberp ‘FIVE)
                                     NIL
                                     > (stringp “hello, world”)
                                     T
                                     > (stringp 100)
                                     NIL
                                   “numberp” is a predicate function that returns T if the argument is a number, and NIL if it is not.
                                   Likewise, “stringp” determines whether or not the argument is a string. Most data-type predicates
                                   are written with the convention seen above; namely, the data-type name followed by a “p” for
                                   predicate. The two common exceptions are “null” which determines whether or not an expression
                                   evaluates to NIL, and “atom” which determines whether or not the argument is an atom (a
                                   single value, indivisible into smaller parts...basically, not a list). Here are some common data-
                                   type predicates built into the lisp language:
                                     null
                                     symbolp
                                     atom
                                     consp
                                     listp
                                     numberp
                                     integerp
                                     rationalp
                                     floatp
                                     complexp
                                     characterp
                                     stringp
                                     vectorp
                                     arrayp
                                     functionp

                                   Self Assessment

                                   State whether the following statements are true or false:
                                   9.  The primary command for taking a list apart is the “Cdr” function.

                                   10.  Zero is the first element.
                                   11.  Most programs can be written without branching at some point.
                                   12.  Most data-type predicates are written with the convention.

                                   4.4 Functions

                                   LISP is a language that is usually associated with the “Functional Programming” paradigm. For
                                   those of you who aren’t familiar with that term, functional programming takes a problem and
                                   models it as mathematical functions for evaluation. This is in contrast to imperative programming
                                   where “state” is the focus, and the outcome of a program is modeled in changes of state. As a
                                   primarily-functional programming language, the most important building block of a LISP
                                   program is the function, so here we’re going to talk about the specifics of defining new functions
                                   and using them.






          64                                LOVELY PROFESSIONAL UNIVERSITY
   65   66   67   68   69   70   71   72   73   74   75