Logical functions - PowerPoint PPT Presentation

1 / 6
About This Presentation
Title:

Logical functions

Description:

COND - This is similar to the familiar switch construct that you have encountered. ... achieve this, use the progn construct. For example: (if ( a 5) (progn ... – PowerPoint PPT presentation

Number of Views:49
Avg rating:3.0/5.0
Slides: 7
Provided by: ckho4
Category:

less

Transcript and Presenter's Notes

Title: Logical functions


1
Logical functions
  • and - Logical AND function. Example
  • (and (gt 5 4) (lt 5 4))
  • or - Logical OR function. Example
  • (and (gt 5 4) (lt 5 4))
  • not - Logical negation. Example
  • (not (gt 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
  • ((gt a 7) (/ a 2))
  • ((lt a 5) ( a 1))
  • (t 1000)
  • )

5
Conditionals - case
  • The LISP case statement is similar to that of
    Cs. 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 (gt a 5)
  • (progn
  • (setq a ( b 7))
  • (setq b ( c 8)))
  • (setq b 4)) the else clause

The then clause
Write a Comment
User Comments (0)
About PowerShow.com