Artificial Intelligence Week 2 : SEARCH - LISP

1 / 32

# Artificial Intelligence Week 2 : SEARCH - LISP - PowerPoint PPT Presentation

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

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

## PowerPoint Slideshow about 'Artificial Intelligence Week 2 : SEARCH - LISP' - maalik

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

### Artificial Intelligence Week 2 : SEARCH - LISP

최 윤 정

참고

http://www.cs.cmu.edu/~dst/LispBook/index.html

함수와 데이터

{

return i+j ;

}

int divide(inti, int j)

{

return i/j ;

} //인자의 순서도 중요

• 데이터 : 속성, information
• 수(number), 단어(word) , 이들의리스트
• interger, float, ratio(비율), string , list
• 함수 : 기능, 역할
• 입력된 데이터로 결과(result)를 만들어 내는 box
함수와 데이터
• FOUR : symbol

4 : integer

• +4 : integer

+ : symbol

7-11 : symbol

• 심볼(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 ..등
List
• Most versatiledata 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))
List 함수 : LENGTH

 3

• 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
EQUAL
• (A (B C) D) 와 (A B (C D))는 다름!
• 길이와 내부구조, 순서가 모두 같을 때만 같음.
CAR and CDR

Combination

Exercise

>>(setqx '( (a b) ( c d ) (e f )))

>>(car x)

>>(car (car (cdr x)))

C

>>(cdr(car (cdr x)))

(D)

( (A B) (C D) (E F ))

Cons : Nonlist structure

(A B C . D)

#1 = (#1# . A)

#1 = ( A B C . #1#)

EVAL notation

(* 3 (+ 5 6) )

(Oddp ( + 1 6))

Define Function in EVAL Notation

( defun average ( x y)

( / ( + x y) 2.0) )

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
3-ways to make lists

1. ( cons ‘a ‘(b c)) : (a b c)

2. ( list ‘a ‘b ‘c) : (a b c)

3.

Review Exercise

Don’t parenthesize variables in the argument list; don’t quote variables;

### LISP on Computer

Listener에서

수정 : ctrl -G

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.

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)