Allegro CL Certification Program Lisp Programming Series Level I Session 1.1.1 Overview of Common Lisp.

Slides:



Advertisements
Similar presentations
Introduction to LISP Programming of Pathway Tools Queries and Updates.
Advertisements

CS 63 LISP Philip Greenspun's Tenth* Rule of Programming:
C-LISP. LISP 2 Lisp was invented by John McCarthy in 1958 while he was at the Massachusetts Institute of Technology (MIT).John McCarthyMassachusetts Institute.
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.
Names and Bindings.
Chapter 3 Functional Programming. Outline Introduction to functional programming Scheme: an untyped functional programming language.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 7: User-Defined Functions II.
Chapter 7: User-Defined Functions II
Chapter 7: User-Defined Functions II Instructor: Mohammad Mojaddam.
Lisp – Introduction יעל נצר מערכות נבונות סמסטר ב' תשס"ו.
CIS 101: Computer Programming and Problem Solving Lecture 8 Usman Roshan Department of Computer Science NJIT.
VBA Modules, Functions, Variables, and Constants
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
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.
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)
Introductory Lisp Programming Lecture # 2 Main Topics –Basic Lisp data types –Lisp primitives –Details of list handling Cons cells (boxes) & their representation.
Artificial Intelligence and Lisp Lecture 6 LiU Course TDDC65 Autumn Semester, 2010
C. About the Crash Course Cover sufficient C for simple programs: variables and statements control functions arrays and strings pointers Slides and captured.
Introduction to a Programming Environment
TES3111 October 2001 Artificial Intelligence LISP.
Guide To UNIX Using Linux Third Edition
CSE S. Tanimoto Introduction 1 LISP Lisp is worth learning for the profound enlightenment experience you will have when you finally get it; that.
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.
Python. What is Python? A programming language we can use to communicate with the computer and solve problems We give the computer instructions that it.
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.
Allegro CL Certification Program Lisp Programming Series Level I Session Top Ten Things to Know.
Chocolate Bar! luqili. Milestone 3 Speed 11% of final mark 7%: path quality and speed –Some cleverness required for full marks –Implement some A* techniques.
Introduction to Perl Practical Extraction and Report Language or Pathologically Eclectic Rubbish Lister or …
8 Shell Programming Mauro Jaskelioff. Introduction Environment variables –How to use and assign them –Your PATH variable Introduction to shell programming.
Operator Precedence First the contents of all parentheses are evaluated beginning with the innermost set of parenthesis. Second all multiplications, divisions,
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 Lisp Functions –Built-in functions –Defining functions –Function Evaluation and Special Forms defun, if Control statements –Conditional if, cond –Repetition.
Programming Fundamentals. Today’s lecture Decisions If else …… Switch Conditional Operators Logical Operators.
Input, Output, and Processing
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
Introduction to Perl Yupu Liang cbio at MSKCC
Allegro CL Certification Program Lisp Programming Series Level I Session Basic Lisp Development in the IDE.
Predicates, Functions and Files "I suppose I should learn Lisp, but it seems so foreign." - Paul Graham, Nov 1983.
Introduction to LISP. Lisp Extensible: It lets you define new operators yourself Lisp programs are expressed as lisp data structures –You can write programs.
PRACTICAL COMMON LISP Peter Seibel 1.
11 Speed & Debug.  Lisp is really two languages:  A language for writing fast programs  A language for writing programs fast  In the early stage,
Python Primer 1: Types and Operators © 2013 Goodrich, Tamassia, Goldwasser1Python Primer.
UMBC CMSC Common Lisp II. UMBC CMSC Input and Output Print is the most primitive output function > (print (list 'foo 'bar)) (FOO BAR) The.
Milos Hauskrecht (PDF) Hieu D. Vu (PPT) LISP PROGARMMING LANGUAGE.
1 Printing in Python Every program needs to do some output This is usually to the screen (shell window) Later we’ll see graphics windows and external files.
Python Let’s get started!.
Programming Fundamentals. Topics to be covered Today Recursion Inline Functions Scope and Storage Class A simple class Constructor Destructor.
Announcements Assignment 1 due Wednesday at 11:59PM Quiz 1 on Thursday 1.
Announcements Assignment 2 Out Today Quiz today - so I need to shut up at 4:25 1.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
1 Outline Review Introduction to LISP Symbols and Numbers Lists Writing LISP Functions LISPWorks.
Artificial Intelligence and Lisp Lecture 6 LiU Course TDDC65 Autumn Semester,
Other Kinds of Arrays Chapter 11
Lists in Lisp and Scheme
Arrays in C.
User-Defined Functions
J.E. Spragg Mitthögskolan 1997
Modern Programming Languages Lecture 21 Fakhar Lodhi
T. Jumana Abu Shmais – AOU - Riyadh
CSE S. Tanimoto Introduction
CSE S. Tanimoto Introduction
Homework Any Questions?.
Allegro CL Certification Program
Homework Applied for cs240? (If not, keep at it!) 8/10 Done with HW1?
Python Primer 1: Types and Operators
CSE S. Tanimoto Introduction
Peter Seibel Practical Common Lisp Peter Seibel
Abstraction and Repetition
Common Lisp II.
Presentation transcript:

