1 / 32

Artificial Intelligence Week 2 : SEARCH - LISP

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

maalik
Télécharger la présentation

Artificial Intelligence Week 2 : SEARCH - LISP

An Image/Link below is provided (as is) to download presentation 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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Artificial Intelligence Week 2 : SEARCH - LISP 최 윤 정 참고 http://www.cs.cmu.edu/~dst/LispBook/index.html

  2. 함수와 데이터 int add(inti, int j) { return i+j ; } int divide(inti, int j) { return i/j ; } //인자의 순서도 중요 • 데이터 : 속성, information • 수(number), 단어(word) , 이들의리스트 • interger, float, ratio(비율), string , list • 함수 : 기능, 역할 • 입력된 데이터로 결과(result)를 만들어 내는 box

  3. 함수와 데이터 • 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 ..등

  4. Combination function +, add1, add2

  5. 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))

  6. Exercise

  7. 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

  8. EQUAL • (A (B C) D) 와 (A B (C D))는 다름! • 길이와 내부구조, 순서가 모두 같을 때만 같음.

  9. Exercise

  10. FIRST, SECOND, THIRD, and REST

  11. Return a Pointer

  12. CAR and CDR Combination

  13. 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 ))

  14. 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. LIST : creating a list

  18. Exercise

  19. EVAL notation (* 3 (+ 5 6) ) (Oddp ( + 1 6))

  20. Define Function in EVAL Notation ( defun average ( x y) ( / ( + x y) 2.0) )

  21. 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

  22. 3-ways to make lists 1. ( cons ‘a ‘(b c)) : (a b c) 2. ( list ‘a ‘b ‘c) : (a b c) 3.

  23. Exercise

  24. Review Exercise Don’t parenthesize variables in the argument list; don’t quote variables;

  25. LISP on Computer

  26. Read-Eval-Print Loop Listener에서 수정 : ctrl -G

  27. 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.

  28. 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)

  29. HEAD, TAIL, and LONG-LIST are all global variables.

  30. COND : if

More Related