Functional Programming. Big Picture. Design of Programming Languages


 Mabel Joanna Richards
 1 years ago
 Views:
Transcription
1 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 of Programming Languages Control Flow Data Types Logic Programming Subroutines, Procedures: Control Abstraction Data Abstraction and ObjectOrientation Design of Programming Languages Design of imperative languages is based directly on the von Neumann architecture Efficiency is the primary concern, rather than the suitability of the language for software development Other designs: Functional programming languages Based on mathematical functions Logic programming languages Based on formal logic (specifically, predicate calculus) 1
2 Design View of a Program If we ignore the details of computation ( how of computation) and focus on the result being computed ( what of computation) A program becomes a black box for obtaining output from input Input Program Output Functional Programming Language Functional programming is a style of programming in which the primary method of computation is the application of functions to arguments x Argument or variable f(x) Function y Output 1940s: Historical Background Alonzo Church and Haskell Curry developed the lambda calculus, a simple but powerful mathematical theory of functions. 6 2
3 1960s: Historical Background John McCarthy developed Lisp, the first functional language. Some influences from the lambda calculus, but still retained variable assignments : Historical Background John Backus publishes award winning article on FP, a functional language that emphasizes higherorder functions and calculating with programs. 8 Mid 1970s: Historical Background Robin Milner develops ML, the first of the modern functional languages, which introduced type inference and polymorphic types. 9 3
4 Historical Background Late 1970s s: David Turner develops a number of lazy functional languages leading up to Miranda, a commercial product. 10 Historical Background 1988: A committee of prominent researchers publishes the first definition of Haskell, a standard lazy functional language. 11 Historical Background 1999: The committee publishes the definition of Haskell 98, providing a longawaited stable version of the language. 12 4
5 Basic Idea of Functional Programming Think of programs, procedures and functions as being represented by the mathematical concept of a function A mathematical function: {elts in domain}? {elts in range} Example: sin(x) domain set: set of all real numbers range set: set of real numbers from 1 to +1 In mathematics, variables always represent actual values There is no such thing as a variable that models a memory location Since there is no concept of memory location or lvalue of variables, a statement such as (x = x + 1) makes no sense A mathematical function defines a value, rather than specifying a sequence of operations on values in memory Imperative Programming Summing the integers 1 to 10 in Java: total = 0; for (i = 1; i? 10; ++i) total = total + i; The computation method is variable assignment Each variable is associated with a memory location 14 Functional Programming Summing the integers 1 to 10 in Haskell: sum [1..10] The computation method is function application. 15 5
6 Functional Programming Function definition vs function application Function definition Declaration describing how a function is to be computed using formal parameters Function application A call to a declared function using actual parameters or arguments In mathematics, a distinction is often not clearly made between a variable and a parameter The term independent variable is often used for both actual and formal parameters Functional Programming Language The objective of the design of a FPL is to mimic mathematical functions to the greatest extent possible Imperative language: operations are completed and results are stored in variables for later use Management of variables is source of complexity for imperative programming FPL: variables are not necessary Without variables, iterative constructs are impossible Repetition must be provided by recursion rather than iterative constructs Example: GCD Find the greatest common divisor (GCD) between 12 and 30 Divisors for 12: 1, 2, 3, 4, 6, 12 Divisors for 30: 1, 2, 3, 5, 6, 10, 15, 30 GCD(12, 30) is equal to 6 Algorithm: u=30, v=12 30 mod 12 = 6 u=12, v=6 12 mod 6 = 0 u=6, v=0 since v=0, GCD=u=6 6
7 Computing GCD int gcd(int u, int v) { int temp; while (v!= 0) { temp = v; v = u % v; u = temp; } return u; } * Computing GCD using iterative construct int gcd(int u, int v) { if (v==0) return u; else return gcd(v, u % v); } * Computing GCD using recursion Fundamentals of FPLs Referential transparency: In FPL, the evaluation of a function always produces the same result given the same parameters E.g., a function rand, which returns a (pseudo) random value, cannot be referentially transparent since it depends on the state of the machine (and previous calls to itself) Most functional languages are implemented with interpreters Using Imperative PLs to support FPLs Limitations Imperative languages often have restrictions on the types of values returned by the function Example: in Fortran, only scalar values can be returned Most of them cannot return functions This limits the kinds of functional forms that can be provided Functional sideeffects Occurs when the function changes one of its parameters or a global variable 7
8 Characteristics of Pure FPL Pure FP languages tend to Have no sideeffects Have no assignment statements Often have no variables! Be built on a small, concise framework Have a simple, uniform syntax Be implemented via interpreters rather than compilers Functional Programming Languages FPL provides a set of primitive functions, a set of functional forms to construct complex functions, a function application operation, some structure to represent data In functional programming, functions are viewed as values themselves, which can be computed by other functions and can be parameters to other functions Functions are firstclass values Lambda Expressions Function definitions are often written as a function name, followed by list of parameters and mapping expression: Example: cube (x)? x * x * x A lambda expression provides a method for defining nameless functions?(x) x * x * x Nameless functions are useful, e.g., functions that are produced for intermediate application to a parameter list do not need a name, for it is applied only at the point of its construction 8
9 Lambda Expressions Function application Lambda expressions are applied to parameter(s) by placing the parameter(s) after the expression e.g. (?(x) x * x * x)(3) evaluates to 27 Lambda expressions can have more than one parameter e.g.?(x, y) x / y Functional Forms A functional form, is a function that either takes functions as parameters, yields a function as its result, or both Also known as higherorder function Function Composition: A functional form that takes two functions as parameters and yields a function whose result is a function whose value is the first actual parameter function applied to the result of the application of the second Example: h??f g which means h (x)? f ( g ( x)) Functional Forms Construction: A functional form that takes a list of functions as parameters and yields a list of the results of applying each of its parameter functions to a given parameter For f (x)? x * x * x and g (x)? x + 3, [f, g] (4) yields (64, 7) Applytoall: A functional form that takes a single function as a parameter and yields a list of values obtained by applying the given function to each element of a list of parameters For h (x)? x * x * x,? ( h, (3, 2, 4)) yields (27, 8, 64) 9
10 LISP Stands for LISt Processing Originally, LISP was a typeless language and used for symbolic processing in AI Two data types: atoms (consists of symbols and numbers) lists (that consist of atoms and nested lists) LISP lists are stored internally as singlelinked lists Lambda notation is used to specify nameless functions (function_name (LAMBDA (arg_1 arg_n) expression)) LISP Function definitions, function applications, and data all have the same form Example: If the list (A B C) is interpreted as data, it is a simple list of three atoms, A, B, and C If it is interpreted as a function application, it means that the function named A is applied to the two parameters, B and C This uniformity of data and programs gives functional languages their flexibility and expressive power programs can be manipulated dynamically LISP The first LISP interpreter appeared only as a demonstration of the universality of the computational capabilities of the notation Example (early Lisp): (defun fact (n) (cond ((lessp n 2) 1)(T (times n (fact (sub1 n)))))) The original intent was to have a notation for LISP programs that would be as close to Fortran s as possible, with additions when necessary This notation was called Mnotation, for metanotation McCarthy believed that list processing could be used to study computability, which at the time was usually studied using Turing machines McCarthy thought that symbolic lists was a more natural model of computation than Turing machines Common Lisp is the ANSI standard Lisp specification All LISP structures, including code and data, have uniform structure Called Sexpressions 10
11 LISP EVAL: a universal function that could evaluate any other functions LISP 1.5: Awkward though elegantly uniform syntax. Dynamic scope rule Inconsistent treatment of functions as arguments because of dynamic scoping Scheme A mid1970s dialect of LISP, designed to be cleaner, more modern, and simpler version than the contemporary dialects of LISP Uses only static scoping Functions are firstclass entities They can be the values of expressions and elements of lists They can be assigned to variables and passed as parameters Scheme Arithmetic: +, , *, /, ABS, SQRT (+ 5 2) yields 7 Most interpreters use prefix notations: ( ) means add 3, 5, and 7 (+ (* 3 5) ( 10 6)) Advantages: Operator/function can take arbitrary number of arguments No ambiguity, because operator is always the leftmost element and the entire combination is delimited by parentheses 11
12 QUOTE Scheme takes one parameter; returns the parameter without evaluation QUOTE is required because the Scheme interpreter, named EVAL, always evaluates parameters to function applications before applying the function. QUOTE is used to avoid parameter valuation when it is not appropriate QUOTE can be abbreviated with the apostrophe prefix operator '(A B) is equivalent to (QUOTE (A B)) (list a b c) versus (list 'a 'b 'c) Scheme  LIST takes any number of parameters; returns a list with the parameters as elements CAR takes a list parameter; returns the first element of that list (CAR '(A B C)) yields A (CAR '((A B) C D)) yields (A B) CDR takes a list parameter; returns the list after removing its first element (CDR '(A B C)) yields (B C) (CDR '((A B) C D)) yields (C D) CONS returns a new list that includes the first parameter as its first element and the second parameter as remainder of its result (CONS (A D) '(B C)) returns ((A D) B C) Scheme: Predicate Functions #T and () are true and false respectively EQ? returns #T if both parameters are atoms and are the same (EQ? 'A 'A) yields #T (EQ? 'A '(A B)) yields () Note that if EQ? is called with list parameters, the result is not reliable Also, EQ? does not work for numeric atoms LIST? returns #T if the parameter is a list; otherwise () NULL? returns #T if the parameter is an empty list; otherwise () Note that NULL? returns #T if the parameter is () Numeric Predicate Functions =, <>, >, <, >=, <=, EVEN?, ODD?, ZERO? 12
13 Form is based on? notation Lambda Expressions (LAMBDA (L) (CAR (CDR L))) L is called a bound variable Lambda expressions can be applied ((LAMBDA(L) (CAR (CDR L))) '((A B) C D)) Constructing Functions DEFINE  Two forms: To bind a symbol to an expression (DEFINE pi ) (DEFINE two_pi (* 2 pi)) To bind names to lambda expressions (DEFINE (cube x) (* x x x)) then you can use: (cube x) Evaluation Process Evaluation process (for normal functions): Parameters are evaluated, in no particular order The values of the parameters are substituted into the function body The function body is evaluated The value of the last expression in the body is the value of the function 13
14 Control Flow Selection the special form, IF (IF predicate then_exp else_exp) (IF (<> count 0) (/ sum count) 0 ) (DEFINE (factorial n) ( IF ( = n 0) 1 (* n (factorial( n 1) ) ) ) ) Control Flow Multiple Selection  the special form, COND (COND (predicate_1 expr {expr}) (predicate_1 expr {expr})... (predicate_1 expr {expr}) (ELSE expr {expr}) ) Returns the value of the last expr in the first pair whose predicate evaluates to true Example Scheme Function member takes an atom and a list; returns #T if atom is in list; () otherwise (DEFINE (member atm lis) )) (COND ((NULL? lis) '()) ((EQ? atm (CAR lis)) #T) ((ELSE (member atm (CDR lis))) 14
15 Example Scheme Function equalsimp returns #T if the two simple lists are equal; () otherwise (DEFINE (equalsimp lis1 lis2) (COND ((NULL? lis1) (NULL? lis2)) ((NULL? lis2) '()) ((EQ? (CAR lis1) (CAR lis2)) (equalsimp (CDR lis1) (CDR lis2))) (ELSE '()) )) equal Example Scheme Function returns #T if the two general lists are equal; () otherwise (DEFINE (equal lis1 lis2) (COND )) ((NOT (LIST? lis1)) (EQ? lis1 lis2)) ((NOT (LIST? lis2)) '()) ((NULL? lis1) (NULL? lis2)) ((NULL? lis2) '()) ((equal (CAR lis1) (CAR lis2)) (equal (CDR lis1) (CDR lis2))) (ELSE '()) Append Example Scheme Function takes two lists as parameters; returns the first parameter list with the elements of the second parameter list appended at the end (DEFINE (append lis1 lis2) )) (COND ((NULL? lis1) lis2) (ELSE (CONS (CAR lis1) (append (CDR lis1) lis2))) 15
16 Scheme Functional Forms Composition The previous examples have used it Apply to All one form in Scheme is mapcar Applies the given function to all elements of the given list; result is a list of the results (DEFINE mapcar fun lis) (COND ((NULL? lis) '()) (ELSE (CONS (fun (CAR lis)) (mapcar fun (CDR lis)))) )) EVAL Scheme interpreter itself is a function named EVAL The EVAL function can also be called directly by Scheme programs It is possible for Scheme to create expressions and calls EVAL to evaluate them Example: adding a list of numbers Cannot apply + directly on a list because + takes any number of numeric atoms as arguments ( ) is OK (+ ( )) is not EVAL One approach: ((DEFINE (adder lis) (COND ((NULL? lis) 0) (ELSE (+ (CAR lis) (adder (CDR lis)))) Another approach: ((DEFINE (adder lis) (COND ((NULL? lis) 0) (ELSE (EVAL (CONS '+ lis))) )) (adder (3 4 6)) causes adder to build the list ( ) The list is then submitted to EVAL, which invokes + and returns the result 13 16
17 Scheme: Output Functions Output Utility Functions: (DISPLAY expression) Example: (DISPLAY (car (A B C))) (NEWLINE) 17
Chapter 15. Functional Programming Languages
Chapter 15 Functional Programming Languages Copyright 2009 AddisonWesley. All rights reserved. 12 Chapter 15 Topics Introduction Mathematical Functions Fundamentals of Functional Programming Languages
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 informationChapter 15 Functional Programming Languages
Chapter 15 Functional Programming Languages Fundamentals of Functional Programming Languages Introduction to Scheme A programming paradigm treats computation as the evaluation of mathematical functions.
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 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 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 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 informationChapter 15. Functional Programming Languages ISBN
Chapter 15 Functional Programming Languages ISBN 0321493621 Chapter 15 Topics Introduction Mathematical Functions Fundamentals of Functional Programming Languages The First Functional Programming Language:
More informationChapter 15. Functional Programming Languages
Chapter 15 Functional Programming Languages Chapter 15 Topics Introduction Mathematical Functions Fundamentals of Functional Programming Languages The First Functional Programming Language: Lisp Introduction
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 information15. Functional Programming
15. Functional Programming 15.1 Introduction The design of the imperative languages is based directly on the von Neumann architecture Efficiency is the primary concern, rather than the suitability of the
More informationFunctional Programming. Pure Functional Languages
Functional Programming Pure functional PLs Sexpressions cons, car, cdr Defining functions readevalprint loop of Lisp interpreter Examples of recursive functions Shallow, deep Equality testing 1 Pure
More informationFunctional Programming. Pure Functional Languages
Functional Programming Pure functional PLs Sexpressions cons, car, cdr Defining functions readevalprint loop of Lisp interpreter Examples of recursive functions Shallow, deep Equality testing 1 Pure
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 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 informationExample Scheme Function: equal
ICOM 4036 Programming Languages Functional Programming Languages Mathematical Functions Fundamentals of Functional Programming Languages The First Functional Programming Language: LISP Introduction to
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 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 informationCSCE 314 TAMU Fall CSCE 314: Programming Languages Dr. Flemming Andersen. Haskell Basics
1 CSCE 314: Programming Languages Dr. Flemming Andersen Haskell Basics 2 Contents 1. Jump into Haskell: Using ghc and ghci (more detail) 2. Historical Background of Haskell 3. Lazy, Pure, and Functional
More informationIntroduction. chapter Functions
chapter 1 Introduction In this chapter we set the stage for the rest of the book. We start by reviewing the notion of a function, then introduce the concept of functional programming, summarise the main
More informationCSCE 314 Programming Languages
CSCE 314 Programming Languages Haskell 101 Dr. Hyunyoung Lee 1 Contents 1. Historical Background of Haskell 2. Lazy, Pure, and Functional Language 3. Using ghc and ghci 4. Functions 5. Haskell Scripts
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 informationLambda Calculus. Gunnar Gotshalks LC1
Lambda Calculus LC1 l Calculus History Developed by Alonzo Church during 1930 s40 s One fundamental goal was to describe what can be computed. Full definition of lcalculus is equivalent in power to
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 informationScheme Tutorial. Introduction. The Structure of Scheme Programs. Syntax
Scheme Tutorial Introduction Scheme is an imperative language with a functional core. The functional core is based on the lambda calculus. In this chapter only the functional core and some simple I/O is
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 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 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 informationConcepts of Programming Languages
Concepts of Programming Languages Lecture 15  Functional Programming Patrick Donnelly Montana State University Spring 2014 Patrick Donnelly (Montana State University) Concepts of Programming Languages
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 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. HernandezCampos, and D. Stotts. Brief
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 informationLambda Calculus LC1
Lambda Calculus LC1 λ Calculus History1 Developed by Alonzo Church during 1930 s40 s One fundamental goal was to describe what can be computed. Full definition of λcalculus is equivalent in power
More informationCSC 533: Programming Languages. Spring 2015
CSC 533: Programming Languages Spring 2015 Functional programming LISP & Scheme Sexpressions: atoms, lists functional expressions, evaluation, define primitive functions: arithmetic, predicate, symbolic,
More informationCSc 372. Comparative Programming Languages. 2 : Functional Programming. Department of Computer Science University of Arizona
1/37 CSc 372 Comparative Programming Languages 2 : Functional Programming Department of Computer Science University of Arizona collberg@gmail.com Copyright c 2013 Christian Collberg 2/37 Programming Paradigms
More informationCSC312 Principles of Programming Languages : Functional Programming Language. Copyright 2006 The McGrawHill Companies, Inc.
CSC312 Principles of Programming Languages : Functional Programming Language Overview of Functional Languages They emerged in the 1960 s with Lisp Functional programming mirrors mathematical functions:
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 subexpressions (if any).
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 informationFunctional Programming Languages (FPL)
Functional Programming Languages (FPL) 1. Definitions... 3 2. Applications... 3 3. Examples... 4 4. FPL Characteristics:... 5 5. Lambda calculus (LC)... 6 5.1. LC expressions forms... 6 5.2. Semantic of
More information11/6/17. Outline. FP Foundations, Scheme. Imperative Languages. Functional Programming. Mathematical Foundations. Mathematical Foundations
Outline FP Foundations, Scheme In Text: Chapter 15 Mathematical foundations Functional programming λcalculus LISP Scheme 2 Imperative Languages We have been discussing imperative languages C/C++, Java,
More informationUserdefined Functions. Conditional Expressions in Scheme
Userdefined Functions The list (lambda (args (body s to a function with (args as its argument list and (body as the function body. No quotes are needed for (args or (body. (lambda (x (+ x 1 s to the increment
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 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 informationModern Programming Languages. Lecture LISP Programming Language An Introduction
Modern Programming Languages Lecture 1821 LISP Programming Language An Introduction 72 Functional Programming Paradigm and LISP Functional programming is a style of programming that emphasizes the evaluation
More informationCS 314 Principles of Programming Languages
CS 314 Principles of Programming Languages Lecture 15: Review and Functional Programming Zheng (Eddy) Zhang Rutgers University March 19, 2018 Class Information Midterm exam forum open in Sakai. HW4 and
More informationProgramming Languages
Programming Languages Tevfik Koşar Lecture  XIII March 2 nd, 2006 1 Roadmap Functional Languages Lambda Calculus Intro to Scheme Basics Functions Bindings Equality Testing Searching 2 1 Functional Languages
More informationCSCC24 Functional Programming Scheme Part 2
CSCC24 Functional Programming Scheme Part 2 Carolyn MacLeod 1 winter 2012 1 Based on slides from Anya Tafliovich, and with many thanks to Gerald Penn and Prabhakar Ragde. 1 The Spirit of Lisplike Languages
More informationProgramming Languages
Programming Languages Lambda Calculus and Scheme CSCIGA.2110003 Fall 2011 λcalculus invented by Alonzo Church in 1932 as a model of computation basis for functional languages (e.g., Lisp, Scheme, ML,
More informationAn introduction to Scheme
An introduction to Scheme Introduction A powerful programming language is more than just a means for instructing a computer to perform tasks. The language also serves as a framework within which we organize
More informationIntroduction to Functional Programming in Racket. CS 550 Programming Languages Jeremy Johnson
Introduction to Functional Programming in Racket CS 550 Programming Languages Jeremy Johnson 1 Objective To introduce functional programming in racket Programs are functions and their semantics involve
More informationPrinciples of Programming Languages COMP251: Functional Programming in Scheme (and LISP)
Principles of Programming Languages COMP251: Functional Programming in Scheme (and LISP) Prof. Dekai Wu Department of Computer Science and Engineering The Hong Kong University of Science and Technology
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 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 informationDocumentation for LISP in BASIC
Documentation for LISP in BASIC The software and the documentation are both Copyright 2008 Arthur NunesHarwitt LISP in BASIC is a LISP interpreter for a Schemelike dialect of LISP, which happens to have
More informationFunctional Programming and λ Calculus. Amey Karkare Dept of CSE, IIT Kanpur
Functional Programming and λ Calculus Amey Karkare Dept of CSE, IIT Kanpur 0 Software Development Challenges Growing size and complexity of modern computer programs Complicated architectures Massively
More informationCOP4020 Programming Assignment 1  Spring 2011
COP4020 Programming Assignment 1  Spring 2011 In this programming assignment we design and implement a small imperative programming language MicroPL. To execute MircoPL code we translate the code to
More informationINF4820: 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 informationCS 415 Midterm Exam Spring 2002
CS 415 Midterm Exam Spring 2002 Name KEY Email Address Student ID # Pledge: This exam is closed note, closed book. Good Luck! Score Fortran Algol 60 Compilation Names, Bindings, Scope Functional Programming
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 informationPrinciples of Programming Languages Topic: Functional Programming Professor L. Thorne McCarty Spring 2003
Principles of Programming Languages Topic: Functional Programming Professor L. Thorne McCarty Spring 2003 CS 314, LS, LTM: Functional Programming 1 Scheme A program is an expression to be evaluated (in
More informationIntroduction to Scheme
How do you describe them Introduction to Scheme Gul Agha CS 421 Fall 2006 A language is described by specifying its syntax and semantics Syntax: The rules for writing programs. We will use Context Free
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 informationIt is better to have 100 functions operate one one data structure, than 10 functions on 10 data structures. A. Perlis
Chapter 14 Functional Programming Programming Languages 2nd edition Tucker and Noonan It is better to have 100 functions operate one one data structure, than 10 functions on 10 data structures. A. Perlis
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 information1.3. Conditional expressions To express case distinctions like
Introduction Much of the theory developed in the underlying course Logic II can be implemented in a proof assistant. In the present setting this is interesting, since we can then machine extract from a
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 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 firstclass values E.g., functions
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 informationIntroduction to Functional Programming in Haskell 1 / 56
Introduction to Functional Programming in Haskell 1 / 56 Outline Why learn functional programming? The essence of functional programming What is a function? Equational reasoning Firstorder vs. higherorder
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 informationChapter 1. Fundamentals of Higher Order Programming
Chapter 1 Fundamentals of Higher Order Programming 1 The Elements of Programming Any powerful language features: so does Scheme primitive data procedures combinations abstraction We will see that Scheme
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 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 informationProgramming Languages Third Edition
Programming Languages Third Edition Chapter 12 Formal Semantics Objectives Become familiar with a sample small language for the purpose of semantic specification Understand operational semantics Understand
More informationRecursive Functions of Symbolic Expressions and Their Application, Part I
Recursive Functions of Symbolic Expressions and Their Application, Part I JOHN MCCARTHY Review: Amit Kirschenbaum Seminar in Programming Languages Recursive Functions of Symbolic Expressions and Their
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 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 MIFLP Evropský sociální fond Praha & EU: Investujeme do vaší budoucnosti L I S P  Introduction L I S P
More informationCS 242. Fundamentals. Reading: See last slide
CS 242 Fundamentals Reading: See last slide Syntax and Semantics of Programs Syntax The symbols used to write a program Semantics The actions that occur when a program is executed Programming language
More informationScheme in Scheme: The Metacircular Evaluator Eval and Apply
Scheme in Scheme: The Metacircular Evaluator Eval and Apply CS21b: Structure and Interpretation of Computer Programs Brandeis University Spring Term, 2015 The metacircular evaluator is A rendition of Scheme,
More informationPrinciples of Programming Languages 2017W, Functional Programming
Principles of Programming Languages 2017W, Functional Programming Assignment 3: Lisp Machine (16 points) Lisp is a language based on the lambda calculus with strict execution semantics and dynamic typing.
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 11 Haskell track: lecture 1
CS 11 Haskell track: lecture 1 This week: Introduction/motivation/pep talk Basics of Haskell Prerequisite Knowledge of basic functional programming e.g. Scheme, Ocaml, Erlang CS 1, CS 4 "permission of
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 information1. true / false By a compiler we mean a program that translates to code that will run natively on some machine.
1. true / false By a compiler we mean a program that translates to code that will run natively on some machine. 2. true / false ML can be compiled. 3. true / false FORTRAN can reasonably be considered
More informationAn Introduction to Scheme
An Introduction to Scheme Stéphane Ducasse stephane.ducasse@inria.fr http://stephane.ducasse.free.fr/ Stéphane Ducasse 1 Scheme Minimal Statically scoped Functional Imperative Stack manipulation Specification
More informationCSc 520 Principles of Programming Languages
CSc 520 Principles of Programming Languages 9: Scheme Metacircular Interpretation Christian Collberg collberg@cs.arizona.edu Department of Computer Science University of Arizona Copyright c 2005 Christian
More informationLisp. Versions of LISP
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 is based on Common Lisp Scheme is one of the major
More informationIntroduction to ML. Mooly Sagiv. Cornell CS 3110 Data Structures and Functional Programming
Introduction to ML Mooly Sagiv Cornell CS 3110 Data Structures and Functional Programming Typed Lambda Calculus Chapter 9 Benjamin Pierce Types and Programming Languages Callbyvalue Operational Semantics
More informationScheme Quick Reference
Scheme Quick Reference COSC 18 Winter 2003 February 10, 2003 1 Introduction This document is a quick reference guide to common features of the Scheme language. It is by no means intended to be a complete
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 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 informationAnnouncements. The current topic: Scheme. Review: BST functions. Review: Representing trees in Scheme. Reminder: Lab 2 is due on Monday at 10:30 am.
The current topic: Scheme! Introduction! Objectoriented programming: Python Functional programming: Scheme! Introduction! Numeric operators, REPL, quotes, functions, conditionals! Function examples, helper
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 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 informationCIS24 Project #3. Student Name: Chun Chung Cheung Course Section: SA Date: 4/28/2003 Professor: Kopec. Subject: Functional Programming Language (ML)
CIS24 Project #3 Student Name: Chun Chung Cheung Course Section: SA Date: 4/28/2003 Professor: Kopec Subject: Functional Programming Language (ML) 1 Introduction ML Programming Language Functional programming
More informationRecursive Functions of Symbolic Expressions and Their Computation by Machine Part I
Recursive Functions of Symbolic Expressions and Their Computation by Machine Part I by John McCarthy IkSoon Kim Winter School 2005 Feb 18, 2005 Overview Interesting paper with By John Mitchell Interesting
More informationComputer Science 21b: Structure and Interpretation of Computer Programs (Spring Term, 2004)
Computer Science 21b: Structure and Interpretation of Computer Programs (Spring Term, 2004) There are only 5 ideas in Computer Science, and by the end of this course, you ll know 3 of them Harry Mairson
More information8/27/17. CS3304 Introduction. What will you learn? Semester Outline. Websites INTRODUCTION TO PROGRAMMING LANGUAGES
CS3304 Introduction In Text: Chapter 1 & 2 COURSE DESCRIPTION 2 What will you learn? Survey of programming paradigms, including representative languages Language definition and description methods Overview
More informationIntroduction to Typed Racket. The plan: Racket Crash Course Typed Racket and PL Racket Differences with the text Some PL Racket Examples
Introduction to Typed Racket The plan: Racket Crash Course Typed Racket and PL Racket Differences with the text Some PL Racket Examples Getting started Find a machine with DrRacket installed (e.g. the
More informationCS 61A Interpreters, Tail Calls, Macros, Streams, Iterators. Spring 2019 Guerrilla Section 5: April 20, Interpreters.
CS 61A Spring 2019 Guerrilla Section 5: April 20, 2019 1 Interpreters 1.1 Determine the number of calls to scheme eval and the number of calls to scheme apply for the following expressions. > (+ 1 2) 3
More information