Common Lisp! John Paxton Montana State University Summer 2003.

Slides:



Advertisements
Similar presentations
Lisp. Versions of LISP Lisp is an old language with many variants Lisp is alive and well today Most modern versions are based on Common Lisp LispWorks.
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)
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)
List manipulation Consider student database, where each student is represented by the following list: * (setf student1 '((Paul Bennett) ((hw1 4.3) (hw2.
1-1 An Introduction to Scheme March Introduction A mid-1970s dialect of LISP, designed to be a cleaner, more modern, and simpler version than.
Lisp Recitation (cse471/598 Fall 2007 ) Aravind Kalavagattu.
CSE 341, S. Tanimoto Pattern Matching - 1 Pattern Matching in Lisp Lists can be used to represent sentences, relations, tree structures, etc. (this list.
Common Lisp! John Paxton Montana State University Summer 2003.
Defining functions in lisp In lisp, all programming is in terms of functions A function is something which –takes some arguments as input –does some computing.
Introduction to Artificial Intelligence Lisp Ruth Bergman Fall 2002.
Lisp. Versions of LISP Lisp is an old language with many variants –LISP is an acronym for List Processing language Lisp is alive and well today Most modern.
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.
Functional programming: LISP Originally developed for symbolic computing Main motivation: include recursion (see McCarthy biographical excerpt on web site).
Common Lisp! John Paxton Montana State University Summer 2003.
Common Lisp! John Paxton Montana State University Summer 2003.
Symbolic Expressions (S Expressions) Syntax: Opening and Closing parenthesis having elements in between. List represented in LISP: (A B2 C3 Shahid) (A.
Functional programming: LISP Originally developed for symbolic computing First interactive, interpreted language Dynamic typing: values have types, variables.
Recursion. Definitions I A recursive definition is a definition in which the thing being defined occurs as part of its own definition Example: A list.
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.
Lisp by Namtap Tapchareon Lisp Background  Lisp was developed by John McCarthy in  Lisp is derives from List Processing Language. 
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.
Yu-Tzu Lin ( 林育慈 )
For Wednesday Read Chapter 4, sections 1 and 2 Homework: –Lisp handout 3.
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.
1 Lists in Lisp and Scheme. 2 Lists are Lisp’s fundamental data structures. Lists are Lisp’s fundamental data structures. However, it is not the only.
Basic Lisp CIS 479/579 Bruce R. Maxim UM-Dearborn.
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.
Lisp Laboratory gcLisp (Golden Common Lisp). Lect. ratchadaporn kanawong2 The history of Lisp In summer 1956, Allen Newell, J.C. Shaw, and Herbert Simon.
KU NLP Artificial Intelligence1 Ch 15. An Introduction to LISP q 15.0 Introduction q 15.1 LISP: A Brief Overview  Symbolic Expressions, the Syntactic.
Common lisp A functional programming language. Useful URL:
Common Lisp! John Paxton Montana State University Summer 2003.
CSCI 2210: Programming in Lisp
CS 330 Programming Languages 11 / 13 / 2008 Instructor: Michael Eckmann.
LISP Data Types Functional Programming Academic Year Alessandro Cimatti
Building user-defined functions: the progressive envelopment technique The idea: define combinations of LISP primitives through a sequence of experiments.
UMBC CMSC Common Lisp II. UMBC CMSC Input and Output Print is the most primitive output function > (print (list 'foo 'bar)) (FOO BAR) The.
Control in LISP More on Predicates & Conditionals.
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.
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.
Functional Programming: Lisp MacLennan Chapter 10.
Comparative Programming Languages Functional programming with Lisp/Scheme.
1 Outline Review Introduction to LISP Symbols and Numbers Lists Writing LISP Functions LISPWorks.
Section 15.4, 15.6 plus other materials
Example of formula (defun roots (a b c) (list
Modern Programming Languages Lecture 20 Fakhar Lodhi
CSE (c) S. Tanimoto, 2002 AI Techniques
Chapter 15 – Functional Programming Languages
Functional Languages Early in AI research, there was a need for symbolic computing handling symbols instead of numbers or strings recursion Design goals.
LISP A brief overview.
First Lecture on Introductory Lisp
J.E. Spragg Mitthögskolan 1997
Modern Programming Languages Lecture 21 Fakhar Lodhi
Lisp Tutorial Click on Xlisp icon – you enter the interpreter
Modern Programming Languages Lecture 20 Fakhar Lodhi
CSE (c) S. Tanimoto, 2004 AI Techniques
LISP A brief overview.
John McCarthy Pioneer in AI Also Lisp Formalize common-sense reasoning
Abstraction and Repetition
Functional Programming: Lisp
Common Lisp II.
Programming Languages
Lisp.
List manipulation Consider student database, where each student is represented by the following list: * (setf student1 '((Paul Bennett) ((hw1 4.3) (hw2.
Lists in Lisp and Scheme
Presentation transcript:

Common Lisp! John Paxton Montana State University Summer 2003

Montana Statistics 2001 Population: 904,433. In contrast, El Salvador has a population of 6,353, % White 6.2% Native American 2.0% Hispanic or Latino Bozeman Population: 27,509.

Montana Statistics Land Area: 376,980 square kilometers. In contrast, El Salvador has 21,040 square kilometers. Fun fact: The greatest recorded 24 hour temperature change occurred in Loma, Montana in The temperature rose from -49 F to 54 F!

Material Defining Functions Local Variables Using Files Predicates Boolean Operands Lisp Representation

defun (defun add-ten (n) (+ n 10) ) ADD-TEN > (add-ten 7) 17

let > (let ((a 1)(b 2)) (+ a b) ) 3 > (+ a b) - EVAL: variable A has no value

let* > (let* ((a 1)(b (+ a 1))) (+ a b) ) 3

Using Files (load “file-name.l”) (load “file-name.lsp”) (compile-file “file-name.l”) (load “file-name”)

Questions 1.Write a function called gringo-dictionary that finds the spanish equivalent for an english word passed in. 2.Write a function that returns the roots of a quadratic equation in a list. For example, (roots 1 5 6) might return ‘(-2 - 3).

Boolean Values t = any non-empty list nil = ‘() = ()

Equality Predicates =(= 3 4) eq(eq ‘(1 2) ‘(1 2)) (setf a ‘(1 2)) (eq a a) equal(equal ‘(1 2) ‘(1 2))

member Predicate (member '(1 2) '((1 1)(1 2)(1 3))) NIL > (member '(1 2) '((1 1)(1 2)(1 3)) :test #'equal) ((1 2) (1 3))

Other Predicates listp atom numberp symbolp null endp >, =, <=

Boolean Operators and or not

if statement (if (> 2 3) 'bigger) NIL > (if (> 2 3) 'bigger 'not-bigger) NOT-BIGGER

cond statement (cond (test1 statement 1 … statement n) (test2 statement 1 … statement m) … (testk statement 1.. statement p) )

cond statement (cond ((> temperature 30) 'hot) ((> temperature 25) 'warm) (t 'pleasant) )

case statement (case temperature (35 ‘hot) (34 ‘hot) … (otherwise ‘pleasant) )

Questions 1.Write a function called blackjack that receives two card names as inputs. If one card is an ace and the other is a jack, the function should return the message blackjack. For example, (blackjack ‘ace ‘jack) would return ‘blackjack.

Questions 2.Define a function that shows a practical use of a cond statement. 3.Define a function that shows a practical use of a case statement. 4.Define a function that shows a practical use of nested conditional statements.

Underlying Representation ‘(1 2 3) 1 2 3

Underlying Representation ‘(1 (2) 3) 1 3 2

Questions 1.Draw the representation of ‘(1 (2 3 (4)) 5) 2.Draw the representation of ‘(defun add-one (n) (+ n 1)) 3.Depict what happens below (setf list1 ‘(2 3)) (setf list2 ‘(cons 1 list1))

Questions 4.Depict what happens below (setf list1 ‘(1 2)) (setf list2 ‘(3)) (setf list3 (append list1 list2)) 5.Depict what happens below (setf alist ‘(1 2 3)) (setf (second alist) 4)