Allegro CL Certification Program Lisp Programming Series Level I Session 1.1.3 Top Ten Things to Know.

Slides:



Advertisements
Similar presentations
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.
Advertisements

1 Programming Languages and Paradigms Lisp Programming.
1 COSC3306: Programming Paradigms Lecture 11: Applicative Programming with Lisp Haibin Zhu, Ph.D. Computer Science Nipissing University (C) 2003.
Lisp Recitation (cse471/598 Fall 2007 ) Aravind Kalavagattu.
1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf 9.4Printing Integers 9.5Printing Floating-Point.
First Lecture on Introductory Lisp Yun Peng. Why Lisp? Because it’s the most widely used AI programming language Because AI researchers and theoreticians.
Introduction CSC 358/458 3/27/2006. Outline Introductions Course goals Course organization History of Lisp Lisp syntax Examples Lisp IDE.
C. About the Crash Course Cover sufficient C for simple programs: variables and statements control functions arrays and strings pointers Slides and captured.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction.
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.
Section 2 - More Basics. The char Data Type Data type of a single character Example char letter; letter = 'C';
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 Presented by.
Allegro CL Certification Program Lisp Programming Series Level I Session Overview of Common Lisp.
Yu-Tzu Lin ( 林育慈 )
Functional Programming
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Streams Streams –Sequences of characters organized.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction.
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.
Chapter 9 Formatted Input/Output. Objectives In this chapter, you will learn: –To understand input and output streams. –To be able to use all print formatting.
A Variable is symbolic name that can be given different values. Variables are stored in particular places in the computer ‘s memory. When a variable is.
The Case primitive: matches the evaluated key form against the unevaluated keys by using eql The general format of case is the following: (case (... ).....
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.
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.
04 Control. Control-Blocks Common Lisp has 3 basic operators for creating blocks of code progn block tagbody If ordinary function calls are the leaves.
06 INPUT AND OUTPUT Functional Programming. Streams Two kinds of streams  Character streams  Binary streams Character streams are Lisp objects representing.
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
PRACTICAL COMMON LISP Peter Seibel 1.
Allegro CL Certification Program Lisp Programming Series Level I Session Basic Lisp Development in the IDE.
LISP Data Types 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.
UMBC CMSC Common Lisp II. UMBC CMSC Input and Output Print is the most primitive output function > (print (list 'foo 'bar)) (FOO BAR) The.
You can access the members of a list with the functions car (or first) and cdr (or rest): (setf list '(a b c)) (car list) ⇒ a (first list) ⇒ a (cdr list)
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
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.
2: Basics Basics Programming C# © 2003 DevelopMentor, Inc. 12/1/2003.
Chapter 14 LISP – Practical 3 Instructor: Haris Shahzad Artificial Intelligence CS-402.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
Common LISP VS JAVA 김민철. Table of contents  1. LISP …………………………………………… 3  2. 데이터 타입 …………………………………… 4  3. 산술 및 논리 연산 ……………………………… 8  4. 변수 선언 및 할당 ………………………………
Input, Output and Variables GCSE Computer Science – Python.
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,
Modern Programming Languages Lecture 20 Fakhar Lodhi
Allegro CL Certification Program
LISP A brief overview.
Using Lisp Lisp is a interactive system
Allegro CL Certification Program
First Lecture on Introductory Lisp
Modern Programming Languages Lecture 21 Fakhar Lodhi
Liquid Common Lisp On Suns.
Introduction to Primitive Data types
Modern Programming Languages Lecture 20 Fakhar Lodhi
Allegro CL Certification Program
LISP A brief overview.
John McCarthy Pioneer in AI Also Lisp Formalize common-sense reasoning
Review for Final Exam.
Defining Functions with DEFUN
Abstraction and Repetition
Data Structures in Lisp
Data Structures in Lisp
Modern Programming Languages Lecture 18 Fakhar Lodhi
Common Lisp II.
Allegro CL Certification Program
Class code for pythonroom.com cchsp2cs
The general format of case is the following: (case <key form>
LISP primitives on sequences
Introduction to Primitive Data types
Presentation transcript:

Allegro CL Certification Program Lisp Programming Series Level I Session Top Ten Things to Know

1. Defining a Function (defun plus (a b) (+ a b)) Function name Argument list Function body (sequence of one or more expressions)

Calling a function (plus 3 5) (defun mean (a b) (/ (plus a b) 2)) First: call PLUS to add a to b Second: divide the result by 2

2. Printing Output (defun print-mean (a b) (format *standard-output* "~A ~%" (mean a b))) First argument is the stream Second argument is the “control string” Third argument is the value to be printed –~A takes the argument and prints it –~% prints a newline –(Analogous to printf in C)

Common Format Control Strings ~A prints any value (strings w/o double quotes) ~S prints any value (strings w/ double quotes) ~5F prints a float in a 5 character wide field ~% prints a newline Combine them to print many things: (format *standard-output* “~A ~5F ~A ~%” 5 pi 10)

Printing Hello (defun hello (name) (format *standard-output* " Hello, ~A ~%" name)) (hello "Linda") Hello, Linda

3. Using Local Variables (defun mean (a b) (let* ((sum (+ a b))) (/ sum 2))) LET* creates local variables Example creates one named SUM Initial value is result of (+ a b)

More Local Variables (defun polynomial (a b c x) (let* ((y1 (* a (* x x))) (y2 (* b x)) (y3 c)) (+ y1 y2 y3))) Ax 2 + Bx + C Three local variables

Avoid this Mistake (defun polynomial (a b c x) (setq y1 (* a (* x x))) (setq y2 (* b x)) (setq y3 c)) (+ y1 y2 y3)) ;;; y1, y2, y3 become globals ;;; compiler will give warnings

4. Using if (defun sign-name (number) (if (> number 0) ’positive ’not-positive)) Boolean test returns true or NIL (false) (If )

Using if, cont’d (defun sign-name (number) (if (> number 0) “positive” (if (= number 0) "zero" "negative")))

Compound Tests NOT: (not (> x 3)) AND: (and (> x 3) (< x 10)) OR: (or (> x 3) (< x 0) (= y 7) (< (+ x y) 5 ))

Other Types of Tests Numeric comparisons: >, >=, <, <=, = Equality of objects: EQ, EQL, EQUAL Equality of strings: string=, string-equal –(string-equal "Radar" "RADAR") Type tests: –(typep x 'integer)

5. Global Variables and Constants (defvar *website* " –*website* is the symbol –Naming convention is to use asterisk in names of global variables (defconstant +timeout+ 60.0) –+timeout+ is the symbol –Naming convention is to use + in names of program constants

6. Assigning Values to Variables In Lisp we use setq or setf instead of =, := etc (setq *todays-temp* 101.5) *todays-temp*  101.5

7. Using Symbols (defun color-name (action) (if (eq action 'stop) 'red (if (eq action 'go) 'green 'yellow)))

8. Using Lists (defvar *abbreviations* '((bos “Boston”) (lga “NY/LaGuardia”) (sfo “San Francisco”))) (defun decode-abbreviation (symbol) (second (assoc symbol *abbreviations*))) (defun add-abbreviation (symbol str) (push (list symbol str) *abbreviations*))

9. Iteration (defun count (N) (dotimes (I N) (format *standard-output* "~A " N))) (defun enumerate (list) (dolist (element list) (format *standard-output* "~A" element)))

Iteration (defun sum (list) (let* ((result 0)) (dolist (item list) (setq result (+ result item))) result)) (sum '( ))  14

10. Packages A Lisp package is a namespace for related functionality –COMMON-LISP: a package for ANSI Common Lisp; you can’t add to it or change it –USER: a package for you to play around in (it’s also the default or initial package) –CG-USER Large applications should use their own package

Package Example (defpackage math (:use common-lisp)) (in-package :math) (defun square (x) (* x x)) The symbol SQUARE now exists in the MATH package The math package “uses” or inherits from the common-lisp package

Packages Every symbols exists in a package –*package* will return the current package –in-package will change the package Default package in the IDE is “COMMON-GRAPHICS-USER”