Dept Computer Science Korea Univ Intelligent Information System
- Slides: 6
Dept. Computer Science, Korea Univ. Intelligent Information System Lab. A I (Artificial Intelligence) Professor I. J. Chung 9/2/2021 1
Dept. Computer Science, Korea Univ. Intelligent Information System Lab. AI (Artificial Intelligence) Local variables and let is used in Lisp to store the results of one action for use in a subsequent action. Lisp provides the special form let to allow us to create the local variables. 9/2/2021 Artificial Intelligence 2
Dept. Computer Science, Korea Univ. Intelligent Information System Lab. AI (Artificial Intelligence) eg. ( defun sum_diff ( ) ( let ( hold 1 hold 2) ( print ’( type a number ) ) ( setq hold 1 ( read ) ) ( print ’( type another number ) ) ( setq hold 2 ( read) ) ( print ’( the sum of two number is ) ) ( print ( + hold 1 hold 2 ) ) ( print ’( the difference of two number is ) ) ( print ( - hold 1 hold 2 ) ) 9/2/2021 Artificial Intelligence 3
Dept. Computer Science, Korea Univ. Intelligent Information System Lab. AI (Artificial Intelligence) → ’( sum-diff ) ( type a number ) 56 ( type another number ) 78 ( the sum of two number is ) 134 ( the difference of two number is ) -22 9/2/2021 Artificial Intelligence 4
Dept. Computer Science, Korea Univ. Intelligent Information System Lab. AI (Artificial Intelligence) eg. procedure rectangle which accepts a list containing the length and width of a rectangle and print area, perimeter, and diagonal of the rectangle. 9/2/2021 Artificial Intelligence 5
Dept. Computer Science, Korea Univ. Intelligent Information System Lab. AI (Artificial Intelligence) (defun rectangle ( dimensions ) ( let (( len ( car dimensions ) ( wid ( cadr dimensions) ) ) ( print ( list ‘area ( * len wid ) ) ) ( print ( list ‘perimeter ( * 2 ( + len wid )))) ( print ( list ‘diagonal ( sqrt ( + ( square len) (square wid )))) 9/2/2021 Artificial Intelligence 6