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

Slides:



Advertisements
Similar presentations
09 Examples Functional Programming. Tower of Hanoi AB C.
Advertisements

ANSI Common Lisp 3. Lists 20 June Lists Conses List Functions Trees Sets Stacks Dotted Lists Assoc-lists.
Lisp II. How EQUAL could be defined (defun equal (x y) ; this is how equal could be defined (cond ((numberp x) (= x y)) ((atom x) (eq x y)) ((atom y)
1 Programming Languages and Paradigms Lisp Programming.
Lisp II. How EQUAL could be defined (defun equal (x y) ; this is how equal could be defined (cond ((numberp x) (= x y)) ((atom x) (eq x y)) ((atom y)
Helper functions: when extra arguments are needed Consider this problem: we want a function index_items that takes a list L and gives a number to each.
6.001 SICP SICP Sections 5 & 6 – Oct 5, 2001 Quote & symbols Equality Quiz.
Introductory Lisp Programming Lecture # 2 Main Topics –Basic Lisp data types –Lisp primitives –Details of list handling Cons cells (boxes) & their representation.
SICP Data Mutation Primitive and Compound Data Mutators Stack Example non-mutating mutating Queue Example non-mutating mutating.
How to define functions? (DEFUN function-name parameter-list commands ) Example: (DEFUN myFunction (x y) (/ x y) ) To call this function, you would then.
Programming Languages I LISP
COMP 205 – Week 11 Dr. Chunbo Chu. Intro Lisp stands for “LISt Process” Invented by John McCarthy (1958) Simple data structure (atoms and lists) Heavy.
LISP 1.5 and beyond A very quick tour. Data Atoms (symbols) including numbers – All types of numbers including Roman! (well, in the early days) – Syntactically.
F UNCTIONAL P ROGRAMMING 05 Functions. F UNCTIONS - G LOBAL F UNCTIONS fboundp Tells whether there is a function with a given symbol as its name > (fboundp.
Advanced Functions In CL, functions are often supplied as parameters to other functions –This gives us tremendous flexibility in writing functions whose.
Functional Programming 02 Lists
PRACTICAL COMMON LISP Peter Seibel 1.
PRACTICAL COMMON LISP Peter Seibel 1.
Mitthögskolan 10/8/ Common Lisp LISTS. Mitthögskolan 10/8/2015 2Lists n Lists are one of the fundamental data structures in Lisp. n However, it.
For Monday Read Chapter 3 Homework: –Lisp handout 2.
1 Lisp Functions –Built-in functions –Defining functions –Function Evaluation and Special Forms defun, if Control statements –Conditional if, cond –Repetition.
Lecture 2-1CS250: Intro to AI/Lisp Intelligent Agents Lecture 3-2 October 14 th, 1999 CS250.
Functional Programming in Scheme and Lisp. Overview In a functional programming language, functions are first class objects. You can create them, put.
Functional Programming and Lisp. Overview In a functional programming language, functions are first class objects. In a functional programming language,
Functional Programming in Scheme and Lisp.
COP4020 Programming Languages Functional Programming Prof. Xin Yuan.
Lecture 6-2CS250: Intro to AI/Lisp Programming in Your Favorite Language Lecture 5-2 February 11 th, 1999 CS250.
Introduction to LISP. Lisp Extensible: It lets you define new operators yourself Lisp programs are expressed as lisp data structures –You can write programs.
UMBC CMSC Common Lisp II. UMBC CMSC Input and Output Print is the most primitive output function > (print (list 'foo 'bar)) (FOO BAR) The.
You can access the members of a list with the functions car (or first) and cdr (or rest): (setf list '(a b c)) (car list) ⇒ a (first list) ⇒ a (cdr list)
Milos Hauskrecht (PDF) Hieu D. Vu (PPT) LISP PROGARMMING LANGUAGE.
1 Variable Declarations Global and special variables – (defvar …) – (defparameter …) – (defconstant …) – (setq var2 (list 4 5)) – (setf …) Local variables.
Lists CSC 358/ Outline Lab #1 / Homework #1 Lists A question List Internals of Lists List operations Extended Example.
Forms Writing your own procedures CS 480/680 – Comparative Languages.
Comparative Programming Languages Functional programming with Lisp/Scheme.
1 Vectors, binary search, and sorting. 2 We know about lists O(n) time to get the n-th item. Consecutive cons cell are not necessarily consecutive in.
Lecture 4: Metacircles Eval Apply David Evans
Edited by Original material by Eric Grimson
CS 550 Programming Languages Jeremy Johnson
Example of formula (defun roots (a b c) (list
Modern Programming Languages Lecture 20 Fakhar Lodhi
Lecture 14 - Environment Model (cont.) - Mutation - Stacks and Queues
CS 270 Math Foundations of CS Jeremy Johnson
LISP A brief overview.
The Metacircular Evaluator
J.E. Spragg Mitthögskolan 1997
Lecture 15: Tables and OOP
Imperative Data Structures
Dynamic Scoping Lazy Evaluation
Lecture 16: Tables and OOP
Modern Programming Languages Lecture 20 Fakhar Lodhi
CSE S. Tanimoto Explicit Function Application
Streams, Delayed Evaluation and a Normal Order Interpreter
LISP A brief overview.
Data Mutation Primitive and compound data mutators set! for names
Lecture 14 - Environment Model (cont.) - Mutation - Stacks and Queues
John McCarthy Pioneer in AI Also Lisp Formalize common-sense reasoning
topics mutable data structures
6.001 SICP Variations on a Scheme
Mutators for compound data Stack Queue
6.001 SICP Data Mutation Primitive and Compound Data Mutators
Lecture 14: The environment model (cont
Announcements Quiz 5 HW6 due October 23
Defining Functions with DEFUN
Functional Programming: Lisp
6.001 SICP Interpretation Parts of an interpreter
Lecture # , , , , מבוא מורחב.
Modern Programming Languages Lecture 18 Fakhar Lodhi
Common Lisp II.
LISP primitives on sequences
Presentation transcript:

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

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

“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

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

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

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

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 3.0 3.0) => 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

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

= 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

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

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

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

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

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