1 / 9

Artificial Intelligence Lecture No. 25

Artificial Intelligence Lecture No. 25. Dr. Asad Ali Safi ​ Assistant Professor, Department of Computer Science,  COMSATS Institute of Information Technology (CIIT) Islamabad, Pakistan. Summary of Previous Lecture. readline function (assert-string) Functions. Today’s Lecture.

opal
Télécharger la présentation

Artificial Intelligence Lecture No. 25

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Artificial IntelligenceLecture No. 25 Dr. Asad Ali Safi ​ Assistant Professor, Department of Computer Science,  COMSATS Institute of Information Technology (CIIT) Islamabad, Pakistan.

  2. Summary of Previous Lecture • readline function • (assert-string) • Functions

  3. Today’s Lecture • If...then...else Function • While loop • Functions • Loop-for-count • Defining functions

  4. If...then...else Function • The if function provides an if...then...else structure to allow for conditional execution of a set of actions. • Syntax (if <expression>then<action>*[else<action>*]) • Any number of allowable actions may be used inside of the then or else portion, including another if...then...else structure. The else portion is optional. • If <expression> evaluates to anything other than the symbol FALSE, then the actions associated with the then portion are executed. Otherwise, the actions associated with the else portion are executed. The return value of the if function is the value of the last <expression> or <action> evaluated.

  5. While loop • The while function is provided to allow simple looping. Its use is similar to that of the if function. • Syntax (while <expression> [do]<action>*) • Again, all predicate functions are available for use in while. Any number of allowable actions may be placed inside the while block, including if...then...else or additional while structures. • The test is performed prior to the first execution of the loop. The actions within the while loop are executed until <expression> evaluates to the symbol FALSE. • The while may optionally include the symbol do after the condition and before the first action. The break and return functions can be used to terminate the loop prematurely. The return value of this function is FALSE unless the return function is used to terminate the loop.

  6. Loop-for-count • The loopforcount function is provided to allow simple iterative looping. • Syntax (loop-for-count <range-spec> [do] <action>*) <range-spec> ::= <end-index> | (<loop-variable> [<start-index> <end-index>]) <start-index> ::= <integer-expression> <end-index> ::= <integer-expression> • Performs the given actions the number of times specified by <range- spec>. If <start- index> is not given, it is assumed to be one. If <start- index> is less than <end- index>, then the body of the loop is never executed. • The integer value of the current iteration can be examined with the loop variable, if specified. • The break and return functions can be used to terminate the loop prematurely. The return value of this function is FALSE unless the return function is used to terminate the loop. Variables from an outer scope may be used within the loop, but the loop variable (if specified) masks any outer variables of the same name. Loops can be nested.

  7. Defining functions • CLIPS allow You to define your own functions with deffunction • General syntax of a deffunction: (deffunction <function-name> (?arg1 ?arg2 .$?argN]) ; last one may be optional multifield (<action 1> <action 2> ... <action K>) ; last action returns value • The names of arguments will not conflict with variable names in a rule if they are the same. • The deffunction will only return the value of the last action; it may be a function, variable or a constant. Let's check simple example:

  8. Other functions • (str-cat "use" "ful" "ness") • (sub-string 4 6 "abcdefghijkl") • (upcase "This is a test of upcase") • (lowcaseA_Word_Test_for_Lowcase) ; one argument only • (first$ (create$ a b c d) ) • (length$ (create$ a b c d) ) • (insert$ (create$ a e f) 2 (create$ b c d))

  9. Summery of Today’s Lecture • If...then...else Function • While loop • Functions • Loop-for-count • Defining functions

More Related