Allegro CL Certification Program Lisp Programming Series Level I Session Overview of Common Lisp

History of Lisp Born in 1958 John McCarthy 2nd oldest language still in active use Still on the leading edge

History of Lisp, cont’d Earliest widespread dialect called Lisp 1.5 Bloomed into serious development environments but fragmented –Interlisp, MacLisp Standardization effort led to Common Lisp, CLtL1, CLtL2, CLOS Common Lisp has itself evolved, most recently into an ANSI standard

The original RAD Environment Rapid Application Development Write a prototype faster than the spec Iterate the development for performance Refine prototype into production quality code

Thrives on Complex Problems Lisp is in a league of its own when problems are complex You can’t spec something if you have never solved a problem like this - you have to experiment and prototype Lisp excels at prototyping The Lisp Environment is well suited to supporting VERY large programs

Dynamic Programming Language ‘Dynamic’ means you can add or redefine functions while the program is running Change a function, compile it, load it, and test it without restarting the application Very fast edit-debug cycle Frequent development strategy: use standin functions for something complicated that will be needed eventually –standin goes into debugger –standin returns dummy values

Myths About Lisp Lisp is interpreted –Normally, you compile your code Lisp is slow –If compiled, its fast as the underlying machine Lisp is big –It is big for a Hello, World application –It is not big for real applications –My MS Office directory is 1.6 GB

More Lisp Myths Weird syntax –(+ a b) instead of a + b takes some getting used to –(+ a (/ b c)) less ambiguous than a + b / c –Parsing lisp programs is trivially easy due to the prefix notation Garbage collector is slow –If you notice it at all, something is probably wrong

