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

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)
Common Lisp! John Paxton Montana State University Summer 2003.
Lisp Recitation (cse471/598 Fall 2007 ) Aravind Kalavagattu.
Prof. Fateman CS 164 Lecture 151 Language definition by interpreter, translator, continued Lecture 15.
CSE 341, S. Tanimoto Pattern Matching - 1 Pattern Matching in Lisp Lists can be used to represent sentences, relations, tree structures, etc. (this list.
Functional Programming COMP2003 A course on functional programming using Common Lisp Dr Eleni Mangina
Arrays (1) You create an array in LISP by using the function (make- array ). All elements are initially set to nil. To create a 1-dimensional array of.
Interactive Session on Project 2 & Assorted Topics Copyright, 1996 © Dale Carnegie & Associates, Inc. By Surendra Singhi Spring 2005.
Procedures with optional parameters which do not require matching arguments Example: consider the exponent function which may take one argument, m, in.
Project 1: Background Informed search : 8- puzzle world BFS, DFS and A* algorithms Heuristics : Manhattan distance, Number of misplaced tiles Lisp programming.
ITERATIVE CONSTRUCTS: DOLIST Dolist is an iterative construct (a loop statement) consisting of a variable declaration and a body The body states what happens.
Functional Programming COMP2003 A course on functional programming using Common Lisp Dr Eleni Mangina
Introduction to Artificial Intelligence Lisp Ruth Bergman Fall 2002.
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.
First Lecture on Introductory Lisp Yun Peng. Why Lisp? Because it’s the most widely used AI programming language Because AI researchers and theoreticians.
Common Lisp! John Paxton Montana State University Summer 2003.
>(setf oldlist ) Constructing a list We know how to make a list in lisp; we simply write it: ‘4321( ) What if we want a new list with that list as a part?
1 Lecture 20:Arrays and Strings Introduction to Computer Science Spring 2006.
ANSI Common Lisp 4. Specialized Data Structures 7 June 2003.
Formatted Output What we know: write(*,*) x print *, x General Form: write (unit, format, options) list unit = * : write to the monitor format = *: no.
Chapter 8 Arrays and Strings
LISP A brief overview. Lisp stands for “LISt Process” –Invented by John McCarthy (1958) –Simple data structure (atoms and lists) –Heavy use of recursion.
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.
CSE 341, S. Tanimoto Lisp Data Structures - 1 Data Structures in Lisp 0. Collections of associations, association lists. 1. Creating graphs with conses.
Functional Programming
Search Much of AI has traditionally revolved around search –Search means “searching among all the possibilities for an answer” (or possibly the best answer)
Input/Output Chapters 7 & 9. Output n Print produces output > (print 100) n It also returns the value it printed –that’s where the second 100 came.
1 Othello Game Programs (human to human). 2 (defconstant all-directs '( )) ALL-DIRECTS (defconstant empty 0) EMPTY (defconstant.
The Case primitive: matches the evaluated key form against the unevaluated keys by using eql The general format of case is the following: (case (... ).....
Error Handling Common Lisp has the throw/catch statements so that you can simulate exception handling as seen in languages like Java But CL goes far beyond.
1 Lisp Functions –Built-in functions –Defining functions –Function Evaluation and Special Forms defun, if Control statements –Conditional if, cond –Repetition.
LISP 2011 년 5 월. Basic Data Types The two most important kinds of objects in LISP for you to know about are atoms and lists. These two kinds are mutually.
Common Lisp! John Paxton Montana State University Summer 2003.
CSE 341, S. Tanimoto Lisp Defining Functions with DEFUN Functions are the primary abstraction mechanism available in Lisp. (Others are structures.
Artificial Intelligence IES 503 Asst. Prof. Dr. Senem Kumova Metin.
06 INPUT AND OUTPUT Functional Programming. Streams Two kinds of streams  Character streams  Binary streams Character streams are Lisp objects representing.
The Loop Macro Many of the CL “functions” are actually macros (let, progn, if, etc) The most complicated macro in CL is probably the Loop macro –The Loop.
Alok Mehta - Programming in Lisp - Macros Programming in Lisp Arrays, Macros, Expert Systems, Misc.
Macros “How can you get anything done in [other languages], I think, without macros?” - Paul Graham, 2003.
Lisp Files, Arrays, and Macros CIS 479/579 Bruce R. Maxim UM-Dearborn.
More Language Features Functional Programming Academic Year Alessandro Cimatti
Introduction to LISP. Lisp Extensible: It lets you define new operators yourself Lisp programs are expressed as lisp data structures –You can write programs.
11 Speed & Debug.  Lisp is really two languages:  A language for writing fast programs  A language for writing programs fast  In the early stage,
UMBC CMSC Common Lisp II. UMBC CMSC Input and Output Print is the most primitive output function > (print (list 'foo 'bar)) (FOO BAR) The.
PRACTICAL COMMON LISP Peter Seibel 1.
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.
Python – May 12 Recap lab Chapter 2 –operators –Strings –Lists –Control structures.
1 Common Lisp. 2 Lisp stands for “LISt Process” –Invented by John McCarthy (1958) –Simple data structure (atoms and lists) –Heavy use of recursion –Interpretive.
PRACTICAL COMMON LISP Peter Seibel 1.
Input Streams “A program designed for inputs from people is usually stressed beyond the breaking point by computer-generated inputs.” Dennis Ritchie, Bell.
Input/Output Chapters 8 & 9. Character Input n Read-char reads a single character n Read-line reads until the next end-of-line –returns a string n Both.
1 Outline Review Introduction to LISP Symbols and Numbers Lists Writing LISP Functions LISPWorks.
Modern Programming Languages Lecture 20 Fakhar Lodhi
Getting Started with Lisp
Imperative Data Structures
Modern Programming Languages Lecture 21 Fakhar Lodhi
Lisp Tutorial Click on Xlisp icon – you enter the interpreter
Liquid Common Lisp On Suns.
Modern Programming Languages Lecture 20 Fakhar Lodhi
Suppose I want to add all the even integers from 1 to 100 (inclusive)
Functions continued.
Defining Functions with DEFUN
Data Structures in Lisp
Data Structures in Lisp
Common Lisp II.
Procedures with optional parameters which do not require matching arguments Example: consider the exponent function which may take one argument, m, in.
Presentation transcript:

Common Lisp! John Paxton Montana State University Summer 2003

Montana Facts The Plains Indians began using buffalo jumps over 2000 years ago.

Array Declarations > (setf numbers (make-array '(4))) #(NIL NIL NIL NIL) > (setf numbers (make-array '(4) :initial-element 0)) #( )

Array Declarations > (setf numbers (make-array '(4) :initial-contents '( ))) #( ) > (setf numbers (make-array '(2 3))) #2A((NIL NIL NIL) (NIL NIL NIL))

Array Access > (setf (aref numbers 0 0) 3) 3 > (setf (aref numbers 2 0) 3) *** - SYSTEM::STORE: subscripts (2 0) for #2A((3 NIL NIL) (NIL NIL NIL)) are out of range

Array Size Determination > (array-dimensions numbers) (2 3) > (array-dimension numbers 0) 2 > (array-dimension numbers 1) 3

Random Numbers > (random 10) ;; 0 – 9, integer 3 > (random 10.0) ;; [0.0, 10.0], real

Formatted Output > (format t “pronto") pronto > (format t "Senor ~% Lopez") Senor Lopez

Formatted Output > (format t "~a + ~a" 1 2) 1 + 2

Questions 1.Write a function that receives a 1-D integer array of size 5 and returns the value of the smallest integer contained in the array. 2.Declare a 3 by 5 matrix named numbers that initially contains all 7s.

Questions 3.Write a function called print-matrix that prints out the contents of the matrix that is passed in. Use the format statement. 4.Write a function called fill-matrix that gives each slot within the passed in matrix a random integer value between 0 and 10 inclusive.

File I/O (defun read-file ( file-name ) (with-open-file (data-file file-name :direction :input) (do ((item (read data-file nil) (read data-file nil))) ((not item) 'done) (format t "~a ~%" item) )))

File I/O sample.dat file contents

File I/O > (read-file "sample.dat") DONE

Question Write a function that finds and prints all permutations of a list. For example, (permute ‘(1 2 3)) could print 1 2 3, 1 3 2, 2 1 3, 2 3 1, 3 1 2, 3 2 1

permute (defun permute (alist &optional (so-far nil)) (cond ((null alist) (format t "~a~%" so-far)) (t (dolist (item alist) (permute (remove item alist) (cons item so-far)) ))))

permute > (permute '(1 2 3)) (3 2 1) (2 3 1) (3 1 2) (1 3 2) (2 1 3) (1 2 3)