DOC PREVIEW
UT Dallas CS 4337 - #Sebesta pl10e ch15 functional prog

This preview shows page 1-2-3-4-5-33-34-35-36-67-68-69-70-71 out of 71 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 71 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 71 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 71 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 71 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 71 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 71 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 71 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 71 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 71 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 71 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 71 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 71 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 71 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 71 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 71 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Chapter 15Chapter 15 TopicsIntroductionMathematical FunctionsLambda ExpressionsFunctional FormsFunction CompositionApply-to-allFundamentals of Functional Programming LanguagesLISP Data Types and StructuresLISP InterpretationOrigins of SchemeThe Scheme InterpreterPrimitive Function EvaluationPrimitive Functions & LAMBDA ExpressionsSpecial Form Function: DEFINEOutput FunctionsNumeric Predicate FunctionsControl FlowList FunctionsList Functions (continued)Slide 22Predicate Function: EQ?Predicate Function: EQV?Predicate Functions: LIST? and NULL?Example Scheme Function: memberExample Scheme Function: equalsimpExample Scheme Function: equalExample Scheme Function: appendExample Scheme Function: LETLET ExampleTail Recursion in SchemeTail Recursion in Scheme - continuedFunctional Form - CompositionFunctional Form – Apply-to-AllFunctions That Build CodeAdding a List of NumbersCommon LISPCommon LISP (continued)Slide 40Slide 41Slide 42MLML SpecificsML Specifics (continued)Slide 46Slide 47Slide 48Slide 49Slide 50Slide 51Slide 52HaskellFunction Definitions with Different Parameter RangesHaskell ListsHaskell (continued)QuicksortLazy EvaluationMember RevisitedF#F# (continued)Slide 62Slide 63Slide 64Slide 65Slide 66Support for Functional Programming in Primarily Imperative LanguagesSupport for Functional Programming in Primarily Imperative Languages (continued)Slide 69Comparing Functional and Imperative LanguagesSummaryChapter 15Functional Programming LanguagesCopyright © 2012 Addison-Wesley. All rights reserved. 1-2Chapter 15 Topics•Introduction•Mathematical Functions•Fundamentals of Functional Programming Languages •The First Functional Programming Language: LISP•Introduction to Scheme•Common LISP•ML•Haskell•F#•Support for Functional Programming in Primarily Imperative Languages•Comparison of Functional and Imperative LanguagesCopyright © 2012 Addison-Wesley. All rights reserved. 1-3Introduction•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 language for software development•The design of the functional languages is based on mathematical functions–A solid theoretical basis that is also closer to the user, but relatively unconcerned with the architecture of the machines on which programs will runCopyright © 2012 Addison-Wesley. All rights reserved. 1-4Mathematical Functions•A mathematical function is a mapping of members of one set, called the domain set, to another set, called the range set•A lambda expression specifies the parameter(s) and the mapping of a function in the following form(x) x * x * x for the function cube(x) = x * x * xCopyright © 2012 Addison-Wesley. All rights reserved. 1-5Lambda Expressions•Lambda expressions describe nameless functions•Lambda expressions are applied to parameter(s) by placing the parameter(s) after the expressione.g., ((x) x * x * x)(2)which evaluates to 8Copyright © 2012 Addison-Wesley. All rights reserved. 1-6Functional Forms•A higher-order function, or functional form, is one that either takes functions as parameters or yields a function as its result, or bothCopyright © 2012 Addison-Wesley. All rights reserved. 1-7Function Composition•A functional form that takes two functions as parameters and yields a function whose value is the first actual parameter function applied to the application of the secondForm: h  f ° gwhich means h (x)  f ( g ( x))For f (x)  x + 2 and g (x)  3 * x,h  f ° g yields (3 * x)+ 2Copyright © 2012 Addison-Wesley. All rights reserved. 1-8Apply-to-all•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 parametersForm: For h(x)  x * x(h, (2, 3, 4)) yields (4, 9, 16)Copyright © 2012 Addison-Wesley. All rights reserved. 1-9Fundamentals of Functional Programming Languages•The objective of the design of a FPL is to mimic mathematical functions to the greatest extent possible•The basic process of computation is fundamentally different in a FPL than in an imperative language–In an imperative language, operations are done and the results are stored in variables for later use–Management of variables is a constant concern and source of complexity for imperative programming•In an FPL, variables are not necessary, as is the case in mathematics•Referential Transparency - In an FPL, the evaluation of a function always produces the same result given the same parametersCopyright © 2012 Addison-Wesley. All rights reserved. 1-10LISP Data Types and Structures•Data object types: originally only atoms and lists•List form: parenthesized collections of sublists and/or atomse.g., (A B (C D) E)•Originally, LISP was a typeless language•LISP lists are stored internally as single-linked listsCopyright © 2012 Addison-Wesley. All rights reserved. 1-11LISP Interpretation•Lambda notation is used to specify functions and function definitions. Function applications and data have the same form.e.g., If the list (A B C) is interpreted as data it isa simple list of three atoms, A, B, and CIf it is interpreted as a function application,it means that the function named A isapplied to the two parameters, B and C•The first LISP interpreter appeared only as a demonstration of the universality of the computational capabilities of the notationCopyright © 2012 Addison-Wesley. All rights reserved. 1-12Origins of Scheme•A mid-1970s dialect of LISP, designed to be a cleaner, more modern, and simpler version than the contemporary dialects of LISP•Uses only static scoping•Functions are first-class entities–They can be the values of expressions and elements of lists–They can be assigned to variables, passed as parameters, and returned from functionsThe Scheme Interpreter•In interactive mode, the Scheme interpreter is an infinite read-evaluate-print loop (REPL)–This form of interpreter is also used by Python and Ruby•Expressions are interpreted by the function EVAL•Literals evaluate to themselvesCopyright © 2012 Addison-Wesley. All rights reserved. 1-13Copyright © 2012 Addison-Wesley. All rights reserved. 1-14Primitive Function Evaluation•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


View Full Document

UT Dallas CS 4337 - #Sebesta pl10e ch15 functional prog

Download #Sebesta pl10e ch15 functional prog
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view #Sebesta pl10e ch15 functional prog and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view #Sebesta pl10e ch15 functional prog 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?