Presentation is loading. Please wait.

Presentation is loading. Please wait.

Logical functions and - Logical AND function. Example: (and (> 5 4) (< 5 4)) or - Logical OR function. Example: (and (> 5 4) (< 5 4)) not - Logical negation.

Similar presentations


Presentation on theme: "Logical functions and - Logical AND function. Example: (and (> 5 4) (< 5 4)) or - Logical OR function. Example: (and (> 5 4) (< 5 4)) not - Logical negation."— Presentation transcript:

1 Logical functions and - Logical AND function. Example: (and (> 5 4) (< 5 4)) or - Logical OR function. Example: (and (> 5 4) (< 5 4)) not - Logical negation. Example: (not (> 5 4))

2 Conditionals - when, unless (when condition statements) (when t (print “true”)) (when nil (print “true”)) (unless condition statements) (unless t (print “true”)) (unless nil (print “true”))

3 Conditionals - cond COND - This is similar to the familiar switch construct that you have encountered. Here is the syntax: (cond (cond1 command1) (cond1 command2) ……… )

4 Conditionals - cond Example of COND in use: (setq a 3) (cond ((evenp a) a) ;if a is even, return a ((> a 7) (/ a 2)) ((< a 5) (+ a 1)) (t 1000) )

5 Conditionals - case The LISP case statement is similar to that of C’s. For example: (setq greeting ‘n) (case greeting (m “Good morning”) (e “Good evening”) (n “Good nite”) )

6 Program block - progn Sometimes we may need to use more than one statement within the then and/or the else clause of an if statement. To achieve this, use the progn construct. For example: (if (> a 5) (progn (setq a (+ b 7)) (setq b (+ c 8))) (setq b 4)) ; the else clause The then clause


Download ppt "Logical functions and - Logical AND function. Example: (and (> 5 4) (< 5 4)) or - Logical OR function. Example: (and (> 5 4) (< 5 4)) not - Logical negation."

Similar presentations


Ads by Google