Programming Languages

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.
1 Programming Languages (CS 550) Mini Language Interpreter Jeremy R. Johnson.
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.
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)
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 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)
Chapter 3 Functional Programming. Outline Introduction to functional programming Scheme: an untyped functional programming language.
CS 355 – PROGRAMMING LANGUAGES Dr. X. Apply-to-all A functional form that takes a single function as a parameter and yields a list of values obtained.
PZ10CX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ10CX - LISP Programming Language Design and Implementation.
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).
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 14 Functional Programming It is better to.
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 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.
Basic Lisp CIS 479/579 Bruce R. Maxim UM-Dearborn.
For Monday Read Chapter 3 Homework: –Lisp handout 2.
Functional Programming in Scheme
CSC3315 (Spring 2009)1 CSC 3315 Programming Paradigms Scheme Language Hamid Harroud School of Science and Engineering, Akhawayn University
ISBN Chapter 15 Functional Programming Languages.
Common lisp A functional programming language. Useful URL:
Lisp Functional Language or Applicative Language –Achieves its effect by applying functions, either recursively or through composition Powerful, expressive,
Introduction to ACL2 CS 680 Formal Methods for Computer Verification Jeremy Johnson Drexel University.
LISP Data Types Functional Programming Academic Year Alessandro Cimatti
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.
Functional Programming: Lisp MacLennan Chapter 10.
1 Programming Languages (CS 550) Lecture 2 Summary Mini Language Interpreter Jeremy R. Johnson.
1 FP Foundations, Scheme In Text: Chapter Chapter 14: FP Foundations, Scheme Mathematical Functions Def: A mathematical function is a mapping of.
Comparative Programming Languages Functional programming with Lisp/Scheme.
1 Introduction to Functional Programming in Racket CS 270 Math Foundations of CS Jeremy Johnson.
1 Outline Review Introduction to LISP Symbols and Numbers Lists Writing LISP Functions LISPWorks.
Functional Programming Languages
Section 15.4, 15.6 plus other materials
CS 550 Programming Languages Jeremy Johnson
Modern Programming Languages Lecture 20 Fakhar Lodhi
Chapter 15 – Functional Programming Languages
Lists in Lisp and Scheme
CS 270 Math Foundations of CS Jeremy Johnson
LISP A brief overview.
Introduction to Functional Programming in Racket
PZ10CX - LISP Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section Appendix A.6.
Mini Language Interpreter Programming Languages (CS 550)
First Lecture on Introductory Lisp
FP Foundations, Scheme In Text: Chapter 14.
Functional Programming Languages
Modern Programming Languages Lecture 21 Fakhar Lodhi
Lisp Tutorial Click on Xlisp icon – you enter the interpreter
CSCE 314: Programming Languages Dr. Dylan Shell
LISP A brief overview.
Introduction to Functional Programming in Racket
Programming Languages
Announcements Quiz 5 HW6 due October 23
List and list operations (continue).
Functional Programming: Lisp
Common Lisp II.
Lisp.
Programming Languages
List manipulation Consider student database, where each student is represented by the following list: * (setf student1 '((Paul Bennett) ((hw1 4.3) (hw2.
LISP primitives on sequences
Presentation transcript:

Programming Languages Meeting 10 November 8/9, 2016

Planning Ahead Next week: Short Exam 2 Program functions Control structures Parameter passing Foundations of functional programming Definitions Syntax Semantic specification

Reflections on Homework Program function, II.4, variables in range 0..maxint What is the value of x when a while loop that has condition x<>b terminates? If sum(1,25,1,k,A[k]) sums the first 25 elements of the array A, by pattern matching sum( _ , _ , _ , _ , ___ ) sums the first 7 powers of 3.

Example 3 (6) int A,B; A := 3; // Show Env element and Store element B := AV(IV(A)); B := AV(IN(A)); B := AN(IV(A)); B := AN(IN(A));

Primitives first last head tail atom? nil? list?

More Primitives appendr appendl length The arithmetic functions The comparison functions

Functional Forms The four Cs constant composition denoted by overbar depends on one object composition denoted by centered small circle depends on two functions

Functional Forms (2) construction conditional denoted by [ ] depends on n functions [f]:x <−> <f:x> (n=1) conditional denoted using −> and ; depends on a predicate and two functions

Functional Forms (3) apply-to-all insert (also known as reduce) denoted by αf depends on one function works only on lists insert (also known as reduce) denoted by /f depends on one function with a number of properties

Exploring reduce Evaluate /f on the list <1,2,3,4,5,6> when f is + - * / ^ max

Exploring apply-to-all Evaluate αf on the list <0, -1, 1, 2, -2> when f is sgn, the function that returns 1 if its argument is positive, -1 if its argument is negative, and 0 otherwise. pow2, where pow2(x) = x^2

Enhanced apply-to-all αf applies f to each element of a list Called apply-to-all apply-to-all1 applies a dyadic function (two arguments) to a fixed object and a list of objects apply-to-all2 applies a dyadic function to a pair of equal length lists

Theorems about Functions Lengths of lists Equivalent compositions of functions

Programming in LISP Our approach; our rules Functions may only use our primitives and user-defined functions. Primitives and functionals may use built-in functions Functions must not use the LISP equivalents of assignment statements or loops Hints: Think recursively Think in parallel Think with composition

Built-In Lisp Functions car cdr reverse length cons append defun cond error funcall mapcar and, or, not fixp numberp zerop, plusp, minusp equal atom null mod +, - , *, / times

Your Turn Create a file using a text editor that contains the LISP definitions of the primitives. Use only the built-in LISP functions listed above. Load your primitives file and test each function thoroughly Create a second file using a text editor that contains the LISP definitions of the functionals. Note: You do not have define composition or condition; they are built into the LISP system.

Your Turn (2) Test your functionals thoroughly. Using the primitives and functionals, define concat, a function that concatenates two lists. Using the primitives and functionals, define IG, the index generator function. (IG n) creates a list of length n containing the first n positive integers. E.g. (IG 5) returns (1 2 3 4 5)

For next time Complete the Your Turn activities.