Symbolic Expressions (S Expressions) Syntax: Opening and Closing parenthesis having elements in between. List represented in LISP: (A B2 C3 Shahid) (A.

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

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.
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.
Functional Programming. Pure Functional Programming Computation is largely performed by applying functions to values. The value of an expression depends.
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.
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.
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).
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 Explicit Function Application 1 Explicit Application of Functions, Functional Arguments and Explicit Evaluation Implicit and explicit.
Introductory Lisp Programming Lecture # 2 Main Topics –Basic Lisp data types –Lisp primitives –Details of list handling Cons cells (boxes) & their representation.
Functional programming: LISP Originally developed for symbolic computing First interactive, interpreted language Dynamic typing: values have types, variables.
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.
(5.1) COEN Functional Languages  Functional programming basics  Atoms and lists; cons  Useful primitive functions  Predicates  Arithmetic functions.
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.
Lisp: a history Developed by John McCarthy in the 1950’s. Developed by John McCarthy in the 1950’s. Only Fortran has higher “seniority” Only Fortran has.
Digital Electronics Data Structures LISP
Basic Lisp CIS 479/579 Bruce R. Maxim UM-Dearborn.
Common Lisp Macros Read for Input Macros Macro lifetime Macro syntax
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.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 7.
LISP John McCarthy and Marvin Minsky formed MIT’s AI Project in Suggested reading: John McCarthy’s home page
Basic LISP Programming Common LISP follows the algorithm below when interacting with users: loop read in an expression from the console; evaluate the expression;
Lisp Functional Language or Applicative Language –Achieves its effect by applying functions, either recursively or through composition Powerful, expressive,
LISP Data Types Functional Programming Academic Year Alessandro Cimatti
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.
Functional Programming: Lisp MacLennan Chapter 10.
CSE 341, S. Tanimoto Lisp Explicit Application of Functions and Functional Arguments In Lisp, functions can be passed as arguments to other functions.
LISP LISt Processing. History & Overview b b One of the oldest high level programming languages. b b First developed in 1958 by John McCarthy. b b Later.
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
CS 326 Programming Languages, Concepts and Implementation
Chapter 15 – Functional Programming Languages
Getting Started with Lisp
LISP LISt Processing.
LISP A brief overview.
Using Lisp Lisp is a interactive system
First Lecture on Introductory Lisp
The Metacircular Evaluator
FP Foundations, Scheme In Text: Chapter 14.
Modern Programming Languages Lecture 21 Fakhar Lodhi
Lisp Tutorial Click on Xlisp icon – you enter the interpreter
CS 36 – Chapter 11 Functional programming Features Practice
Modern Programming Languages Lecture 20 Fakhar Lodhi
The Metacircular Evaluator (Continued)
CSE S. Tanimoto Explicit Function Application
Explicit Application of Procedures, and Explicit Evaluation
Lisp: Using Functions as Data
LISP A brief overview.
John McCarthy Pioneer in AI Also Lisp Formalize common-sense reasoning
Defining Macros in Lisp
Defining Functions with DEFUN
LISP LISt Processing.
Abstraction and Repetition
Functional Programming: Lisp
Lisp: Using Functions as Data
LISP LISt Processing.
Modern Programming Languages Lecture 18 Fakhar Lodhi
Common Lisp II.
Programming Languages
Lisp.
More Scheme CS 331.
LISP primitives on sequences
Presentation transcript:

Symbolic Expressions (S Expressions) Syntax: Opening and Closing parenthesis having elements in between. List represented in LISP: (A B2 C3 Shahid) (A B (C D E) F G) LISP

Internal Representation A B2C3Shahid A B C D E FG nil

Functional Programming Defining Functions: Syntax: ( defun{Function Name} ( {parameters} {procedure or body of the function} ) Setting Values to variables: (setq A 2) or (set ‘A 2)

Arithmetic Operations (+ A B) means A+B (* 7 7) means 7*7=49 (- C D) means C-D (- (+10 20) 7) means ((10+20)- 7 = 23

Tree Diagram for Evaluation ( + (* 10 20) (* 2 3)) + (* 10 20) * (* 2 3) *

Built In Commands Quote: returns the list as it is. –(quote(a b c)) or use ‘ instead of quote. –Returns (a b c) List: load the argument as a list –(list( )) –Returns ( ) Eval: evaluates the list or quoted list. –(eval ( quote (+ 2 3))) –Returns 5 –( quote (+ 2 3)) –Returns (+2 3) Nth n: returns the nth value of the list –(nth 0 ( )) returns 1 –(nth 3 ( )) returns 4 –(nth 5 ( )) returns 6

Examples (= (+ 5 1 ) 6 ) returns t ( > (* 5 6) (+ 4 5)) returns t Other List Operators (length ‘( )) returns 4 (member 8 ‘( )) returns t and if not present then returns nil (null ()) returns t

Assignments Statements (setq a=0) returns 0 (let ((a 3) b); local assignment (setq b 4);if you go outside let a goes to 0 (+ a b)) 7 a 0 b error b not bounded at the top level

Sample Programme Programme to add three numbers: ( defun ADDNUMBERS (num1 num2 num3) (setq sum 0); initialise the sum to zero (setq sum ( + sum num1); add first number (setq sum ( + sum num2)); (setq sum ( + sum num3)) );

Conditionals Command ‘cond’ Syntax: ( cond ( ) ( ) ( ) )

Example ( defun absolute_values(x) (cond ( ( < x 0) (-x)); (t x))) This programme returns the value of x as it is if x>0 otherwise returns -x

List Manipulation Command ‘cons’ (cons ‘a ‘(b c)) returns (a b c) Command ‘append’ does the same operation as cons Command ‘car’ Returns the first element of the list Command ‘cdr’ Returns the list excluding the first element

Examples (cdr ‘((a b) (c d))) –returns ((c d)) (car (cdr (car list1))) ca d ar (cadar x) (car (car(x))(caar x) (car(car(car x)))(caaar x) (cdr(car(cdr x)))(cdadr x)

Recursion Write a programme that finds the factorial of a number Syntax: (defun factorial(x) (recursive call))? recursive call: (* x ( factorial ( - x 1) ) )