CSE 341 -- S. Tanimoto Lisps's Basic Functionality 1 LISP: Basic Functionality S-expressions Conses Lists Predicates Evaluation and quoting Conditional.

Slides:



Advertisements
Similar presentations
CS 63 LISP Philip Greenspun's Tenth* Rule of Programming:
Advertisements

ANSI Common Lisp 3. Lists 20 June Lists Conses List Functions Trees Sets Stacks Dotted Lists Assoc-lists.
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.
Lists in Lisp and Scheme a. Lists are Lisp’s fundamental data structures, but there are others – Arrays, characters, strings, etc. – Common Lisp has moved.
CSE 3341/655; Part 4 55 A functional program: Collection of functions A function just computes and returns a value No side-effects In fact: No program.
1 Programming Languages and Paradigms Lisp Programming.
LISP Programming. LISP – simple and powerful mid-1950’s by John McCarthy at M.I.T. “ LIS t P rocessing language” Artificial Intelligence programs LISP.
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.
First Lecture on Introductory Lisp Yun Peng. Why Lisp? Because it’s the most widely used AI programming language Because AI researchers and theoreticians.
LISP primitives on sequences FIRST (or CAR) and REST (or CDR) take lists apart. Consider the list (First day of the semester). * (first '(First day of.
CSE S. Tanimoto Macros 1 Defining Macros in Lisp Extensibility: A language is extensible if the language can be extended. New Lisp control structures.
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.
TES3111 Oct 2001 Data Structures S-Expression - Symbolic expression. It can be an Atom, a List or a collection of S- Expression enclosed by (…) Atom -
Artificial Intelligence and Lisp Lecture 6 LiU Course TDDC65 Autumn Semester, 2010
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 and Scheme I. Versions of LISP LISP is an acronym for LISt Processing language Lisp is an old language with many variants – Fortran is the only older.
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.
Digital Electronics Data Structures LISP
CSE S. Tanimoto Lisp Lisp S-Expressions: ATOMs Every Lisp object is either an ATOM or a CONS Symbols and numbers are kinds of atoms: X, APPLE,
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.
CSE 341, S. Tanimoto Lisp Defining Functions with DEFUN Functions are the primary abstraction mechanism available in Lisp. (Others are structures.
Functional Programming and Lisp. Overview In a functional programming language, functions are first class objects. In a functional programming language,
Artificial Intelligence IES 503 Asst. Prof. Dr. Senem Kumova Metin.
COP4020 Programming Languages Functional Programming Prof. Xin Yuan.
Basic LISP Programming Common LISP follows the algorithm below when interacting with users: loop read in an expression from the console; evaluate the expression;
CSE S. Tanimoto Lisp Defining Macros in Lisp Extensibility: A language is extensible if the language can be extended. New Lisp control structures.
Machaut Messe Performance Performance Performance Isorhythm Isorhythm.
Introduction to ACL2 CS 680 Formal Methods for Computer Verification Jeremy Johnson Drexel University.
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.
Introduction to LISP. Lisp Extensible: It lets you define new operators yourself Lisp programs are expressed as lisp data structures –You can write programs.
Milos Hauskrecht (PDF) Hieu D. Vu (PPT) LISP PROGARMMING LANGUAGE.
CSE S. Tanimoto More-Concepts - 1 More Programming Language Concepts Currying Lazy Evaluation Polymorphism.
Introduction to LISP Atoms, Lists Math. LISP n LISt Processing n Function model –Program = function definition –Give arguments –Returns values n Mathematical.
CSE 341, S. Tanimoto Lisp Explicit Application of Functions and Functional Arguments In Lisp, functions can be passed as arguments to other functions.
Lisp S-Expressions: ATOMs
Defining Macros in Lisp
Modern Programming Languages Lecture 20 Fakhar Lodhi
Data Structures in Lisp
Lists in Lisp and Scheme
LISP A brief overview.
J.E. Spragg Mitthögskolan 1997
Lisp Tutorial Click on Xlisp icon – you enter the interpreter
Scheme: Basic Functionality
CSE S. Tanimoto Explicit Function Application
Functional Programming Concepts
Lisp: Using Functions as Data
LISP A brief overview.
Functional Programming Concepts
Lisp: Representation of Data
Defining Macros in Lisp
Defining Functions with DEFUN
Abstraction and Repetition
Lisp: Using Functions as Data
Bindings, Scope, and Extent
LISP: Basic Functionality
Modern Programming Languages Lecture 18 Fakhar Lodhi
Functional Programming Concepts
LISP: Basic Functionality
LISP: Basic Functionality
Lisp.
Lisp: Representation of Data
LISP primitives on sequences
Lists in Lisp and Scheme
Presentation transcript:

CSE S. Tanimoto Lisps's Basic Functionality 1 LISP: Basic Functionality S-expressions Conses Lists Predicates Evaluation and quoting Conditional Evaluation

CSE S. Tanimoto Lisps's Basic Functionality 2 Lisp S-Expressions: ATOMs Every Lisp object is either an ATOM or a CONS Symbols and numbers are kinds of atoms: X, APPLE, A-SYMBOL 1, 5.7, 3/5 Many other Lisp data objects are considered to be atoms (even strings and arrays are atoms!).

CSE S. Tanimoto Lisps's Basic Functionality 3 Lisp S-Expressions: CONSes Every Lisp object is either an ATOM or a CONS A CONS represents an association or pairing of two other Lisp objects. (A. B) (APPLE. RED) (PI ) (X. (Y. Z))

CSE S. Tanimoto Lisps's Basic Functionality 4 Lisp S-Expressions: Lists We define lists as follows: The symbol NIL is a list; it’s the empty list. This list is written in list notation as ( ) Any cons having the following structure is a list, (S1. (S2. (... (Sn. NIL)... ) ) ) where each S1 is either an atom or a cons. This list is written in list notation as (S1 S2... Sn)

CSE S. Tanimoto Lisps's Basic Functionality 5 Examples of Lists > ’(a b c d e) (A B C D E) > () NIL > nil NIL > ’() NIL > ’(apple. (banana. (lime. nil))) (APPLE BANANA LIME)

CSE S. Tanimoto Lisps's Basic Functionality 6 Predicates That Identify Lists > (atom ’(a b c)) NIL > (atom ’x) T > (consp ’(a b c)) T > (consp ’x) NIL

CSE S. Tanimoto Lisps's Basic Functionality 7 List predicates (continued) > (listp ’(a b c)) T > (listp ’x) NIL > (consp ’()) ; NIL is not a cons. NIL > (listp ’()) ; NIL is a list. T > (consp ’(a. b)) T > (listp ’(a. b)) ;note listp’s limitation. T

CSE S. Tanimoto Lisps's Basic Functionality 8 Lisp Tries to Print Conses as Lists > ’(a. (b. c)) (A B. C) > ’(a. nil) (A) > ’((a. b). (c. d)) ((A. B)C. D) > ’((nil. nil). (nil. nil)) ((NIL)NIL)

CSE S. Tanimoto Lisps's Basic Functionality 9 Lisp Forms A form is a list whose first element is a symbol that names an operator. If the first element names a function, then the form is a functional form. > ( ) ; a functional form 6 > (functionp #’+) T > (setq x 5) ; a special form 5 > (functionp #’setq) ; Error!

CSE S. Tanimoto Lisps's Basic Functionality 10 Evaluation of Functional Forms A functional form is evaluted as follows: If there are any arguments in the form, then they are evaluated in left-to-right order. The number of arguments is compared with the number permitted by the function named by the first element of the form. If the number is compatible, then the function is applied to the values of the arguments.

CSE S. Tanimoto Lisps's Basic Functionality 11 QUOTE Unlike functional forms, “special forms” are not required to have their arguments evaluated. QUOTE is a special form that returns its argument unevaluated. > (quote ( )) ( ) > (quote x) X > ’( ) ( ) > ’x X

CSE S. Tanimoto Lisps's Basic Functionality 12 SETQ SETQ is a special form that evaluates its second argument and assigns that value to the symbol which must be its first argument. > (setq x ( )) 6 > (setq x (* x 3)) 18 > (setq y ’( )) ( ) > (setq y (rest y)) (1 2 3) > (setq y (first y)) 1

CSE S. Tanimoto Lisps's Basic Functionality 13 IF IF is a special form that evaluates its first argument. If the result is NIL it skips its second argument and evaluates and returns its third element if any. If the result of evaluating the first element was not NIL, it evaluates the second argument and returns that value. > (setq x 10) 10 > (if (> x 2) (- x 1) (+ x 1)) 9