Functional Programming with Common Lisp
|
|
- Theresa Hawkins
- 5 years ago
- Views:
Transcription
1 Functional Programming with Common Lisp Kamen Tomov July 03, 2015
2 Table of Contents What is This About? Functional Programming Specifics Is Lisp a Functional Language? Lisp Says Hi Functional Programming Features Functional Processing of Sequences Beyond the Functional Paradigm Summary
3 What is This About? What is FP?
4 What is This About? What is FP? In computer science, FP is a programming paradigm a style of building the structure and elements of computer programs that treats computation as the evaluation of mathematical functions It is a declarative programming paradigm (not describing the control flow) which means programming is done with expressions What is expression?
5 What is This About? What is FP? In computer science, FP is a programming paradigm a style of building the structure and elements of computer programs that treats computation as the evaluation of mathematical functions It is a declarative programming paradigm (not describing the control flow) which means programming is done with expressions What is expression? A combination of stuff that according to some rules evaluates to a value What is a functional language made up from?
6 What is This About? What is FP? In computer science, FP is a programming paradigm a style of building the structure and elements of computer programs that treats computation as the evaluation of mathematical functions It is a declarative programming paradigm (not describing the control flow) which means programming is done with expressions What is expression? A combination of stuff that according to some rules evaluates to a value What is a functional language made up from? Functions What is a function?
7 What is This About? What is FP? In computer science, FP is a programming paradigm a style of building the structure and elements of computer programs that treats computation as the evaluation of mathematical functions It is a declarative programming paradigm (not describing the control flow) which means programming is done with expressions What is expression? A combination of stuff that according to some rules evaluates to a value What is a functional language made up from? Functions What is a function? A function is a concept from math that has been with us for centuries: A function is a static, well-defined mapping from input values to output values. For example: f (ax) = 2x + 1
8 What is This About? Functional is the new object-oriented What is the value of Functional Programming? Powerful Paradigm (brings simplicity, clarity, and quality all resulting in shorter development time) Growing availability of features in mainstream languages Growing popularity of functional languages
9 Lisp is a Dinosaur First Appearance: 1958 Invented by John McCarthy at MIT. Steve Russell invents the fundamental eval function Based on Alonzo Church s lambda calculus Influenced by IPL - a bit younger and lower-level language created at RAND Corporation and the Carnegie Institute of Technology First implementation - Steve Russell on an IBM 704 computer
10 What is This About? It wasn t me! When it comes to Lisp, I am: Not a Hacker...
11 What is This About? It wasn t me! When it comes to Lisp, I am: Not a Hacker... Perhaps not yet..
12 What is This About? It wasn t me! When it comes to Lisp, I am: Not a Hacker... Perhaps not yet.. Not a Scientist...
13 What is This About? It wasn t me! When it comes to Lisp, I am: Not a Hacker... Perhaps not yet.. Not a Scientist... It would have been great
14 What is This About? It wasn t me! When it comes to Lisp, I am: Not a Hacker... Perhaps not yet.. Not a Scientist... It would have been great Not a McCarthy contemporary...
15 What is This About? It wasn t me! When it comes to Lisp, I am: Not a Hacker... Perhaps not yet.. Not a Scientist... It would have been great Not a McCarthy contemporary... Believe it or not
16 What is This About? It wasn t me! When it comes to Lisp, I am: Not a Hacker... Perhaps not yet.. Not a Scientist... It would have been great Not a McCarthy contemporary... Believe it or not My only qualification is...
17 What is This About? It wasn t me! When it comes to Lisp, I am: Not a Hacker... Perhaps not yet.. Not a Scientist... It would have been great Not a McCarthy contemporary... Believe it or not My only qualification is... I m extremely good looking
18 Functional Programming Specifics Can you enumerate functional programming languages?
19 Functional Programming Specifics Can you enumerate functional programming languages? What is a must to be able to program functionally?
20 Functional Programming Specifics Can you enumerate functional programming languages? What is a must to be able to program functionally? First-class functions.
21 Functional Programming Specifics Can you enumerate functional programming languages? What is a must to be able to program functionally? First-class functions. What is good to have?
22 Functional Programming Specifics Can you enumerate functional programming languages? What is a must to be able to program functionally? First-class functions. What is good to have? Anonymous functions Recursion Immutability Closures (for optimization) GC Currying Lazy evaluation
23 Functional Programming Specifics Can you enumerate functional programming languages? What is a must to be able to program functionally? First-class functions. What is good to have? Anonymous functions Recursion Immutability Closures (for optimization) GC Currying Lazy evaluation How much of this is needed for a language to qualify for a functional?
24 Is Lisp a Functional Language? defun keyword in Lisp actually creates a funcallable instance, not a static mapping input to output Lisp being functional - origin: (1) an abstraction for locally naming arguments in a piece of re-usable code - manual register and stacks manipulation; (2) procedures being values themselves Back to the definition of a mathematical function and pure functional languages creation Observation: Pure functional is not practical real-world problems solver. Applicable to closed systems. The takeaway: isolation of functional and non-functional parts. What should happen vs how does it happen
25 How does Lisp fit in? Functions are first-class citizens Anything returns value. No statements concept to support horrible infix syntax Lots of the good to have s of the functional languages. Lisp introduced most of them. The rest - via macroses Functional languages vs functional style Not a functional language but a software factory for languages or other code Conclusion
26 What Do Others Say? Lisp has jokingly been called the most intelligent way to misuse a computer. I think that description is a great compliment because it transmits the full flavor of liberation: it has assisted a number of our most gifted fellow humans in thinking previously impossible thoughts. - Edsger Dijkstra, CACM, 15:10 Lisp is worth learning for the profound enlightenment experience you will have when you finally get it; that experience will make you a better programmer for the rest of your days, even if you never actually use Lisp itself a lot. - Eric Raymond, How to Become a Hacker
27 Common Lisp Overview The Lisp Family: Arc, AutoLISP, Clojure, Common Lisp, Emacs Lisp, EuLisp, Franz Lisp, Hy, Interlisp, ISLISP, LeLisp, LFE, Maclisp, MDL, Newlisp, NIL, Picolisp, Portable Standard Lisp, Racket, Scheme, SKILL, Spice Lisp, T, XLISP, Zetalisp Major Lisp dialect: Common Lisp Designed by Scott Fahlman, Richard P. Gabriel, Dave Moon, Guy Steele, Dan Weinreb First appeared in ANSI standard, Kent Pitman Typing: Dynamic, Strong Hardware: General Purpose and Lisp Machines OS: Cross-platform Drop Common
28 Lisp Syntax Calculate 32/2(1 + 3)
29 Lisp Syntax Calculate 32/2(1 + 3) 64
30 Lisp Syntax Calculate 32/2(1 + 3) 64 Calculate (* (/ 16 4) (+ 2 6))
31 Lisp Syntax Calculate 32/2(1 + 3) 64 Calculate (* (/ 16 4) (+ 2 6)) 32
32 Lisp Syntax This is MathML excerpt: <math> <apply> <plus/> <apply> <times/> <ci>a</ci> <apply> <power/> <ci>x</ci> <cn>2</cn> </apply> </apply> <ci>c</ci> </apply> </math>
33 Lisp Syntax This is MathML excerpt: <math> <apply> <plus/> <apply> <times/> <ci>a</ci> <apply> <power/> <ci>x</ci> <cn>2</cn> </apply> </apply> <ci>c</ci> </apply> </math> It is equivalent to: ax 2 + c
34 Lisp Syntax This is MathML excerpt: <math> <apply> <plus/> <apply> <times/> <ci>a</ci> <apply> <power/> <ci>x</ci> <cn>2</cn> </apply> </apply> <ci>c</ci> </apply> </math> It is equivalent to: ax 2 + c How about this: (+ (* a (expt x 2)) c))
35 Lisp Syntax This is MathML excerpt: <math> <apply> <plus/> <apply> <times/> <ci>a</ci> <apply> <power/> <ci>x</ci> <cn>2</cn> </apply> </apply> <ci>c</ci> </apply> </math> It is equivalent to: ax 2 + c How about this: (+ (* a (expt x 2)) c)) And they call parentheses stupid!?
36 Basics x ; the symbol X () ; the empty list (1 2 3) ; a list of three numbers ("foo" "bar") ; a list of two strings (x y z) ; a list of three symbols (x 1 "foo") ; a list of a symbol, a number, and a string (+ (* 2 3) 4) ; a list of a symbol, a list, and a number. (format t "hello, world") (list a b c) (cons a nil) (cons a (list b c)) (car (list a b)) (cdr (list a b)) (car (cons a b)) (cdr (cons a b))
37 Functional Programming Features Functional Programming Features Functions Recursive Functions Higher-order Functions Anonymous Functions Closures Currying Pure Functional vs Destructive Operations
38 Functions (string-upcase "Guess my return value?") (list 6 7 8) (append (list 1 2 3) (4 5 6)) (defun hello-world () "An awesome hello, world" (format t "hello, world")) (defun foo (a b) (values a b)) (multiple-value-bind (a1 a2) (foo 1 2) (list a1 a2)) (defun bar (a &key b c) (+ a b c))
39 Recursive Functions Fibonacci sequence F n = F n 1 + F n 2 F 1 = 1, F 2 = 1 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144,...
40 Recursive Functions Fibonacci sequence F n = F n 1 + F n 2 F 1 = 1, F 2 = 1 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144,... (defun fib-ntl (n) (if (or (= n 1) (= n 2)) 1 (+ (fib-ntl (- n 1)) (fib-ntl (- n 2))))) Can we do better?
41 Recursive Functions Fibonacci sequence F n = F n 1 + F n 2 F 1 = 1, F 2 = 1 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144,... (defun fib-ntl (n) (if (or (= n 1) (= n 2)) 1 (+ (fib-ntl (- n 1)) (fib-ntl (- n 2))))) Can we do better? (defun fib (n &optional (F[n-1] 1) (F[n-2] 0)) (if (= n 1) F[n-1] (fib (1- n) (+ F[n-1] F[n-2]) F[n-1])))
42 Higher-order Functions (count-if # upper-case-p "Functional Programming With Common Lisp") (funcall # ) (apply # + (list 1 2 3)) (defun ex-1 (fn1 fn2 fn3) (or fn1 fn2 fn3)) ; Invoking returned function ; boundp, fboundp, setf, symbol-function (let ((* 3)) (* * *)) (defun ex-2 (fn &rest some-stuff) (apply fn some-stuff))
43 Anonymous Functions (lambda (parameters) body) (lambda (x) (* x 2)) ; invocation (funcall (lambda (x) (* x 2)) 3) ((lambda (x) (* x 2)) 3) ; usage (mapcar # (lambda (x) (* x 2)) (1 2 3))
44 Closures (let ((a 1)) (defun my-closure () a)) (let ((a 1)) (defun my-closure-1 () a) (setq a 7) (defun my-closure-2 () a)) (defun two-funs (x) (list (function (lambda () x)) (function (lambda (y) (setq x y))))) (setq funs (two-funs 6)) (funcall (car funs)) (funcall (cadr funs) 43) (funcall (car funs))
45 Currying
46 Currying Definition The technique of translating the evaluation of a function that takes multiple args (or a tuple) into a sequence of functions, each with a single argument. (defun curry (fn &rest args) (lambda (&rest more-args) (apply fn (append args more-args)))) (funcall (curry # + 3) 5) ( ) (funcall (curry (curry (curry (curry # + 1) 2) 3) 4)) (defun currying (fn lst) (if (null lst) (funcall fn) (currying (curry fn (car lst)) (cdr lst)))) (currying # + ( )) (setf (symbol-function power-of-ten) (curry # expt 10)) (power-of-ten 3)
47 Pure Functional vs Destructive Operations ; Pure functional code: (append (list 1 2) (list 3 4)) ; How does that work internally? Nondestructive Destructive SUBST NSUBST SUBST-IF NSUBST-IF APPEND NCONC BUTLAST NBUTLAST INTERSECTION NINTERSECTION UNION NUNION REVERSE NREVERSE REMOVE DELETE SUBSTITUTE NSUBSTITUTE SUBSTITUTE-IF NSUBSTITUTE-IF REMOVE-DUPLICATES DELETE-DUPLICATES
48 Destructive Operations What is a destructive operation and why would one want to use it?
49 Destructive Operations What is a destructive operation and why would one want to use it? Definition Operations that modify existing objects are called destructive. Two types of destructive operations in Lisp: For-side-effect operations Recycling operations Guess the type? (let ((v (cons a b))) (setf (car v) e) v) (nreverse ( )) One can separate the functional code from the rest.
50 Avoiding Dangerous Operations (defparameter *my-list* (list ))
51 Avoiding Dangerous Operations (defparameter *my-list* (list )) (defun nil-nth (n l) "Set nth element of list to nil and return modified list. (setf (nth n l) nil) l)
52 Avoiding Dangerous Operations (defparameter *my-list* (list )) (defun nil-nth (n l) "Set nth element of list to nil and return modified list. (setf (nth n l) nil) l) (defun nil-nth (n l) "Return list with nth element set to nil." (if (zerop n) (cons nil (rest l)) (cons (car l) (nil-nth (1- n) (rest l)))))
53 Functional Processing of Sequences Functional Processing of Sequences Sequences Map Reduce Take Filter
54 Sequences
55 Sequences Definition Sequences are ordered collections of objects, called the elements of the sequence.
56 Map
57 Map Definition The mapping operation involves applying a function to successive sets of arguments in which one argument is obtained from each sequence. (map list # car ((1 a) (2 b) (3 c))) (mapcar # car ((1 a) (2 b) (3 c))) (map string # (lambda (x y) (char " ABCDEF" (mod (+ x y) 16))) ( ) ( )) (map list # - ( )) (map string # (lambda (x) (if (oddp x) #\1 #\0)) ( ))
58 Reduce
59 Reduce Definition reduce uses a binary operation, FUNCTION, to combine the elements of SEQUENCE bounded by START and END. (reduce # * ( )) (reduce # append ((1) (2)) :initial-value (i n i t)) (reduce # append ((1) (2)) :from-end t :initial-value (i n i t)) (reduce # - ( ) :start 1 :end 5) (reduce # - ( ) :from-end t) (reduce # + ()) (reduce # + (3)) (reduce # list ( )) (reduce # list ( ) :from-end t) (reduce # list ( ) :initial-value foo) (reduce # list ( ) :from-end t :initial-value foo)
60 Take
61 Take Definition Search a sequence for an element that satisfies a test. If found - indicate with the return value. (find-if # oddp ( ) :end 3 :from-end t) (position #\a "baobab" :from-end t) (position-if # oddp ((1) (2) (3) (4)) :start 1 :key # car) (position-if (complement # oddp) ((1) (2) (3) (4)) :start (search "dog" "it s a dog s life") (mismatch "abcd" "ABCDE" :test # char-equal)
62 Filter
63 Filter Definition Filter is a higher-order function that processes a sequence in some order to produce a new sequence containing exactly those elements of the original sequence for which a given predicate returns the boolean value true. (remove-if # oddp #( )) (remove 4 ( )) (remove 4 ( ) :count 1) (mapcan # (lambda (x) (and (numberp x) (list x))) (a 1 b c 3 4 d 5)) (remove 3 ( ) :test # >) delete and delete-if are like remove and remove-if respectively, but they may modify the sequence. Possible side effect
64 The Powerful Macro System (setq a 1)
65 The Powerful Macro System (setq a 1) (resetq 1 a)
66 The Powerful Macro System (setq a 1) (resetq 1 a) (defmacro resetq (val var) (setq,var,val))
67 The Powerful Macro System (setq a 1) (resetq 1 a) (defmacro resetq (val var) (setq,var,val)) However, SETQ is more than that..
68 Yet Another SETQ - the List Resetter I (defun resetify1 1 (lst) (do ((result) (fst (first lst) (first lst)) (snd (second lst) (second lst))) ((null lst) (nreverse result)) (push snd result) (push fst result) (pop lst) (pop lst)))
69 Yet Another SETQ - the List Resetter II (defun resetify2 (lst &optional result) (if (null lst) result (resetify2 (cddr lst) (append result (list (second lst) (first lst))))))
70 Yet Another SETQ - the Macro (defmacro resetq (&body args) (setq,@(resetify args)))
71 Yet Another SETQ - Local Function (defmacro resetq (&body args) (labels ((resetify (lst &optional result) (print "ran") (if (null lst) result (resetify (cddr lst) (append result (list (second lst) (first lst))))))) (setq,@(resetify args))))
72 Summary Functional Programming Lisp
73 Becoming a Lisp Hacker Play Read & Discuss Web Site: Newsgroup: comp.lang.lisp IRC channel: #lisp
74 The End Further Questions?
75 Acknowledgments To those who gave us Lisp, its libraries and tools The Common Lisp HyperSpec by Kent M. Pitman Practical Common Lisp - Peter Seibel On Lisp - Paul Graham The Common Lisp Cookbook Project Let Over Lambda by Doug Hoyte Successful Lisp by David B. Lamkins Wikipedia, Linux, Emacs, Texinfo, Beamer, etc.
INF4820: Algorithms for Artificial Intelligence and Natural Language Processing. Common Lisp Fundamentals
INF4820: Algorithms for Artificial Intelligence and Natural Language Processing Common Lisp Fundamentals Stephan Oepen & Murhaf Fares Language Technology Group (LTG) August 30, 2017 Last Week: What is
More informationImperative, OO and Functional Languages A C program is
Imperative, OO and Functional Languages A C program is a web of assignment statements, interconnected by control constructs which describe the time sequence in which they are to be executed. In Java programming,
More informationSection 10: LISP to Scheme. Evolution of Software Languages
Section Evolution of Software Languages Theo D'Hondt Bachelor of Computer Science Faculty of Sciences and Bio-Engineering Sciences Vrije Universiteit Brussel Academic Year 2015-2016 Evolution of Software
More informationFunctional Languages. CSE 307 Principles of Programming Languages Stony Brook University
Functional Languages CSE 307 Principles of Programming Languages Stony Brook University http://www.cs.stonybrook.edu/~cse307 1 Historical Origins 2 The imperative and functional models grew out of work
More informationINF4820. Common Lisp: Closures and Macros
INF4820 Common Lisp: Closures and Macros Erik Velldal University of Oslo Oct. 19, 2010 Erik Velldal INF4820 1 / 22 Topics for Today More Common Lisp A quick reminder: Scope, binding and shadowing Closures
More informationFunctional Programming. Big Picture. Design of Programming Languages
Functional Programming Big Picture What we ve learned so far: Imperative Programming Languages Variables, binding, scoping, reference environment, etc What s next: Functional Programming Languages Semantics
More informationIntroduction to Lisp
Last update: February 16, 2010 Introduction to Lisp Dana Nau Dana Nau 1 Outline I assume you know enough about computer languages that you can learn new ones quickly, so I ll go pretty fast If I go too
More informationRobot Programming with Lisp
4. Functional Programming: Higher-order Functions, Map/Reduce, Lexical Scope Institute for Artificial University of Bremen 9 of November, 2017 Functional Programming Pure functional programming concepts
More information4/19/2018. Chapter 11 :: Functional Languages
Chapter 11 :: Functional Languages Programming Language Pragmatics Michael L. Scott Historical Origins The imperative and functional models grew out of work undertaken by Alan Turing, Alonzo Church, Stephen
More informationFUNKCIONÁLNÍ A LOGICKÉ PROGRAMOVÁNÍ 2. ÚVOD DO LISPU: ATOMY, SEZNAMY, FUNKCE,
FUNKCIONÁLNÍ A LOGICKÉ PROGRAMOVÁNÍ 2. ÚVOD DO LISPU: ATOMY, SEZNAMY, FUNKCE, 2011 Jan Janoušek MI-FLP Evropský sociální fond Praha & EU: Investujeme do vaší budoucnosti L I S P - Introduction L I S P
More informationAnnouncement. Overview. LISP: A Quick Overview. Outline of Writing and Running Lisp.
Overview Announcement Announcement Lisp Basics CMUCL to be available on sun.cs. You may use GNU Common List (GCL http://www.gnu.org/software/gcl/ which is available on most Linux platforms. There is also
More informationCS 314 Principles of Programming Languages
CS 314 Principles of Programming Languages Lecture 16: Functional Programming Zheng (Eddy Zhang Rutgers University April 2, 2018 Review: Computation Paradigms Functional: Composition of operations on data.
More informationCS 480. Lisp J. Kosecka George Mason University. Lisp Slides
CS 480 Lisp J. Kosecka George Mason University Lisp Slides Symbolic Programming Symbols: +, -, 1, 2 etc. Symbolic expressions: (+ 1 2), (+ (* 3 4) 2) Symbolic programs are programs that manipulate symbolic
More informationCommon Lisp. Blake McBride
Contents Common Lisp Blake McBride (blake@mcbride.name) 1 Data Types 2 2 Numeric Hierarchy 3 3 Comments 3 4 List Operations 4 5 Evaluation and Quotes 5 6 String Operations 5 7 Predicates 6 8 Math Predicates
More informationCommon LISP Tutorial 1 (Basic)
Common LISP Tutorial 1 (Basic) CLISP Download https://sourceforge.net/projects/clisp/ IPPL Course Materials (UST sir only) Download https://silp.iiita.ac.in/wordpress/?page_id=494 Introduction Lisp (1958)
More informationSymbolic Programming. Dr. Zoran Duric () Symbolic Programming 1/ 89 August 28, / 89
Symbolic Programming Symbols: +, -, 1, 2 etc. Symbolic expressions: (+ 1 2), (+ (* 3 4) 2) Symbolic programs are programs that manipulate symbolic expressions. Symbolic manipulation: you do it all the
More informationCommon LISP-Introduction
Common LISP-Introduction 1. The primary data structure in LISP is called the s-expression (symbolic expression). There are two basic types of s-expressions: atoms and lists. 2. The LISP language is normally
More informationRobot Programming with Lisp
2. Imperative Programming Institute for Artificial University of Bremen Lisp the Language LISP LISt Processing language 2 Lisp the Language LISP LISt Processing language (LISP Lots of Irritating Superfluous
More informationCOP4020 Programming Languages. Functional Programming Prof. Robert van Engelen
COP4020 Programming Languages Functional Programming Prof. Robert van Engelen Overview What is functional programming? Historical origins of functional programming Functional programming today Concepts
More informationA Brief Introduction to Common Lisp
A Brief Introduction to Common Lisp David Gu Schloer Consulting Group david_guru@gty.org.in A Brief History Originally specified in 1958, Lisp is the second-oldest highlevel programming language in widespread
More informationFunctional Programming Lecture 1: Introduction
Functional Programming Lecture 1: Introduction Viliam Lisý Artificial Intelligence Center Department of Computer Science FEE, Czech Technical University in Prague viliam.lisy@fel.cvut.cz Acknowledgements
More informationLisp Basic Example Test Questions
2009 November 30 Lisp Basic Example Test Questions 1. Assume the following forms have been typed into the interpreter and evaluated in the given sequence. ( defun a ( y ) ( reverse y ) ) ( setq a (1 2
More informationINF4820: Algorithms for Artificial Intelligence and Natural Language Processing. More Common Lisp
INF4820: Algorithms for Artificial Intelligence and Natural Language Processing More Common Lisp Stephan Oepen & Murhaf Fares Language Technology Group (LTG) September 6, 2017 Agenda 2 Previously Common
More informationFunctional programming with Common Lisp
Functional programming with Common Lisp Dr. C. Constantinides Department of Computer Science and Software Engineering Concordia University Montreal, Canada August 11, 2016 1 / 81 Expressions and functions
More informationModern Programming Languages. Lecture LISP Programming Language An Introduction
Modern Programming Languages Lecture 18-21 LISP Programming Language An Introduction 72 Functional Programming Paradigm and LISP Functional programming is a style of programming that emphasizes the evaluation
More informationDepartment of Computer and information Science Norwegian University of Science and Technology
Department of Computer and information Science Norwegian University of Science and Technology http://www.idi.ntnu.no/ A Crash Course in LISP MNFIT272 2002 Anders Kofod-Petersen anderpe@idi.ntnu.no Introduction
More informationArtificial Intelligence Programming
Artificial Intelligence Programming Rob St. Amant Department of Computer Science North Carolina State University Lisp basics NC State University 2 / 99 Why Lisp? Some recent Lisp success stories include
More informationA little bit of Lisp
B.Y. Choueiry 1 Instructor s notes #3 A little bit of Lisp Introduction to Artificial Intelligence CSCE 476-876, Fall 2017 www.cse.unl.edu/~choueiry/f17-476-876 Read LWH: Chapters 1, 2, 3, and 4. Every
More informationScheme. Functional Programming. Lambda Calculus. CSC 4101: Programming Languages 1. Textbook, Sections , 13.7
Scheme Textbook, Sections 13.1 13.3, 13.7 1 Functional Programming Based on mathematical functions Take argument, return value Only function call, no assignment Functions are first-class values E.g., functions
More informationFUNKCIONÁLNÍ A LOGICKÉ PROGRAMOVÁNÍ 4. LISP: PROMĚNNÉ, DALŠÍ VLASTNOSTI FUNKCÍ, BLOKY, MAPOVACÍ FUNKCIONÁLY, ITERAČNÍ CYKLY,
FUNKCIONÁLNÍ A LOGICKÉ PROGRAMOVÁNÍ 4. LISP: PROMĚNNÉ, DALŠÍ VLASTNOSTI FUNKCÍ, BLOKY, MAPOVACÍ FUNKCIONÁLY, ITERAČNÍ CYKLY, 2011 Jan Janoušek MI-FLP Evropský sociální fond Praha & EU: Investujeme do vaší
More informationFunctional Programming
Functional Programming CS 1025 Computer Science Fundamentals I Stephen M. Watt University of Western Ontario When the Function is the Thing In O-O programming, you typically know where an action is needed,
More informationFunctional Programming
Functional Programming CS331 Chapter 14 Functional Programming Original functional language is LISP LISt Processing The list is the fundamental data structure Developed by John McCarthy in the 60 s Used
More informationLECTURE 16. Functional Programming
LECTURE 16 Functional Programming WHAT IS FUNCTIONAL PROGRAMMING? Functional programming defines the outputs of a program as a mathematical function of the inputs. Functional programming is a declarative
More informationDocumentation for LISP in BASIC
Documentation for LISP in BASIC The software and the documentation are both Copyright 2008 Arthur Nunes-Harwitt LISP in BASIC is a LISP interpreter for a Scheme-like dialect of LISP, which happens to have
More informationReview of Functional Programming
Review of Functional Programming York University Department of Computer Science and Engineering 1 Function and # It is good programming practice to use function instead of quote when quoting functions.
More informationLISP. Everything in a computer is a string of binary digits, ones and zeros, which everyone calls bits.
LISP Everything in a computer is a string of binary digits, ones and zeros, which everyone calls bits. From one perspective, sequences of bits can be interpreted as a code for ordinary decimal digits,
More information11/6/17. Functional programming. FP Foundations, Scheme (2) LISP Data Types. LISP Data Types. LISP Data Types. Scheme. LISP: John McCarthy 1958 MIT
Functional programming FP Foundations, Scheme (2 In Text: Chapter 15 LISP: John McCarthy 1958 MIT List Processing => Symbolic Manipulation First functional programming language Every version after the
More informationLecture Notes on Lisp A Brief Introduction
Why Lisp? Lecture Notes on Lisp A Brief Introduction Because it s the most widely used AI programming language Because Prof Peng likes using it Because it s good for writing production software (Graham
More informationIntroduction to LISP. York University Department of Computer Science and Engineering. York University- CSE V.
Introduction to LISP York University Department of Computer Science and Engineering York University- CSE 3401- V. Movahedi 11_LISP 1 Introduction to LISP Evaluation and arguments S- expressions Lists Numbers
More informationNotes on Higher Order Programming in Scheme. by Alexander Stepanov
by Alexander Stepanov August 1986 INTRODUCTION Why Scheme? Because it allows us to deal with: 1. Data Abstraction - it allows us to implement ADT (abstact data types) in a very special way. The issue of
More informationIntroduction 2 Lisp Part III
Introduction 2 Lisp Part III Andreas Wichert LEIC-T (Página da cadeira: Fenix) (I) Home Work (II) Data Types and Generic Programming (III) Lisp is Science (IV) Lisp Macros (V) More about Common Lisp an
More informationChapter 11 :: Functional Languages
Chapter 11 :: Functional Languages Programming Language Pragmatics Michael L. Scott Copyright 2016 Elsevier 1 Chapter11_Functional_Languages_4e - Tue November 21, 2017 Historical Origins The imperative
More informationSummer 2017 Discussion 10: July 25, Introduction. 2 Primitives and Define
CS 6A Scheme Summer 207 Discussion 0: July 25, 207 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,
More informationFunctional Programming. Pure Functional Programming
Functional Programming Pure Functional Programming Computation is largely performed by applying functions to values. The value of an expression depends only on the values of its sub-expressions (if any).
More informationCSCI337 Organisation of Programming Languages LISP
Organisation of Programming Languages LISP Getting Started Starting Common Lisp $ clisp i i i i i i i ooooo o ooooooo ooooo ooooo I I I I I I I 8 8 8 8 8 o 8 8 I \ `+' / I 8 8 8 8 8 8 \ `-+-' / 8 8 8 ooooo
More informationSCHEME AND CALCULATOR 5b
SCHEME AND CALCULATOR 5b COMPUTER SCIENCE 6A July 25, 203 In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,
More informationFP Foundations, Scheme
FP Foundations, Scheme In Text: Chapter 15 1 Functional Programming -- Prelude We have been discussing imperative languages C/C++, Java, Fortran, Pascal etc. are imperative languages Imperative languages
More informationCS 842 Ben Cassell University of Waterloo
CS 842 Ben Cassell University of Waterloo Recursive Descent Re-Cap Top-down parser. Works down parse tree using the formal grammar. Built from mutually recursive procedures. Typically these procedures
More informationProgramming Language Pragmatics
Chapter 10 :: Functional Languages Programming Language Pragmatics Michael L. Scott Historical Origins The imperative and functional models grew out of work undertaken Alan Turing, Alonzo Church, Stephen
More informationSCHEME 8. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. March 23, 2017
SCHEME 8 COMPUTER SCIENCE 61A March 2, 2017 1 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,
More informationFunctional programming in LISP
Programming Languages Week 4 Functional programming in LISP College of Information Science and Engineering Ritsumeikan University review of part 3 enumeration of dictionaries you receive a sequence of
More informationJohn McCarthy IBM 704
How this course works SI 334: Principles of Programming Languages Lecture 2: Lisp Instructor: an arowy Lots of new languages Not enough class time to cover all features (e.g., Java over the course of 34-36:
More informationAllegro CL Certification Program
Allegro CL Certification Program Lisp Programming Series Level I Session 1.3.1 David Margolies Manipulating Lists 9/16/2010 1 What is a List? An ordered (possibly empty) collection of things in a particular
More informationA Quick Introduction to Common Lisp
CSC 244/444 Notes last updated ug. 30, 2016 Quick Introduction to Common Lisp Lisp is a functional language well-suited to symbolic I, based on the λ-calculus and with list structures as a very flexible
More informationAssociative Database Managment WIlensky Chapter 22
Associative Database Managment WIlensky Chapter 22 DB-1 Associative Database An associative database is a collection of facts retrievable by their contents» Is a poodle a dog? Which people does Alice manage?»
More informationLambda Calculus see notes on Lambda Calculus
Lambda Calculus see notes on Lambda Calculus Shakil M. Khan adapted from Gunnar Gotshalks recap so far: Lisp data structures basic Lisp programming bound/free variables, scope of variables Lisp symbols,
More informationAssociative Database Managment
Associative Database Managment WIlensky Chapter 22 DB-1 Associative Database An associative database is a collection of facts retrievable by their contents» Is a poodle a dog? Which people does Alice manage?»
More informationSCHEME 7. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. October 29, 2015
SCHEME 7 COMPUTER SCIENCE 61A October 29, 2015 1 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,
More informationCS A331 Programming Language Concepts
CS A331 Programming Language Concepts Lecture 10 Alternative Programming Languages (Functional LISP Declarative - PROLOG) March 24, 2014 Sam Siewert Functional PL Concepts Based on Lambda Calculus Output
More informationScheme: Expressions & Procedures
Scheme: Expressions & Procedures CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Friday, March 31, 2017 Glenn G. Chappell Department of Computer Science University
More informationProgramming Systems in Artificial Intelligence Functional Programming
Click to add Text Programming Systems in Artificial Intelligence Functional Programming Siegfried Nijssen 8/03/16 Discover thediscover world at the Leiden world University at Leiden University Overview
More informationAllegro CL Certification Program
Allegro CL Certification Program Lisp Programming Series Level I Presented by 1 About David Margolies Manager, Documentation, Franz Inc Been working with Lisp since 1984 dm@franz.com 2 About Franz Inc.
More informationFunctional Programming. Pure Functional Languages
Functional Programming Pure functional PLs S-expressions cons, car, cdr Defining functions read-eval-print loop of Lisp interpreter Examples of recursive functions Shallow, deep Equality testing 1 Pure
More informationIntroduction to Functional Programming
PART I TE RI AL Introduction to Functional Programming MA CHAPTER 1: A Look at Functional Programming History CO PY RI GH TE D CHAPTER 2: Putting Functional Programming into a Modern Context 1A Look at
More informationIntroduction to Functional Programming
Introduction to Functional Programming Xiao Jia xjia@cs.sjtu.edu.cn Summer 2013 Scheme Appeared in 1975 Designed by Guy L. Steele Gerald Jay Sussman Influenced by Lisp, ALGOL Influenced Common Lisp, Haskell,
More informationSCHEME The Scheme Interpreter. 2 Primitives COMPUTER SCIENCE 61A. October 29th, 2012
SCHEME COMPUTER SCIENCE 6A October 29th, 202 In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs, we will eventually
More information19 Machine Learning in Lisp
19 Machine Learning in Lisp Chapter Objectives Chapter Contents ID3 algorithm and inducing decision trees from lists of examples. A basic Lisp implementation of ID3 Demonstration on a simple credit assessment
More informationA Genetic Algorithm Implementation
A Genetic Algorithm Implementation Roy M. Turner (rturner@maine.edu) Spring 2017 Contents 1 Introduction 3 2 Header information 3 3 Class definitions 3 3.1 Individual..........................................
More informationImperative languages
Imperative languages Von Neumann model: store with addressable locations machine code: effect achieved by changing contents of store locations instructions executed in sequence, flow of control altered
More informationIntroduction to Functional Programming and basic Lisp
Introduction to Functional Programming and basic Lisp Based on Slides by Yves Lespérance & Peter Roosen-Runge 1 Functional vs Declarative Programming declarative programming uses logical statements to
More informationScheme: Data. CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, April 3, Glenn G.
Scheme: Data CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, April 3, 2017 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks ggchappell@alaska.edu
More informationOrganization of Programming Languages CS3200/5200N. Lecture 11
Organization of Programming Languages CS3200/5200N Razvan C. Bunescu School of Electrical Engineering and Computer Science bunescu@ohio.edu Functional vs. Imperative The design of the imperative languages
More informationFunctional Programming. Pure Functional Languages
Functional Programming Pure functional PLs S-expressions cons, car, cdr Defining functions read-eval-print loop of Lisp interpreter Examples of recursive functions Shallow, deep Equality testing 1 Pure
More informationPutting the fun in functional programming
CM20167 Topic 4: Map, Lambda, Filter Guy McCusker 1W2.1 Outline 1 Introduction to higher-order functions 2 Map 3 Lambda 4 Filter Guy McCusker (1W2.1 CM20167 Topic 4 2 / 42 Putting the fun in functional
More informationFunctional Programming Languages (FPL)
Functional Programming Languages (FPL) 1. Definitions... 2 2. Applications... 2 3. Examples... 3 4. FPL Characteristics:... 3 5. Lambda calculus (LC)... 4 6. Functions in FPLs... 7 7. Modern functional
More informationAnnouncements. Today s Menu
Announcements 1 Today s Menu Finish Introduction to ANNs (original material by Dr. Mike Nechyba) > Slides 58-60 > Adjusting the Learning Rate Loose Ends in > Lambda Expressions Review > I/O Functions >
More informationA Small Interpreted Language
A Small Interpreted Language What would you need to build a small computing language based on mathematical principles? The language should be simple, Turing equivalent (i.e.: it can compute anything that
More informationLambda Calculus and Lambda notation in Lisp II. Based on Prof. Gotshalks notes on Lambda Calculus and Chapter 9 in Wilensky.
λ Calculus Basis Lambda Calculus and Lambda notation in Lisp II Based on Prof. Gotshalks notes on Lambda Calculus and Chapter 9 in Wilensky Mathematical theory for anonymous functions» functions that have
More informationFunctional Programming
Functional Programming Björn B. Brandenburg The University of North Carolina at Chapel Hill Based in part on slides and notes by S. Olivier, A. Block, N. Fisher, F. Hernandez-Campos, and D. Stotts. Brief
More informationMeet the Macro. a quick introduction to Lisp macros. Patrick Stein / TC Lisp Users Group /
Meet the Macro a quick introduction to Lisp macros Patrick Stein / TC Lisp Users Group / 2009-07-14 Attack Plan Some other things called macros First look at Lisp macros More advanced macros Uh-oh, my
More informationCPS 506 Comparative Programming Languages. Programming Language Paradigm
CPS 506 Comparative Programming Languages Functional Programming Language Paradigm Topics Introduction Mathematical Functions Fundamentals of Functional Programming Languages The First Functional Programming
More informationObject Oriented Programming (OOP)
Object Oriented Programming (OOP) o New programming paradigm o Actions Objects o Objects Actions o Object-oriented = Objects + Classes + Inheritance Imperative programming o OOP (Object-Oriented Programming)
More informationFunctional Languages. Hwansoo Han
Functional Languages Hwansoo Han Historical Origins Imperative and functional models Alan Turing, Alonzo Church, Stephen Kleene, Emil Post, etc. ~1930s Different formalizations of the notion of an algorithm
More informationCIS4/681 { Articial Intelligence 2 > (insert-sort '( )) ( ) 2 More Complicated Recursion So far everything we have dened requires
1 A couple of Functions 1 Let's take another example of a simple lisp function { one that does insertion sort. Let us assume that this sort function takes as input a list of numbers and sorts them in ascending
More informationFundamentals of Artificial Intelligence COMP221: Functional Programming in Scheme (and LISP)
Fundamentals of Artificial Intelligence COMP221: Functional Programming in Scheme (and LISP) Prof. Dekai Wu Department of Computer Science and Engineering The Hong Kong University of Science and Technology
More informationSOFTWARE ARCHITECTURE 6. LISP
1 SOFTWARE ARCHITECTURE 6. LISP Tatsuya Hagino hagino@sfc.keio.ac.jp slides URL https://vu5.sfc.keio.ac.jp/sa/ 2 Compiler vs Interpreter Compiler Translate programs into machine languages Compilers are
More informationCOMMOM OBJECT ORIENTED LISP SYSTEMS
COMMOM OBJECT ORIENTED LISP SYSTEMS HISTORY: The following information is derived from the history section of dpans Common Lisp. Lisp is a family of languages with a long history. Early key ideas in Lisp
More information15 Unification and Embedded Languages in Lisp
15 Unification and Embedded Languages in Lisp Chapter Objectives Chapter Contents Pattern matching in Lisp: Database examples Full unification as required for Predicate Calculus problem solving Needed
More informationFUNKCIONÁLNÍ A LOGICKÉ PROGRAMOVÁNÍ 3. LISP: ZÁKLADNÍ FUNKCE, POUŽÍVÁNÍ REKURZE,
FUNKCIONÁLNÍ A LOGICKÉ PROGRAMOVÁNÍ 3. LISP: ZÁKLADNÍ FUNKCE, POUŽÍVÁNÍ REKURZE, 2011 Jan Janoušek MI-FLP Evropský sociální fond Praha & EU: Investujeme do vaší budoucnosti Comments in Lisp ; comments
More informationALISP interpreter in Awk
ALISP interpreter in Awk Roger Rohrbach 1592 Union St., #94 San Francisco, CA 94123 January 3, 1989 ABSTRACT This note describes a simple interpreter for the LISP programming language, written in awk.
More informationGene Kim 9/9/2016 CSC 2/444 Lisp Tutorial
Gene Kim 9/9/2016 CSC 2/444 Lisp Tutorial About this Document This document was written to accompany an in-person Lisp tutorial. Therefore, the information on this document alone is not likely to be sufficient
More informationFunctional Programming and Haskell
Functional Programming and Haskell Tim Dawborn University of Sydney, Australia School of Information Technologies Tim Dawborn Functional Programming and Haskell 1/22 What are Programming Paradigms? A programming
More informationRecursion & Iteration
Recursion & Iteration York University Department of Computer Science and Engineering 1 Overview Recursion Examples Iteration Examples Iteration vs. Recursion Example [ref.: Chap 5,6 Wilensky] 2 Recursion
More informationCommon Lisp Object System Specification. 1. Programmer Interface Concepts
Common Lisp Object System Specification 1. Programmer Interface Concepts Authors: Daniel G. Bobrow, Linda G. DeMichiel, Richard P. Gabriel, Sonya E. Keene, Gregor Kiczales, and David A. Moon. Draft Dated:
More informationPrinciples of Programming Languages
Principles of Programming Languages www.cs.bgu.ac.il/~ppl172 Lesson 6 - Defining a Programming Language Bottom Up Collaboration and Management - Elements of Programming Dana Fisman 1 What we accomplished
More informationFunctional Programming. Contents
Functional Programming Gunnar Gotshalks 2003 September 27 Contents Introduction... 2 Example for Inner Product... 2 Basis Set for Functionals... 3 Example Function Definitions... 3 Lisp Builtin Functionals...
More informationFall 2018 Discussion 8: October 24, 2018 Solutions. 1 Introduction. 2 Primitives
CS 6A Scheme Fall 208 Discussion 8: October 24, 208 Solutions Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write
More informationLecture #2 Kenneth W. Flynn RPI CS
Outline Programming in Lisp Lecture #2 Kenneth W. Flynn RPI CS Items from last time Recursion, briefly How to run Lisp I/O, Variables and other miscellany Lists Arrays Other data structures Jin Li lij3@rpi.edu
More information(Func&onal (Programming (in (Scheme)))) Jianguo Lu
(Func&onal (Programming (in (Scheme)))) Jianguo Lu 1 Programming paradigms Func&onal No assignment statement No side effect Use recursion Logic OOP AOP 2 What is func&onal programming It is NOT what you
More informationFall 2017 Discussion 7: October 25, 2017 Solutions. 1 Introduction. 2 Primitives
CS 6A Scheme Fall 207 Discussion 7: October 25, 207 Solutions Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write
More information