artificial intelligence week 2 : search - lisp
DESCRIPTION
Artificial Intelligence Week 2 : SEARCH - LISP . 최 윤 정 참고 http://www.cs.cmu.edu/~dst/LispBook/index.html. 함수와 데이터. int add( int i , int j) { return i+j ; }. int divide( int i , int j) { return i /j ; } // 인자의 순서도 중요. 데이터 : 속성 , information - PowerPoint PPT PresentationTRANSCRIPT
Artificial Intelligence Week 2 : SEARCH - LISP
최 윤 정
참고http://www.cs.cmu.edu/~dst/LispBook/index.html
1
함수와 데이터
데이터 : 속성 , information 수 (number), 단어 (word) , 이들의 리스트
interger, float, ratio( 비율 ), string , list
함수 : 기능 , 역할
입력된 데이터로 결과 (result) 를 만들어 내는 box
2
int add(int i, int j){
return i+j ;}
int divide(int i, int j){
return i/j ;} // 인자의 순서도 중요
함수와 데이터
심볼 (symbol) : Lisp 의 데이터 타입중 하나
Sequence of letter , digits and special characters X, My-name, THREE-IS-3 Special symbols :
T : logical True, Yes NIL: logical False, No, Emptiness
술어 (Predicate) : 질문 - 답변 함수
결과가 True 면 T, False 면 Nil 을 return 기본 build-in 함수들
NUMBERP, SYMBOLP, EQUAL, ODDP,EVENP .. 등
3
FOUR : symbol4 : integer+4 : integer+ : symbol7-11 : symbol
Combination function +, add1, add2
4
List Most versatile data type ( ) 로 둘러 쌓인 item 들의 묶음
A : symbol, (A) : list (a b c), (1 2 3), ( I Love You) 실제 pointer 를 사용한 cons cell 의 연결구조 (NIL 을 가리키는 cell 이 마지막 요소 )
(RED GREEN BLUE)
( (BLUE SKY) (GREEN GRASS) (BROWN EARTH))
5
Exercise
6
List 함수 : LENGTH Length : Top-level 의 cons cell 개수
(A (B C) D) : A , ( B C) , D 3 (A (B C) (D E F) ) : 3 ( ) = NIL = empty list : 0 NIL : symbol 이면서 list
7
3
EQUAL
(A (B C) D) 와 (A B (C D)) 는 다름 ! 길이와 내부구조 , 순서가 모두 같을 때만 같음 .
8
Exercise
9
FIRST, SECOND, THIRD, and REST
10
Return a Pointer
11
CAR and CDR
12
Combination
13
Exercise
( (A B) (C D) (E F ))
14
>>(setq x '( (a b) ( c d ) (e f )))>>(car x) >>(car (car (cdr x))) C>>(cdr (car (cdr x))) (D)
CONS : Create a new cons cell
15
Cons : Nonlist structure (A B C . D)
#1 = (#1# . A)
#1 = ( A B C . #1#)
16
Exercise
17
18
LIST : creating a list
19
Exercise
20
EVAL notation (* 3 (+ 5 6) )
(Oddp ( + 1 6))
21
Define Function in EVAL Notation
( defun average ( x y) ( / ( + x y)
2.0) )
22
Symbols and Lists as Data Evaluating symbols
pi : 3.14159 , Build-in variable ! Eggplant : ERROR! , unassigned variable
Quote : ‘ (equal kim park) : ERROR! Unassigned variable. (equal ‘kim ‘park) : nil
23
3-ways to make lists
1. ( cons ‘a ‘(b c)) : (a b c) 2. ( list ‘a ‘b ‘c) : (a b c)
3.
24
Exercise
25
Review Exercise
26
Don’t parenthesize variables in the argument list; don’t quote variables;
LISP on Computer
27
Read-Eval-Print Loop Listener 에서
수정 : ctrl - G
28
defun : define function
But , The most frequently occurring errors in LISP are parenthetical errors. It
is thus almost imperative to employ some sort of counting or pairing device to check parentheses every time that a function is changed.
— Elaine Gord, ‘‘Notes on the debugging of LISP programs,’’ 1964.
29
Setf : assign a value to a variable > (setf x ’(a b c))(A B C)
> (setf y (cons ’d (cdr x)))(D B C)
> x (A B C)
> y (D B C)
30
HEAD, TAIL, and LONG-LIST are all global variables.
31
COND : if
32