Presentation is loading. Please wait.

Presentation is loading. Please wait.

Intelligent Agents Lecture 3-2 October 14th, 1999 CS250 Lecture 2-1

Similar presentations


Presentation on theme: "Intelligent Agents Lecture 3-2 October 14th, 1999 CS250 Lecture 2-1"— Presentation transcript:

1 Intelligent Agents Lecture 3-2 October 14th, 1999 CS250 Lecture 2-1
CS250: Intro to AI/Lisp

2 Projects What’s expected Project ideas Lecture 2-1
CS250: Intro to AI/Lisp

3 “Get Your Red-Hot Lists Here!”
Conses are pairs of pointers First pointer is the car Rest is the cdr Lists are conses in which: First pointer is the first element Second pointer is the rest of the list No intermediate pointers makes last expensive USER(104): (last (list 'a 'b 'c)) (C) Lecture 2-1 CS250: Intro to AI/Lisp

4 Box & Pointer a c b d Represent a cons graphically
(list ‘a (list ‘b ‘c) ‘d) a c b d nil Lecture 2-1 CS250: Intro to AI/Lisp

5 eq True if its arguments are the same, identical object; otherwise, returns false (eq 'a 'b) => false (eq 'a 'a) => true (eq 3 3) => true OR => false (eq 3 3.0) => false Lecture 2-1 CS250: Intro to AI/Lisp

6 More on eq Crazy things can happen Question from last time:
Implementations can “collapse” constants (eq “Foo” “Foo”) could be TRUE or FALSE If interpreted, it’s always FALSE Question from last time: (eq ‘(a .b) ‘(a . b)) could be TRUE or FALSE (eq (cons ‘a ‘b) (cons ‘a ‘b)) is FALSE Lecture 2-1 CS250: Intro to AI/Lisp

7 eql True of two objects, x and y, in the folowing cases:
1. If x and y are eq. 2. If x and y are both numbers of the same type and the same value. 3. If they are both characters that represent the same character. (eql 'a 'b) => false (eql 'a 'a) => true (eql 3 3) => true (eql 3 3.0) => false (eql ) => true (eql #c(3 -4) #c(3 -4)) => true (eql #c(3 -4.0) #c(3 -4)) => false Lecture 2-1 CS250: Intro to AI/Lisp

8 eq vs. eql eql tells whether two objects are conceptually the same
eq tells whether two objects are implementationally the same Lecture 2-1 CS250: Intro to AI/Lisp

9 = Numeric comparisons USER(3): (= 3 3 3 3) T USER(4): (= 3 3.0 3 3 3)
NIL Lecture 2-1 CS250: Intro to AI/Lisp

10 Sequences Sequences are ordered “sets” Many useful functions:
Lists + vectors Many useful functions: elt reverse map remove length nreverse some delete ... Lecture 2-1 CS250: Intro to AI/Lisp

11 Association lists Easy lookup tables Try this
(setf nickname '(("Red Sox" . "Losers") ("Mets" . "Wannabes") ("Yankees" . "World champions"))) What is returned by: (assoc “Red Sox” nickname) Lecture 2-1 CS250: Intro to AI/Lisp

12 Keyword args Keywords enable flexibility in arguments
Playing with args: &rest &optional &key Lecture 2-1 CS250: Intro to AI/Lisp

13 The rest of the story How does #’+ work?
How to handle an unknown number: Use a list Use rest Testing for nil (defun any-nil-p (&rest all-values) (notevery #'null (mapcar #'null all-values))) Lecture 2-1 CS250: Intro to AI/Lisp

14 Optional parameters Add an optional parameter with a default value
((lambda (a &optional (b 2)) (+ a (* b 3))) 4 5) ((lambda (a &optional (b 2)) (+ a (* b 3))) 4) Lecture 2-1 CS250: Intro to AI/Lisp


Download ppt "Intelligent Agents Lecture 3-2 October 14th, 1999 CS250 Lecture 2-1"

Similar presentations


Ads by Google