Common Lisp! John Paxton Montana State University Summer 2003.

Slides:



Advertisements
Similar presentations
Lisp Control and Data Structures CIS 479/579 Bruce R. Maxim UM-Dearborn.
Advertisements

09 Examples Functional Programming. Tower of Hanoi AB C.
CS 63 LISP Philip Greenspun's Tenth* Rule of Programming:
ANSI Common Lisp 3. Lists 20 June Lists Conses List Functions Trees Sets Stacks Dotted Lists Assoc-lists.
Functions Robin Burke CSC 358/
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)
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)
Tricks.
Common Lisp! John Paxton Montana State University Summer 2003.
List manipulation Consider student database, where each student is represented by the following list: * (setf student1 '((Paul Bennett) ((hw1 4.3) (hw2.
Higher Order Functions “I hope you’re convinced, by now, that programming languages with first-class functions let you find more opportunities for abstraction,
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.
1 Introduction of Lisp function e.g. (+ 2 2) Shift+Enter Execute …… (+ 1 2) 3 ( ) 15 (- 1 6) -5 ( ) -5 (- ( ) (+
1 LISP III. 2 Functional programming l Definition From the "comp.lang.functional FAQ" Functional programming is a style of programming that emphasizes.
COMMON LISP Symbolic Expressions The syntactic elements of the LISP programming language are symbolic expressions. –Known as s-expressions. –Both programs.
Functional Programming COMP2003 A course on functional programming using Common Lisp Dr Eleni Mangina
Common Lisp! John Paxton Montana State University Summer 2003.
Project 1: Background Informed search : 8- puzzle world BFS, DFS and A* algorithms Heuristics : Manhattan distance, Number of misplaced tiles Lisp programming.
Commands and predicates LISP functions are divided into 2 classes. Predicates are functions that return boolean values i.e. t or nil. The rest are commands.
Introduction to Artificial Intelligence Lisp Ruth Bergman Fall 2002.
Common Lisp! John Paxton Montana State University Summer 2003.
CSCI Programming in Lisp; Instructor: Alok Mehta; 3_structs.ppt1 CSCI 2210: Programming in Lisp Programming Techniques Data Structures More Built-in.
Common Lisp! John Paxton Montana State University Summer 2003.
Returning values from functions You can return a value from a function by using the built- in function : ( return-from Function_name value) For example:
CMSC 471 LISP. Why Lisp? Because it’s the most widely used AI programming language Because it’s good for writing production software (Graham article)
CSE S. Tanimoto Explicit Function Application 1 Explicit Application of Functions, Functional Arguments and Explicit Evaluation Implicit and explicit.
Mapping And Iteration So far, the only Lisp mechanism we have considered, which allows an action to be performed repeatedly is recursion. Most programming.
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.
For Wednesday Read Chapter 4, sections 1 and 2 Homework: –Lisp handout 3.
Functional Programming 02 Lists
Alok Mehta - Programming in Lisp - Data Abstraction and Mapping Programming in Lisp Data Abstraction and Mapping.
CSE473 Winter /09/98 LISP Agent Continued Administrative –PS0 out, PS1 assigned next Monday Last time –agent design and demo –the top-level agent.
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.
Lecture 2-1CS250: Intro to AI/Lisp Intelligent Agents Lecture 3-2 October 14 th, 1999 CS250.
Iteration Chapters 6 & 7. Iteration in LISP n LISP (unlike Prolog) allows iteration –mapcar, remove-if(-not), count-if, find-if for special purpose iteration.
ITEC 380 Organization of programming languages Lecture 5 – Functional Programming.
Lecture 6-2CS250: Intro to AI/Lisp Programming in Your Favorite Language Lecture 5-2 February 11 th, 1999 CS250.
Lisp Files, Arrays, and Macros CIS 479/579 Bruce R. Maxim UM-Dearborn.
Lisp Functional Language or Applicative Language –Achieves its effect by applying functions, either recursively or through composition Powerful, expressive,
Introduction to LISP. Lisp Extensible: It lets you define new operators yourself Lisp programs are expressed as lisp data structures –You can write programs.
Procedures with optional parameters which do not require matching arguments Example: consider the exponent function which may take one argument, m, in.
Operating on Lists Chapter 6. Firsts and Seconds n Transforming list of pairs into two lists –(firsts ‘((1 5) (2 6) (3 7)))  (1 2 3) –(seconds ‘((1 5)
Milos Hauskrecht (PDF) Hieu D. Vu (PPT) LISP PROGARMMING LANGUAGE.
Lists CSC 358/ Outline Lab #1 / Homework #1 Lists A question List Internals of Lists List operations Extended Example.
Basic Introduction to Lisp
Search as a problem solving technique. Consider an AI program that is capable of formulating a desired goal based on the analysis of the current world.
Functional Programming: Lisp MacLennan Chapter 10.
CSE 341, S. Tanimoto Lisp Explicit Application of Functions and Functional Arguments In Lisp, functions can be passed as arguments to other functions.
Comparative Programming Languages Functional programming with Lisp/Scheme.
1 Simple Lisp Programs References:
Functions CSC 358/
Section 15.4, 15.6 plus other materials
LISP – (LISt Processing)
The Environment Model*
LISP A brief overview.
J.E. Spragg Mitthögskolan 1997
Modern Programming Languages Lecture 20 Fakhar Lodhi
CSE S. Tanimoto Explicit Function Application
Functional Programming Concepts
Lisp: Using Functions as Data
Functional Programming Concepts
Functional Programming: Lisp
Lisp: Using Functions as Data
Functional Programming Concepts
Common Lisp II.
Programming Languages
List manipulation Consider student database, where each student is represented by the following list: * (setf student1 '((Paul Bennett) ((hw1 4.3) (hw2.
Presentation transcript:

Common Lisp! John Paxton Montana State University Summer 2003

Montana Facts Did you know that Montana had no speed limits on its interstate highways until May 28, 1999? Did you know that Montana has the shortest river in the world? The Roe River near Great Falls is just 58 feet long!

Mapping funcall apply mapcar remove-if, remove-if-not count-if find-if lambda

funcall > (funcall #'append '(1 2) '(3 4)) ( )

apply > (apply #'append '((1 2)(3 4))) ( )

mapcar > (mapcar #'oddp '(1 2 3)) (T NIL T) Question: Write a recursive function called my-mapcar that produces the same results as mapcar, but does not use mapcar.

mapcar (defun my-mapcar (fn alist) (if (null alist) nil (cons (funcall fn (first alist)) (my-mapcar fn (rest alist))) )

remove-if, remove-if-not > (remove-if #'oddp '(1 2 3)) (2) > (remove-if-not #'oddp '(1 2 3)) (1 3) Question: Write a recursive function called my-remove-if.

count-if > (count-if #'oddp '(1 2 3)) 2 Question: Write a recursive version called my-count-if.

find-if > (find-if #'oddp '(1 2 3)) 1 Question: Write a recursive function called my-find-if.

lambda > (mapcar #'(lambda (n) (+ n 1)) '(1 2 3)) (2 3 4) Used for anonymous, one-time functions. I don’t use them very often.