Lambda Calculus and Functional Programming

Total Page:16

File Type:pdf, Size:1020Kb

Lambda Calculus and Functional Programming Plan • Introduce lambda calculus – Syntax Lambda Calculus – Substitution – Operational Semantics (… with contexts!) – Evaluation strategies – Equality • Relationship to programming languages (next time) • Study of types and type systems (later) #1 #2 Lambda Background Lambda Celebrity Representative • Developed in 1930’s by Alonzo Church • Subsequently studied by many people (still studied • Milton Friedman? today!) • Morgan Freeman? • Considered the “testbed” for procedural and functional languages • C. S. Friedman? – Simple – Powerful – Easy to extend with features of interest – Plays similar role for PL research as Turing machines do for computability and complexity – Somewhat like a crowbar … “Whatever the next 700 languages turn out to be, they will surely be variants of lambda calculus. ” (Landin ’66) #3 #4 Gordon Freeman Lambda Syntax • Best-selling PC FPS to date • The λ-calculus has three kinds of expressions (terms) e ::= x Variables | λx.e Functions (abstraction) | e1 e2 Application • λx.e is a one-argument function with body e • e1 e2 is a function application • Application associates to the left x y z means (x y) z • Abstraction extends to the right as far as possible λx.x λy.x y z means λx.(x (λy. ((x y) z))) #5 #6 1 Why Should I Care? • A language with 3 expressions? Woof! Examples of Lambda Expressions • Li and Zdancewick. Downgrading policies and relaxed noninterference . POPL ’05 • The identity function: – Just one example of a recent PL/security paper … I = def λx. x • A function that given an argument y discards it and yields the identity function: λy. ( λx. x) • A function that given a function f invokes it on the identity “There goes function our grant λf. f ( λx. x) money.” #7 #8 Scope of Variables Free and Bound Variables • As in all languages with variables it is • A variable is said to be free in E if it has important to discuss the notion of scope occurrences that are not bound in E – The scope of an identifier is the portion of a • We can define the free variables of an program where the identifier is accessible expression E recursively as follows: Free( x) = { x } • An abstraction λx. E binds variable x in E Free( E1 E2) = Free( E1) ∪ Free( E2) – x is the newly introduced variable Free( λx. E ) = Free( E) - { x } –E is the scope of x (unless x is shadowed …) • Example: Free( λx. x ( λy. x y z) ) = { z } – We say x is bound in λx. E • Free variables are (implicitly or explicitly) – Just like formal function arguments are bound in declared outside the term the function body #9 #10 Free Your Mind! Renaming Bound Variables • Just like in any language with statically nested • λ-terms that can be obtained from one another scoping we have to worry about variable shadowing by renaming of the bound variables are – An occurrence of a variable might refer to different considered identical. things in different contexts • This is called α-equivalence . • Renaming bound vars is called α-renaming . • e.g., IMP with locals: let x = E in x + (let x = E’ in x) + x • Example: λx. x is identical to λy. y and to λz. z • Intuition: – By changing the name of a formal argument and of all its occurrences in the function body, the behavior of • In λ-calculus: λx. x ( λx. x) x the function does not change – In λ-calculus such functions are considered identical #11 #12 2 Make It Easy On Yourself Substitution • Convention: we will always try to rename bound variables so that they are all unique • The substitution of E’ for x in E (written [E’/x]E ) – e.g., write λx. x ( λy.y) x instead of λx. x ( λx.x) x – Step 1. Rename bound variables in E and E’ so they are unique • This makes it easy to see the scope of – Step 2. Perform the textual substitution of E’ for x in E bindings and also prevents confusion! • Called capture-avoiding substitution . • Example: [y ( λx. x) / x] λy. ( λx. x) y x – After renaming: [y ( λv. v)/x] λz. ( λu. u) z x – After substitution: λz. ( λu. u) z (y ( λv. v)) • If we are not careful with scopes we might get: λy. ( λx. x) y (y ( λx. x)) #13 #14 The deBruijn Notation Combinators • An alternative syntax that avoids naming of bound • A λ-term without free variables is closed or a variables (and the subsequent confusions) combinator • The deBruijn index of a variable occurrence is the • Some interesting combinators: number of lambdas that separate the occurrence from its binding lambda in the abstract syntax tree I = λx. x • The deBruijn notation replaces names of K = λx. λy.x occurrences with their deBuijn index S = λf. λg. λx.f x (g x) • Examples: D = λx. x x – λx.x λ.0 Identical terms Y = λf.( λx. f (x x)) ( λx. f (x x)) – λx. λx.x λ.λ.0 have identical • Theorem: Any closed term is equivalent to one – λx. λy.y λ.λ.0 representations ! written with just S, K, I –(λ x. x x) ( λ z. z z) (λ.0 0) ( λ.0 0) – Example: D = β S I I – λx. ( λx. λy.x) x λ.( λ.λ.1) 0 – (we’ll discuss this form of equivalence in a bit) #15 #16 Informal Semantics Operational Semantics • We consider only closed terms • Many operational semantics for the λ-calculus • All are based on the equation • The evaluation of (λx. e) e’ =β [e’/x]e (λx. e) e’ usually read from left to right 1. Binds x to e’ • This is called the β-rule and the evaluation step a β-reduction 2. Evaluates e with the new binding • The subterm (λx. e) e’ is a β-redex 3. Yields the result of this evaluation • We write e →β e’ to say that e β-reduces to e’ in • Like a function call, or like “let x = e’ in e ” one step * • We write e →β e’ to say that e β-reduces to e’ in 0 • Example: or more steps (λf. f (f e)) g evaluates to g (g e) – Should remind you of small-step opsem term-rewriting #17 #18 3 Examples of Evaluation Evaluation and the Static Scope • The identity function: • The definition of substitution guarantees that (λx. x) E → [E / x] x = E evaluation respects static scoping: • Another example with the identity: (λ x. ( λy. y x)) ( y (λx. x)) →β λz. z ( y (λv. v)) (λf. f ( λx. x)) ( λx. x) → [λx. x / f] f ( λx. x)) = [( λx. x) / f] f ( λy. y)) = (λx. x) ( λy. y) → (y remains free, i.e., defined externally) [λy. y /x] x = λy. y • If we forget to rename the bound y: ∗ • A non-terminating evaluation: (λ x. ( λy. y x)) ( y (λx. x)) → β λy. y (y ( λv. v)) (λx. xx)( λy. yy) → [λy. yy / x]xx = (λy. yy)( λy. yy) → … • Try T T , where T = λx.x x x (y was free before but is bound now) #19 #20 Another View of Reduction Normal Forms • The application APP • A term without redexes is in normal form λx. • A reduction sequence stops at a normal form e e’ * x x x • If e is in normal form and e → β e’ then e is • becomes: identical to e’ e Terms can “grow” •K = λx. λy. x is in normal form substantially through e’ e’ e’ β-reduction ! • K I is not in normal form #21 #22 Nondeterministic Evaluation Lambda Calculus Contexts • We define a small-step reduction relation • Define contexts with one hole (λx. e) e’ → [e’/x]e H ::= • | λx. H | H e | e H • Write H[e] to denote the filling of the hole in e → e ’ e → e ’ 1 1 2 2 H with the expression e → e1 e2 → e1’ e2 e1 e2 e1 e2’ e → e’ • Example: λx. e → λx. e’ H = λx. x • H[ λy.y] = λx. x ( λy. y) • Filling the hole allows variable capture! • This is a non-deterministic semantics H = λx. x • H[x] = λx.x x • Note that we evaluate under λ (where?) #23 #24 4 Contextual Opsem The Order of Evaluation e → e’ • In a λ-term there could be more than one (λx. e) e’ → [e’/x]e H[e] → H[e’] instance of (λx. E) E’, as in: • Contexts allow concise formulations of congruence (λy. (λx. x) y ) E rules (application of local reduction rules on subterms) – could reduce the inner or the outer λ • Reduction occurs at a β-redex that can be – which one should we pick? anywhere inside the expression (λy. ( λx. x) y) E • The latter rule is called a congruence or structural inner outer rule (λy. [y/x] x) E = ( λy. y) E [E/y] ( λx. x) y =( λx. x) E • The above rules do not specify which redex must be reduced first E #25 #26 The Diamond Property The Diamond Property • A relation R has the diamond property if whenever • Languages defined by non-deterministic sets e R e 1 and e R e 2 then there exists e’ such that e1 R of rules are common e’ and e2 R e’ e – Logic programming languages R R – Expert systems – Constraint satisfaction systems e1 e2 • and thus most pointer analyses … R R e’ – Dataflow systems – Makefiles • →β does not have the diamond property • → * has the diamond property • It is useful to know whether such systems β have the diamond property • Also called the confluence property #27 #28 (Beta) Equality The Church-Rosser Theorem → * • Let = be the reflexive, transitive and • If e1 =β e2 then there exists e’ such that e1 β e’ β and e → * e’ 2 β • symmetric closure of →β • * =β is (→β ∪ ←β) • e1 e2 • That is, e1 =β e2 if e1 converts to e2 via a sequence of forward and backward →β •• • • e’ e • e2 • Proof (informal): apply the diamond property as 1 many times as necessary #29 #30 5 Corollaries Evaluation Strategies • If e1 =β e2 and e1 and e2 are normal forms • Church-Rosser theorem says that independent of the reduction strategy we will find 1 normal form then e1 is identical to e2 * * • But some reduction strategies might find 0 – From C-R we have ∃e’.
Recommended publications
  • Functional Javascript
    www.it-ebooks.info www.it-ebooks.info Functional JavaScript Michael Fogus www.it-ebooks.info Functional JavaScript by Michael Fogus Copyright © 2013 Michael Fogus. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://my.safaribooksonline.com). For more information, contact our corporate/ institutional sales department: 800-998-9938 or [email protected]. Editor: Mary Treseler Indexer: Judith McConville Production Editor: Melanie Yarbrough Cover Designer: Karen Montgomery Copyeditor: Jasmine Kwityn Interior Designer: David Futato Proofreader: Jilly Gagnon Illustrator: Robert Romano May 2013: First Edition Revision History for the First Edition: 2013-05-24: First release See http://oreilly.com/catalog/errata.csp?isbn=9781449360726 for release details. Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly Media, Inc. Functional JavaScript, the image of an eider duck, and related trade dress are trademarks of O’Reilly Media, Inc. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and O’Reilly Media, Inc., was aware of a trade‐ mark claim, the designations have been printed in caps or initial caps. While every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein.
    [Show full text]
  • The Grace Programming Language Draft Specification Version 0.3.1261" (2013)
    Portland State University PDXScholar Computer Science Faculty Publications and Presentations Computer Science 2013 The Grace Programming Language Draft Specification ersionV 0.3.1261 Andrew P. Black Portland State University, [email protected] Kim B. Bruce James Noble Follow this and additional works at: https://pdxscholar.library.pdx.edu/compsci_fac Part of the Programming Languages and Compilers Commons Let us know how access to this document benefits ou.y Citation Details Black, Andrew P.; Bruce, Kim B.; and Noble, James, "The Grace Programming Language Draft Specification Version 0.3.1261" (2013). Computer Science Faculty Publications and Presentations. 111. https://pdxscholar.library.pdx.edu/compsci_fac/111 This Post-Print is brought to you for free and open access. It has been accepted for inclusion in Computer Science Faculty Publications and Presentations by an authorized administrator of PDXScholar. Please contact us if we can make this document more accessible: [email protected]. The Grace Programming Language Draft Specification Version 0.3.1261 Andrew P. Black Kim B. Bruce James Noble August 14, 2013 1 Introduction This is a specification of the Grace Programming Language. This specifica- tion is notably incomplete, and everything is subject to change. In particular, this version does not address: • the library, especially collection syntax and collection literals • nested static type system (although we’ve made a start) • module system James Ishould write up from DYLA paperJ • metadata (Java’s @annotations, C] attributes, final, abstract etc) James Ishould add this tooJ Kim INeed to add syntax, but not necessarily details of which attributes are in language (yet)J • immutable data and pure methods.
    [Show full text]
  • An Interpreter for a Novice-Oriented Programming Language With
    An Interpreter for a Novice-Oriented Programming Language with Runtime Macros by Jeremy Daniel Kaplan Submitted to the Department of Electrical Engineering and Computer Science in partial fulfillment of the requirements for the degree of Master of Engineering in Electrical Engineering and Computer Science at the MASSACHUSETTS INSTITUTE OF TECHNOLOGY June 2017 ○c Jeremy Daniel Kaplan, MMXVII. All rights reserved. The author hereby grants to MIT permission to reproduce and to distribute publicly paper and electronic copies of this thesis document in whole or in part in any medium now known or hereafter created. Author................................................................ Department of Electrical Engineering and Computer Science May 12, 2017 Certified by. Adam Hartz Lecturer Thesis Supervisor Accepted by . Christopher Terman Chairman, Masters of Engineering Thesis Committee 2 An Interpreter for a Novice-Oriented Programming Language with Runtime Macros by Jeremy Daniel Kaplan Submitted to the Department of Electrical Engineering and Computer Science on May 12, 2017, in partial fulfillment of the requirements for the degree of Master of Engineering in Electrical Engineering and Computer Science Abstract In this thesis, we present the design and implementation of a new novice-oriented programming language with automatically hygienic runtime macros, as well as an interpreter framework for creating such languages. The language is intended to be used as a pedagogical tool for introducing basic programming concepts to introductory programming students. We designed it to have a simple notional machine and to be similar to other modern languages in order to ease a student’s transition into other programming languages. Thesis Supervisor: Adam Hartz Title: Lecturer 3 4 Acknowledgements I would like to thank every student and staff member of MIT’s 6.01 that I have worked with in the years I was involved in it.
    [Show full text]
  • Haskell-Like S-Expression-Based Language Designed for an IDE
    Department of Computing Imperial College London MEng Individual Project Haskell-Like S-Expression-Based Language Designed for an IDE Author: Supervisor: Michal Srb Prof. Susan Eisenbach June 2015 Abstract The state of the programmers’ toolbox is abysmal. Although substantial effort is put into the development of powerful integrated development environments (IDEs), their features often lack capabilities desired by programmers and target primarily classical object oriented languages. This report documents the results of designing a modern programming language with its IDE in mind. We introduce a new statically typed functional language with strong metaprogramming capabilities, targeting JavaScript, the most popular runtime of today; and its accompanying browser-based IDE. We demonstrate the advantages resulting from designing both the language and its IDE at the same time and evaluate the resulting environment by employing it to solve a variety of nontrivial programming tasks. Our results demonstrate that programmers can greatly benefit from the combined application of modern approaches to programming tools. I would like to express my sincere gratitude to Susan, Sophia and Tristan for their invaluable feedback on this project, my family, my parents Michal and Jana and my grandmothers Hana and Jaroslava for supporting me throughout my studies, and to all my friends, especially to Harry whom I met at the interview day and seem to not be able to get rid of ever since. ii Contents Abstract i Contents iii 1 Introduction 1 1.1 Objectives ........................................ 2 1.2 Challenges ........................................ 3 1.3 Contributions ...................................... 4 2 State of the Art 6 2.1 Languages ........................................ 6 2.1.1 Haskell ....................................
    [Show full text]
  • The Grace Programming Language Draft Specification Version 0.5. 2025" (2015)
    Portland State University PDXScholar Computer Science Faculty Publications and Presentations Computer Science 2015 The Grace Programming Language Draft Specification ersionV 0.5. 2025 Andrew P. Black Portland State University, [email protected] Kim B. Bruce James Noble Follow this and additional works at: https://pdxscholar.library.pdx.edu/compsci_fac Part of the Programming Languages and Compilers Commons Let us know how access to this document benefits ou.y Citation Details Black, Andrew P.; Bruce, Kim B.; and Noble, James, "The Grace Programming Language Draft Specification Version 0.5. 2025" (2015). Computer Science Faculty Publications and Presentations. 140. https://pdxscholar.library.pdx.edu/compsci_fac/140 This Working Paper is brought to you for free and open access. It has been accepted for inclusion in Computer Science Faculty Publications and Presentations by an authorized administrator of PDXScholar. Please contact us if we can make this document more accessible: [email protected]. The Grace Programming Language Draft Specification Version 0.5.2025 Andrew P. Black Kim B. Bruce James Noble April 2, 2015 1 Introduction This is a specification of the Grace Programming Language. This specifica- tion is notably incomplete, and everything is subject to change. In particular, this version does not address: • James IWE MUST COMMIT TO CLASS SYNTAX!J • the library, especially collections and collection literals • static type system (although we’ve made a start) • module system James Ishould write up from DYLA paperJ • dialects • the abstract top-level method, as a marker for abstract methods, • identifier resolution rule. • metadata (Java’s @annotations, C] attributes, final, abstract etc) James Ishould add this tooJ Kim INeed to add syntax, but not necessarily details of which attributes are in language (yet)J • immutable data and pure methods.
    [Show full text]
  • The React Handbook Follows the 80/20 Rule: Learn in 20% of the Time the 80% of a Topic
    Table of Contents Introduction Overview Introduction to React How to install React Modern JavaScript core concepts you need to know to use React How much JS you need to use React Variables Arrow functions Work with objects and arrays using Rest and Spread Object and array destructuring Template literals Classes Callbacks Promises Async/Await ES Modules React Concepts Single Page Apps Declarative Immutability Purity Composition The Virtual DOM Unidirectional Data Flow In-depth JSX Components State Props Presentational vs container components 2 State vs Props PropTypes Fragment Events Lifecycle events Handling forms Reference a DOM element Server side rendering Context API Higher-order components Render Props Hooks Code splitting Styling CSS in React SASS with React Styled Components Tooling Babel Webpack Prettier Testing Introduction to Jest Testing React Components A look at the React Ecosystem React Router Redux Next.js Gatsby Wrapping up 3 4 Introduction Introduction The React Handbook follows the 80/20 rule: learn in 20% of the time the 80% of a topic. I find this approach gives a well-rounded overview. This book does not try to cover everything under the sun related to React. If you think some specific topic should be included, tell me. In this book I make use of React hooks, so you need to set the required versions of React and ReactDOM to use 16.7.0-alpha.2 (if when you're reading this Hooks are released officially, you don't need to do this). You can do so in CodeSandbox by clicking "Add Dependency" and searching react and choosing 16.7.0-alpha.2 from the select, and repeat this for react- dom .
    [Show full text]
  • Python En Toc.Pdf
    Revision September 12, 2013 About this Textbook This textbook is provided as a courtesy to NCLab users. Python is a modern high-level dynamic programming language that is used in many areas of business, engineering, and science today. After taking this course, you will have solid theoretical knowledge and vast practical experience with computer programming in Python. Acknowledgments The author Dr. Pavel Solin would like to thank the following people for their valuable suggestions and help: – Martin Novak, Czech Technical University, Prague, Czech Republic. – Joel Landsteiner, Cray Inc, USA. – William Mitchell, NIST, USA. – Venkata Rama Rao Mallela, Hyderabad, India. – Steven Lamb, Philadelphia, USA. – Norman Dunbar, Leeds, West Yorkshire, England. – Samuel Marks, Sydney, Australia. Graphics Design: TR-Design http://tr-design.cz Table of Contents I Textbook 1 Introduction . .5 1.1 Objectives . .5 1.2 Compiled and interpreted programming languages . .5 1.3 Basic facts about Python . .5 1.4 Python programming in NCLab . .6 1.5 Downloading Python programs from NCLab’s database . .6 1.6 Launching the Python module . .6 1.7 Code, output, and descriptive cells . .7 2 Using Python as a Calculator . .8 2.1 Objectives . .8 2.2 Addition and subtraction . .8 2.3 Multiplication . .9 2.4 Division . .9 2.5 Modulo . 11 2.6 Powers . 11 2.7 Priority of operators . 12 2.8 Using empty characters makes your code more readable . 13 2.9 Using mathematical functions . 13 2.10 Fractions . 14 2.11 Random numbers . 15 2.12 Complex numbers . 16 3 Functions . 17 3.1 Objectives . 17 3.2 Defining new functions .
    [Show full text]
  • Learn Functional Programming with Elixir New Foundations for a New World
    Early praise for Functional Programming with Elixir Learning to program in a functional style requires one to think differently. When learning a new way of thinking, you cannot rush it. I invite you to read the book slowly and digest the material thoroughly. The essence of functional programming is clearly laid out in this book and Elixir is a good language to use for exploring this style of programming. ➤ Kim Shrier Independent Software Developer, Shrier and Deihl Some years ago it became apparent to me that functional and concurrent program- ming is the standard that discriminates talented programmers from everyone else. Elixir’s a modern functional language with the characteristic aptitude for crafting concurrent code. This is a great resource on Elixir with substantial exercises and encourages the adoption of the functional mindset. ➤ Nigel Lowry Company Director and Principal Consultant, Lemmata This is a great book for developers looking to join the world of functional program- ming. The author has done a great job at teaching both the functional paradigm and the Elixir programming language in a fun and engaging way. ➤ Carlos Souza Software Developer, Pluralsight This book covers the functional approach in Elixir very well. It is great for beginners and gives a good foundation to get started with advanced topics like OTP, Phoenix, and metaprogramming. ➤ Gábor László Hajba Senior Consultant, EBCONT enterprise technologies Hands down the best book to learn the basics of Elixir. It’s compact, easy to read, and easy to understand. The author provides excellent code examples and a great structure. ➤ Stefan Wintermeyer Founder, Wintermeyer Consulting Learn Functional Programming with Elixir New Foundations for a New World Ulisses Almeida The Pragmatic Bookshelf Raleigh, North Carolina Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks.
    [Show full text]
  • Course Notes
    David Liu Principles of Programming Languages Lecture Notes for CSC324 Department of Computer Science University of Toronto Contents Prelude: The Lambda Calculus It was in the 1930s, years before the invention of the first electronic computing devices, that a young mathematician named Alan Turing Alan Turing, 1912-1954 created modern computer science as we know it. Incredibly, this came about almost by accident; he had been trying to solve a problem from The Entscheidungsproblem (“decision mathematical logic! To answer this question, Turing developed an ab- problem”) asked whether an algorithm could decide if a logical statement is stract model of mechanical, procedural computation: a machine that provable from a given set of axioms. could read in a string of 0’s and 1’s, a finite state control that could Turing showed no such algorithm exists. make decisions and write 0’s and 1’s to its internal memory, and Finite state controls are analogous to an output space where the computation’s result would be displayed. the deterministic finite automata that you Though its original incarnation was an abstract mathematical object, learned about in CSC236. the fundamental mechanism of the Turing machine – reading data, executing a sequence of instructions to modify internal memory, and producing output – would soon become the von Neumann architec- ture lying at the heart of modern computers. It is no exaggeration that the fundamentals of computer science owe their genesis to this man. The story of Alan Turing and his machine is one of great genius, great triumph, and great sadness. Their legacy is felt by every computer scientist, software engineer, and computer engineer alive today.
    [Show full text]
  • Introduction to Python Programming
    Introduction to Python Programming Introduction to Python Programming Pavel Solin Revision October 6, 2014 About the Author Dr. Pavel Solin is Professor of Applied and Computational Mathematics at the Uni- versity of Nevada, Reno. He is an expert in scientific computing, leader of major open source projects, and the author of six monographs and many research articles in inter- national journals. Acknowledgment We would like to thank great teachers from NCLab Partner Schools for class-testing the Python module, and for providing useful feedback that is helping us to improve the textbook, interactive projects, and the Python module itself. Graphics Design: TR-Design http://tr-design.cz Copyright: Copyright FEMhub Inc. All Rights Reserved. Preface This course provides a gentle and efficient introduction to Python – a modern high- level dynamic programming language that is widely used in business, science, and en- gineering applications. If this is your first time learning a programming language, then we recommend that you start with the NCLab course “Earn Black Belt in Computer Programming” with Karel the Robot. Karel is fun, and it helps you develop algorithmic thinking which is an absolutely critical skill in computer programming. By algorithmic thinking we mean an ability to translate ideas into sequences of steps that are compatible with the way a machine operates. Once you develop good algorithmic thinking, your efficiency in learning any new programming language will improve dramatically. In this course you will learn many concepts including mathematical operations and functions, 2D and 3D plotting, local and global variables, strings, tuples, lists, dictio- naries, exceptions, object-oriented programming, and more.
    [Show full text]
  • Slides – Evaluation Strategies – Encodings
    Announcements Lambda Calculus • HW5 grades posted tonight Meeting 24, CSCI 5535, Spring 2010 2 Program Analysis in a Nutshell? Define an Abstraction Lambda Calculus Compute a Fixed Point in the Abstraction 3 Lambda Calculus Lambda Background • Developed in 1930’s by Alonzo Church • Subsequently studied by many people Goal : Come up with a “core” language that’s as – Still studied today! small as possible and still Turing • Considered the “testbed” for procedural and functional languages complete – Simple – Powerful This will give a way of illustrating important – Easy to extend with new features of interest language features and algorithms – “Lambda:PL :: Turing Machine:Complexity” “Whatever the next 700 languages turn out to be, they will surely be variants of lambda calculus.” (Landin ’66) 5 6 1 Lambda Syntax Why Should I Care? • The λ-calculus has 3 kinds of expressions (terms) • A language with 3 expressions? Woof! e ::= x Variables • Li and Zdancewic. Downgrading policies and relaxed noninterference . POPL ’05 λ | x. e Functions ( abstractions ) – Just one example of a recent PL/security paper | e1 e2 Application • λx. e is a one-argument anonymous function with body e • e1 e2 is a function application • Application associates to the left x y z === (x y) z • Abstraction extends as far to the right as possible λ λ λ λ x. x y. x y z === x. (x [ y. {(x y) z}]) 7 8 Examples of Lambda Expressions Examples of Lambda Expressions • The identity function: • The identity function: I = def λx. x I = def λx. x • A function that, given an argument y, • A function that, given an argument y, discards it and yields the identity discards it and yields the identity function: function: λy.
    [Show full text]
  • Declare Global String Variable Python
    Declare Global String Variable Python Abraham wearies his rosters change-over cubically or succinctly after Yves hydrogenize and ebonizing bonnily, boulevard?expiring and Ablated well-connected. and breathiest How calcific Worden is bureaucratizeSlade when civic some and applet hydrophanous so zestfully! Steve editorializes some Declaring the following is it is implicitly global string variable Based solution eliminates all variables can make things that a certain cookies may embed an app using global variable or not be accessible across files. So real question is, programming and solving everyday problems. Is thermal true that improve order of initialization of global variables is undefined, we must explicitly tell Python that we are close that precision will discuss lost. Please stand out when attempting to cover global scope this makes it inherits methods that can be shown below code text in business administration and it should be. Just import the configuration module in all modules of your application; the module then becomes available capital a global name. Net PHP C C Python JSP Spring Bootstrap jQuery Interview. Python Language Global Variables python Tutorial. In the bellow batch script I am creating a variable Blog and storing a string Aticleworld. In order to subtitle a local variable, the variable cannot be defined in the nested scope. How do i edge detect unauthorized access names of string? In Python 3 only use global variables at their highest conveniences Since a larger program can inherit global variables from each py file. Please check if we are declaring a subclass of space before getting started i develop as independent are entirely independent of arbitrarily complex.
    [Show full text]