Famous Lisp Applications Yahoo Stores ( –Build a web site Orbitz ( –Search Airline Fares EMACS Mars Pathfinder planning Chandra and Hubble space telescope planning

Lisp Syntax Prefix notation –Function name followed by zero or more args Delimited by parentheses ( ) (* (- 7 1) (- 4 2) 2) (print “Hello, world”)

Examples of Lisp Syntax (solve-polynomial ) (if (eq weather 'cold) (turn-on-heat) (turn-on-ac)) (dotimes (i 5)  (print i))

Function Definitions Use defun Specify function name, list of argument names, then body of function (defun square (x) (* x x)) No requirement to declare the type of x, as you do in C, C++ or Java

Lisp Syntax Simplicity That’s really all there is to know about the syntax of the language It is as clean and simple as you can get No ambiguities, no special cases This simplicity can make it powerfully flexible

Lisp is Rich ANSI Common Lisp –978 symbols some of which name operators, variables, and constants Lots of things you may never use –ODDP: true if an integer is an odd number Lots of things to you might have to write for yourself in another language –Sorting and searching algorithms –Hash tables –Adjustable length arrays Saves you time in the long run (in the short run you've got a lot to learn)

Everything Is An Object The value of every variable is an object –A variable is not just a way to reference storage Everything has a type that can be discovered Everything (almost) can move (due to GC) Everything has properties about which one can ask questions

Program Data is Freed Automatically In Lisp there is no free() The job of the garbage collector is to notice objects that are not referenced anywhere The garbage collector runs periodically, not continuously When triggered, the GC stops lisp long enough to copy “live” objects into a new area, then lisp continues

Evaluation When a lisp program is “run”, the call to run the program is evaluated. That is, it is processed by a Common Lisp function called eval.

Evaluation cont’d There are three kinds of objects which can be evaluated. –Symbol –a list of which the first element is the name of an operator (a compound form) –a self-evaluating object

Self-Evaluating Objects Numbers Strings And more...

Expression Evaluation If the expression is a list of which the first element names a function, then: Each of the elements in the list, after the function name is evaluated. The result of each such evaluation is passed to the function as an argument.

Expression Evaluation cont’d ( ) “+” names a function ( ) is a function call with args 2, 3 and 4 Value of the arguments are passed to the function Function returns a value Evaluating an expression always returns a value

Argument Evaluation If any of the args are themselves expressions they are evaluated in the same manner. The sub-expression is evaluated and its result passed as an arg (* (- 7 1) (- 4 2) 2) –returns 24

Order of Evaluation Arguments are evaluated from left to right To see, try this: (defun foo (x y) nil) (foo (print “This”) (print “That”))

Try Out the Evaluator USER(2): ( ) 9 USER(3): (* (- 7 1) (- 4 2) 2) 24 Type expression to the Lisp prompt and hit Enter Lisp reads what you typed, evaluates it, and prints the return value

Lisp Data types Usual Data Types in Other Languages –Numbers: 123, 1.45, -10e2, 3/5, #C(2 3) –Strings: "This is a fine day" Fundamental Lisp Data types –Symbols: HELLO, FOO, START –Lists: (a (b c) d) –Characters: #\A, #\z, #\space

Quote When anything immediately preceded by a ‘ is evaluated the value returned is the object which followed the ‘. a is not the same as ‘a (a) is not the same as ‘(a) ‘a is equivalent to (quote a) ‘(a b c) is equivalent to (quote (a b c))

What are Symbols? A symbol is an object that has a name and possibly a value. Symbols have other attributes, including: –Possibly an associated function definition –Property list

What are Symbols, cont’d The special operator setq and the macro setf can be used to change the value of a variable named by a symbol: –(setq color 'red) –(setq mnop z) –(setf qrst 'z) –Quote (') says don’t use the value of the symbol red, use the symbol itself.

Variable Assignment Using setq and setf The second element of the list is NOT evaluated The third element of the list is evaluated (setq x 35.0) The “variable” being “set” is named by the symbol x (setf y 37.0) (setf z (+ 2 3))

t and nil There are distinguished symbols t and nil Variables named by the symbols t and nil ALWAYS evaluate to themselves –t evaluates to t –nil evaluates to nil

Program Data is Typed, Variables are NOT typed (setq x 35) ; value of x is integer (setq x 35.0) ; value of x is float In most other languages, x could hold an integer or a float but not both Variables have no inherent type Values (memory locations) are objects that carry type information

Data Equality internally Lisp refers to most objects via pointers fundamental equality operation is EQ –only true if the two arguments point to the same object –test is very efficient EQL is default

Using Symbols (if (eq today 'Monday) …) (setq eye-color 'blue) (find 'meat ingredients)

ANSI Lisp is Case-Insensitive These lines are all equivalent: –(setq color ‘red) ; downcase –(Setq Color ‘Red) ; capitalized –(setq color ‘RED) ; uppercase By convention, most lisp code is lower case Allegro Common Lisp lets you create a case-sensitive lisp

Lists Lists are fundamental to LISP –LISP = LISt Processing Lists are zero or more elements enclosed by parentheses You have to quote them or Lisp will assume you are calling a function '(red green blue)

Lists, cont’d Lists have a printed representation of open parenthesis, followed by the list elements, followed by close parenthesis. Sounds familiar, no? –Lisp source code is just lists of lisp expressions. Printed representation can be read in too.

Overview of Lists - Creation Typing a list to the Lisp Listener '(this is a list) --> (THIS IS A LIST) Creating a list with code: (list 'so 'is 'this) --> (SO IS THIS) These are NOT equivalent

Input (read *standard-input*) –Reads one Lisp object from *standard-input* –Examples of “one Lisp object”: String: “hello, world” Symbol: RED List: (one two three) Number: –Second argument is optional

Output (print 'hello *standard-output*) –Prints HELLO to *standard-out* –Returns the symbol HELLO as its value –Stream argument is optional USER(2): (print 'hello) HELLO USER(3):

Examples of Lists ( ) ((1 2 3) 4 (5 6)) (1 'foo T NIL "frob")

Lisp Programs A Lisp program consists of one or more lists It is very easy for Lisp programs to generate and execute Lisp code This is NOT true of most other languages

Top-level loop great for performing experiments also great for debugging when developing code, use files

Edit/compile/debug Use Emacs on UNIX or IDE on Windows to create source code in files. Compile the code into object files (*.fasl) Run, test, and debug the program Edit an individual definition Compile an individual definition Go to “Run, Test and Debug”

Edit/compile/debug cont’d Profile speed to find bottlenecks Profile memory allocation Optimize code with compiler declarations Trace function calls and set breakpoints to characterize control flow Find and edit the callers of a function

Summary Lisp is a very rich language –there are very many predefined useful functions –can’t remember all details of all, but don’t need to Extremely easy to add your own functions