CS 296 — Getting Started in Clojure Version 0.6 Mattox Beckman

Total Page:16

File Type:pdf, Size:1020Kb

CS 296 — Getting Started in Clojure Version 0.6 Mattox Beckman CS 296 — Getting Started in Clojure Version 0.6 Mattox Beckman Contents 1 About Clojure 2 1.1 Purpose . 2 1.2 History of Clojure ........................................ 2 1.3 Getting Clojure ......................................... 2 1.4 Typographic Conventions . 3 2 Numerics, Arithmetic, and Function Calls 3 2.1 Function Calls . 3 2.2 Mathematics . 4 2.3 Exercises . 4 3 Creating and Using Variables 4 3.1 Define . 4 3.2 Let.................................................. 4 3.3 Exercises . 4 4 Built-in Data Structures 4 4.1 Sequences . 4 4.2 Lists . 5 4.3 Vectors . 6 4.4 Hash Maps . 6 5 Creating Functions 8 5.1 Lambda . 8 5.2 Another Shortcut . 8 5.3 Defn . 9 6 Conditionals 9 6.1 What is truth? . 9 6.2 cond . 9 7 Records 10 8 Mutation 10 9 Looping 10 9.1 You don’t need to do it. 10 9.2 But I really want to use a loop! . 11 9.3 List Comprehensions . 11 10 Namespaces 12 11 Solutions to exercises 12 12 Colophon1 13 1 About Clojure In the mid 1990’s, Matthias Felleisen founded PLT, a group of researchers interested in Scheme. 1.1 Purpose They produced their own dialect of Scheme called, appropriately enough, PLT Scheme. In 2010, they The purpose of this document is to help a program- renamed PLT Scheme version 5.0 to Racket. mer get up to speed using Clojure. It is not meant Lisp was very influential for a long time, until the to be comprehensive, but to serve as a starting point dreaded AI Winter. Researchers began to doubt the so that other reference materials will make more ability of symbolic logic to mimic human intelligence, sense. and AI (Artificial Intelligence) became less popular. I assume that the reader has programmed before, Because Lisp was considered an “AI language,” it and thus will be familiar with variables, function also became less popular. calls, loops, and the like. I do not assume that the In spite of this, people continued to work with reader’s experience is extensive. Lisp, writing production code and creating new di- This document is organized by sections. Each sec- alects. We will ignore them all except for the one tion will introduce an aspect of Clojure. Included that concerns us now. In 2009, Rich Hickey released will be discussion, sample code, and some exercises. Clojure publicly. Because it could run on the There are many code examples. You should read JVM and have access to all of Java’s libraries, it this with a running Clojure environment so you generated a lot of excitement, and is quickly finding can type them in and play with them yourself. This its way into industry. is the fastest way to learn. When you are finished with these sections you 1.3 Getting Clojure should be ready to start programming! The very short version is “get Leinengen”. Leinen- 1.2 History of Clojure gen, or lein as the command is called, is a Clo- jure build tool. It can run Clojure programs, Clojure is a dialect of Lisp. Lisp is best under- but it can also manage Clojure packages very eas- stood as a family of languages. This language family ily. We will be using this extensively in the course. is ancient, one of the oldest languages still in use to- It can be found at http://leiningen.org. day. The fact that it is still in use is a testimony to You will definitely want a Clojure-aware editor. its expressive power and its ability to be modified to If you want to get started quickly, the IDE called the will of the programmer. Today there are many LightTable is very promising. It’s a simple .jar dialects of Lisp in use, some quite new. These in- file, and runs almost everywhere. It can use the vim clude Common Lisp, Scheme, Racket, Guile, keybindings, for those of you who know what those and of course, Clojure. are. This is one of our recommended environments. In 1958, John McCarthy created the Lisp pro- Visit http://www.lighttable.com to try it. gramming language at MIT. It was meant to be a The eclipse package has a plugin called theoretical exercise, but then one of his graduate stu- CounterClockwise that supports Clojure, and I dents converted it to assembly language, and thus am told that it is good. You can find it at the first Lisp interpreter came into being. http://code.google.com/p/counterclockwise. In 1962, the first Lisp compiler was written in There are two editors also worth mentioning. The Lisp. A language is usually considered a “toy” lan- learning curve on them is much higher, but the ben- guage until it can compile itself. efit is also greater once you are familiar with them. In the early 1970’s, Sussman and Steele developed The course web site has some resources for both of Scheme to study a programming concept called the these. actor.1 In 1975, the first paper on Scheme was The first is an ancient editor called vim. It is a published. modal editor, with keybindings optimized for touch- typists. You can edit very quickly with vim. You 1Actors are entities that have their own threads and states, and can communicate with other actors. They are an early will want to get some plugins to vim to work with attempt to understand distributed computing, and are still in Clojure: the details can be found on the course use today. web site. 2 The second is another ancient editor called emacs. (plus 10 20) ; => 30 The author of this guide started learning it 25 years ago (and it was already considered old then), though or on the following line, like this: still in constant development. It is likely the most common environment for Clojure programmers. (plus 10 20) For a best-of-all-worlds approach, someone has ;; => 30 even written a vim emulator in emacs. It is called evil, and the reader can decide if that is just a co- incidence or not. The spacemacs project has put a 2 Numerics, Arithmetic, and Function lot of effort into unifying the two editors. Calls 1.4 Typographic Conventions Clojure contains many numeric types. The usual The examples in this manual will be of two types: ones are there, such as integers and floats. They look files and interactive environments. A file listing will like you would expect. Note that the semicolon is look like this: the comment character in Clojure. (defn plus [a b] 10 ; Long Integers (+ a b)) 234.345 ; Floats Running the program from the interactive envi- It also has big integers. These allow as many digits ronment will look like this. as you have memory to store them. % lein repl 918741238974019237401239487 ; Bignums nREPL server started on port 43244 REPL-y 0.2.0 Clojure has fractions, though we propbably will Clojure~1.5.1 not use them much. You can convert them to floats Docs: (doc function-name-here) if you want. (find-doc "part-of-name-here") Source: (source function-name-here) 50/15 ; => 10/3 (float 50/15) ; => 3.3333333333333335 user=> (load-file "foo.clj") #'user/plus user=> (plus 10 20) 2.1 Function Calls 30 In Clojure, every computation begins with a parenthesis. This is the most noticeable feature of The % lein repl is the Unix prompt and com- the language, and perhaps the most important. In mand to start Clojure, and the user=> symbol is non-lisps, a function call might look like f(x,y). In the Clojure prompt. Your own prompts may look Clojure, it looks like different depending on how your environment is set up. f Most of the examples in this document will be run ( x y) from the Unix command line, but you could also use one of the editors we mentioned to take advantage So, to add two numbers 10 and 20, you would write of the graphic user interface. In order to reduce the amount of space it takes to (+ 10 20) demonstrate Clojure code, many documentation writers use the convention of writing an expression To add 3 × 3 to 4 × 4 you would write followed by a comment displaying its value. The two forms are inline, like this: (+ (* 3 3)(* 4 4)) 3 There are a few strengths to this setup. First, (def a 10) precedence is explicit. You all know the algebraic (def b (+ 15 5)) rules governing times and plus, but there are many (+ a b) ; => 30 other operators. Second, this allows functions to take a variable number of arguments. For example, Variables created by def persist throughout their you can say (+ 2 4 8) to get 14, and you can say (< scope. 10 x 20) to check if variable x is between 10 and 20. Here is some example code 3.2 Let (+ 10 20 30) ; => 60 The second way to create variables is with the let (- 50 20 1) ; => 29 form. The syntax is (let [v1 e1 ...] body). Un- (* 8 6 7 5 3 9) ; => 45360 like def, the variables created by let are temporary (mod 10 4) ; => 2 and local. They exist only in the body part of the let, and then disappear. You can define more than 2.2 Mathematics one variable at a time by adding more pairs. Clojure uses Java’s Math library to handle ma- This session illustrates the interaction between lo- chine math. There is a separate library if you want cal and global variables. to use such functions on extended precision numbers. We will not be needing that in this class.
Recommended publications
  • Programming Languages
    Programming Languages Recitation Summer 2014 Recitation Leader • Joanna Gilberti • Email: [email protected] • Office: WWH, Room 328 • Web site: http://cims.nyu.edu/~jlg204/courses/PL/index.html Homework Submission Guidelines • Submit all homework to me via email (at [email protected] only) on the due date. • Email subject: “PL– homework #” (EXAMPLE: “PL – Homework 1”) • Use file naming convention on all attachments: “firstname_lastname_hw_#” (example: "joanna_gilberti_hw_1") • In the case multiple files are being submitted, package all files into a ZIP file, and name the ZIP file using the naming convention above. What’s Covered in Recitation • Homework Solutions • Questions on the homeworks • For additional questions on assignments, it is best to contact me via email. • I will hold office hours (time will be posted on the recitation Web site) • Run sample programs that demonstrate concepts covered in class Iterative Languages Scoping • Sample Languages • C: static-scoping • Perl: static and dynamic-scoping (use to be only dynamic scoping) • Both gcc (to run C programs), and perl (to run Perl programs) are installed on the cims servers • Must compile the C program with gcc, and then run the generated executable • Must include the path to the perl executable in the perl script Basic Scope Concepts in C • block scope (nested scope) • run scope_levels.c (sl) • ** block scope: set of statements enclosed in braces {}, and variables declared within a block has block scope and is active and accessible from its declaration to the end of the block
    [Show full text]
  • Preview Objective-C Tutorial (PDF Version)
    Objective-C Objective-C About the Tutorial Objective-C is a general-purpose, object-oriented programming language that adds Smalltalk-style messaging to the C programming language. This is the main programming language used by Apple for the OS X and iOS operating systems and their respective APIs, Cocoa and Cocoa Touch. This reference will take you through simple and practical approach while learning Objective-C Programming language. Audience This reference has been prepared for the beginners to help them understand basic to advanced concepts related to Objective-C Programming languages. Prerequisites Before you start doing practice with various types of examples given in this reference, I'm making an assumption that you are already aware about what is a computer program, and what is a computer programming language? Copyright & Disclaimer © Copyright 2015 by Tutorials Point (I) Pvt. Ltd. All the content and graphics published in this e-book are the property of Tutorials Point (I) Pvt. Ltd. The user of this e-book can retain a copy for future reference but commercial use of this data is not allowed. Distribution or republishing any content or a part of the content of this e-book in any manner is also not allowed without written consent of the publisher. We strive to update the contents of our website and tutorials as timely and as precisely as possible, however, the contents may contain inaccuracies or errors. Tutorials Point (I) Pvt. Ltd. provides no guarantee regarding the accuracy, timeliness or completeness of our website or its contents including this tutorial. If you discover any errors on our website or in this tutorial, please notify us at [email protected] ii Objective-C Table of Contents About the Tutorial ..................................................................................................................................
    [Show full text]
  • Chapter 5 Names, Bindings, and Scopes
    Chapter 5 Names, Bindings, and Scopes 5.1 Introduction 198 5.2 Names 199 5.3 Variables 200 5.4 The Concept of Binding 203 5.5 Scope 211 5.6 Scope and Lifetime 222 5.7 Referencing Environments 223 5.8 Named Constants 224 Summary • Review Questions • Problem Set • Programming Exercises 227 CMPS401 Class Notes (Chap05) Page 1 / 20 Dr. Kuo-pao Yang Chapter 5 Names, Bindings, and Scopes 5.1 Introduction 198 Imperative languages are abstractions of von Neumann architecture – Memory: stores both instructions and data – Processor: provides operations for modifying the contents of memory Variables are characterized by a collection of properties or attributes – The most important of which is type, a fundamental concept in programming languages – To design a type, must consider scope, lifetime, type checking, initialization, and type compatibility 5.2 Names 199 5.2.1 Design issues The following are the primary design issues for names: – Maximum length? – Are names case sensitive? – Are special words reserved words or keywords? 5.2.2 Name Forms A name is a string of characters used to identify some entity in a program. Length – If too short, they cannot be connotative – Language examples: . FORTRAN I: maximum 6 . COBOL: maximum 30 . C99: no limit but only the first 63 are significant; also, external names are limited to a maximum of 31 . C# and Java: no limit, and all characters are significant . C++: no limit, but implementers often impose a length limitation because they do not want the symbol table in which identifiers are stored during compilation to be too large and also to simplify the maintenance of that table.
    [Show full text]
  • Introduction to Programming in Lisp
    Introduction to Programming in Lisp Supplementary handout for 4th Year AI lectures · D W Murray · Hilary 1991 1 Background There are two widely used languages for AI, viz. Lisp and Prolog. The latter is the language for Logic Programming, but much of the remainder of the work is programmed in Lisp. Lisp is the general language for AI because it allows us to manipulate symbols and ideas in a commonsense manner. Lisp is an acronym for List Processing, a reference to the basic syntax of the language and aim of the language. The earliest list processing language was in fact IPL developed in the mid 1950’s by Simon, Newell and Shaw. Lisp itself was conceived by John McCarthy and students in the late 1950’s for use in the newly-named field of artificial intelligence. It caught on quickly in MIT’s AI Project, was implemented on the IBM 704 and by 1962 to spread through other AI groups. AI is still the largest application area for the language, but the removal of many of the flaws of early versions of the language have resulted in its gaining somewhat wider acceptance. One snag with Lisp is that although it started out as a very pure language based on mathematic logic, practical pressures mean that it has grown. There were many dialects which threaten the unity of the language, but recently there was a concerted effort to develop a more standard Lisp, viz. Common Lisp. Other Lisps you may hear of are FranzLisp, MacLisp, InterLisp, Cambridge Lisp, Le Lisp, ... Some good things about Lisp are: • Lisp is an early example of an interpreted language (though it can be compiled).
    [Show full text]
  • Algorithms and Data Structures Lecture 11: Symbol Table ADT
    cs2010: algorithms and data structures Lecture 11: Symbol Table ADT Vasileios Koutavas School of Computer Science and Statistics Trinity College Dublin Algorithms ROBERT SEDGEWICK | KEVIN WAYNE 3.1 SYMBOL TABLES ‣ API ‣ elementary implementations Algorithms ‣ ordered operations FOURTH EDITION ROBERT SEDGEWICK | KEVIN WAYNE http://algs4.cs.princeton.edu 3.1 SYMBOL TABLES ‣ API ‣ elementary implementations Algorithms ‣ ordered operations ROBERT SEDGEWICK | KEVIN WAYNE http://algs4.cs.princeton.edu Symbol tables Key-value pair abstraction. ・Insert a value with specified key. ・Given a key, search for the corresponding value. Ex. DNS lookup. ・Insert domain name with specified IP address. ・Given domain name, find corresponding IP address. domain name IP address www.cs.princeton.edu 128.112.136.11 www.princeton.edu 128.112.128.15 www.yale.edu 130.132.143.21 www.harvard.edu 128.103.060.55 www.simpsons.com 209.052.165.60 key value 3 Symbol table applications application purpose of search key value dictionary find definition word definition book index find relevant pages term list of page numbers file share find song to download name of song computer ID financial account process transactions account number transaction details web search find relevant web pages keyword list of page names compiler find properties of variables variable name type and value routing table route Internet packets destination best route DNS find IP address domain name IP address reverse DNS find domain name IP address domain name genomics find markers DNA string known positions file system find file on disk filename location on disk 4 Symbol tables: context Also known as: maps, dictionaries, associative arrays.
    [Show full text]
  • The Machine That Builds Itself: How the Strengths of Lisp Family
    Khomtchouk et al. OPINION NOTE The Machine that Builds Itself: How the Strengths of Lisp Family Languages Facilitate Building Complex and Flexible Bioinformatic Models Bohdan B. Khomtchouk1*, Edmund Weitz2 and Claes Wahlestedt1 *Correspondence: [email protected] Abstract 1Center for Therapeutic Innovation and Department of We address the need for expanding the presence of the Lisp family of Psychiatry and Behavioral programming languages in bioinformatics and computational biology research. Sciences, University of Miami Languages of this family, like Common Lisp, Scheme, or Clojure, facilitate the Miller School of Medicine, 1120 NW 14th ST, Miami, FL, USA creation of powerful and flexible software models that are required for complex 33136 and rapidly evolving domains like biology. We will point out several important key Full list of author information is features that distinguish languages of the Lisp family from other programming available at the end of the article languages and we will explain how these features can aid researchers in becoming more productive and creating better code. We will also show how these features make these languages ideal tools for artificial intelligence and machine learning applications. We will specifically stress the advantages of domain-specific languages (DSL): languages which are specialized to a particular area and thus not only facilitate easier research problem formulation, but also aid in the establishment of standards and best programming practices as applied to the specific research field at hand. DSLs are particularly easy to build in Common Lisp, the most comprehensive Lisp dialect, which is commonly referred to as the “programmable programming language.” We are convinced that Lisp grants programmers unprecedented power to build increasingly sophisticated artificial intelligence systems that may ultimately transform machine learning and AI research in bioinformatics and computational biology.
    [Show full text]
  • An Evaluation of Go and Clojure
    An evaluation of Go and Clojure A thesis submitted in partial satisfaction of the requirements for the degree Bachelors of Science in Computer Science Fall 2010 Robert Stimpfling Department of Computer Science University of Colorado, Boulder Advisor: Kenneth M. Anderson, PhD Department of Computer Science University of Colorado, Boulder 1. Introduction Concurrent programming languages are not new, but they have been getting a lot of attention more recently due to their potential with multiple processors. Processors have gone from growing exponentially in terms of speed, to growing in terms of quantity. This means processes that are completely serial in execution will soon be seeing a plateau in performance gains since they can only rely on one processor. A popular approach to using these extra processors is to make programs multi-threaded. The threads can execute in parallel and use shared memory to speed up execution times. These multithreaded processes can significantly speed up performance, as long as the number of dependencies remains low. Amdahl‘s law states that these performance gains can only be relative to the amount of processing that can be parallelized [1]. However, the performance gains are significant enough to be looked into. These gains not only come from the processing being divvied up into sections that run in parallel, but from the inherent gains from sharing memory and data structures. Passing new threads a copy of a data structure can be demanding on the processor because it requires the processor to delve into memory and make an exact copy in a new location in memory. Indeed some studies have shown that the problem with optimizing concurrent threads is not in utilizing the processors optimally, but in the need for technical improvements in memory performance [2].
    [Show full text]
  • Scope in Fortran 90
    Scope in Fortran 90 The scope of objects (variables, named constants, subprograms) within a program is the portion of the program in which the object is visible (can be use and, if it is a variable, modified). It is important to understand the scope of objects not only so that we know where to define an object we wish to use, but also what portion of a program unit is effected when, for example, a variable is changed, and, what errors might occur when using identifiers declared in other program sections. Objects declared in a program unit (a main program section, module, or external subprogram) are visible throughout that program unit, including any internal subprograms it hosts. Such objects are said to be global. Objects are not visible between program units. This is illustrated in Figure 1. Figure 1: The figure shows three program units. Main program unit Main is a host to the internal function F1. The module program unit Mod is a host to internal function F2. The external subroutine Sub hosts internal function F3. Objects declared inside a program unit are global; they are visible anywhere in the program unit including in any internal subprograms that it hosts. Objects in one program unit are not visible in another program unit, for example variable X and function F3 are not visible to the module program unit Mod. Objects in the module Mod can be imported to the main program section via the USE statement, see later in this section. Data declared in an internal subprogram is only visible to that subprogram; i.e.
    [Show full text]
  • Clojure, Given the Pun on Closure, Representing Anything Specific
    dynamic, functional programming for the JVM “It (the logo) was designed by my brother, Tom Hickey. “It I wanted to involve c (c#), l (lisp) and j (java). I don't think we ever really discussed the colors Once I came up with Clojure, given the pun on closure, representing anything specific. I always vaguely the available domains and vast emptiness of the thought of them as earth and sky.” - Rich Hickey googlespace, it was an easy decision..” - Rich Hickey Mark Volkmann [email protected] Functional Programming (FP) In the spirit of saying OO is is ... encapsulation, inheritance and polymorphism ... • Pure Functions • produce results that only depend on inputs, not any global state • do not have side effects such as Real applications need some changing global state, file I/O or database updates side effects, but they should be clearly identified and isolated. • First Class Functions • can be held in variables • can be passed to and returned from other functions • Higher Order Functions • functions that do one or both of these: • accept other functions as arguments and execute them zero or more times • return another function 2 ... FP is ... Closures • main use is to pass • special functions that retain access to variables a block of code that were in their scope when the closure was created to a function • Partial Application • ability to create new functions from existing ones that take fewer arguments • Currying • transforming a function of n arguments into a chain of n one argument functions • Continuations ability to save execution state and return to it later think browser • back button 3 ..
    [Show full text]
  • Programming Language Concepts/Binding and Scope
    Programming Language Concepts/Binding and Scope Programming Language Concepts/Binding and Scope Onur Tolga S¸ehito˘glu Bilgisayar M¨uhendisli˘gi 11 Mart 2008 Programming Language Concepts/Binding and Scope Outline 1 Binding 6 Declarations 2 Environment Definitions and Declarations 3 Block Structure Sequential Declarations Monolithic block structure Collateral Declarations Flat block structure Recursive declarations Nested block structure Recursive Collateral Declarations 4 Hiding Block Expressions 5 Static vs Dynamic Scope/Binding Block Commands Static binding Block Declarations Dynamic binding 7 Summary Programming Language Concepts/Binding and Scope Binding Binding Most important feature of high level languages: programmers able to give names to program entities (variable, constant, function, type, ...). These names are called identifiers. Programming Language Concepts/Binding and Scope Binding Binding Most important feature of high level languages: programmers able to give names to program entities (variable, constant, function, type, ...). These names are called identifiers. definition of an identifier ⇆ used position of an identifier. Formally: binding occurrence ⇆ applied occurrence. Programming Language Concepts/Binding and Scope Binding Binding Most important feature of high level languages: programmers able to give names to program entities (variable, constant, function, type, ...). These names are called identifiers. definition of an identifier ⇆ used position of an identifier. Formally: binding occurrence ⇆ applied occurrence. Identifiers are declared once, used n times. Programming Language Concepts/Binding and Scope Binding Binding Most important feature of high level languages: programmers able to give names to program entities (variable, constant, function, type, ...). These names are called identifiers. definition of an identifier ⇆ used position of an identifier. Formally: binding occurrence ⇆ applied occurrence. Identifiers are declared once, used n times.
    [Show full text]
  • Names, Scopes, and Bindings (Cont.)
    Chapter 3:: Names, Scopes, and Bindings (cont.) Programming Language Pragmatics Michael L. Scott Copyright © 2005 Elsevier Review • What is a regular expression ? • What is a context-free grammar ? • What is BNF ? • What is a derivation ? • What is a parse ? • What are terminals/non-terminals/start symbol ? • What is Kleene star and how is it denoted ? • What is binding ? Copyright © 2005 Elsevier Review • What is early/late binding with respect to OOP and Java in particular ? • What is scope ? • What is lifetime? • What is the “general” basic relationship between compile time/run time and efficiency/flexibility ? • What is the purpose of scope rules ? • What is central to recursion ? Copyright © 2005 Elsevier 1 Lifetime and Storage Management • Maintenance of stack is responsibility of calling sequence and subroutine prolog and epilog – space is saved by putting as much in the prolog and epilog as possible – time may be saved by • putting stuff in the caller instead or • combining what's known in both places (interprocedural optimization) Copyright © 2005 Elsevier Lifetime and Storage Management • Heap for dynamic allocation Copyright © 2005 Elsevier Scope Rules •A scope is a program section of maximal size in which no bindings change, or at least in which no re-declarations are permitted (see below) • In most languages with subroutines, we OPEN a new scope on subroutine entry: – create bindings for new local variables, – deactivate bindings for global variables that are re- declared (these variable are said to have a "hole" in their
    [Show full text]
  • Class 15: Implementing Scope in Function Calls
    Class 15: Implementing Scope in Function Calls SI 413 - Programming Languages and Implementation Dr. Daniel S. Roche United States Naval Academy Fall 2011 Roche (USNA) SI413 - Class 15 Fall 2011 1 / 10 Implementing Dynamic Scope For dynamic scope, we need a stack of bindings for every name. These are stored in a Central Reference Table. This primarily consists of a mapping from a name to a stack of values. The Central Reference Table may also contain a stack of sets, each containing identifiers that are in the current scope. This tells us which values to pop when we come to an end-of-scope. Roche (USNA) SI413 - Class 15 Fall 2011 2 / 10 Example: Central Reference Tables with Lambdas { new x := 0; new i := -1; new g := lambda z{ ret :=i;}; new f := lambda p{ new i :=x; i f (i>0){ ret :=p(0); } e l s e { x :=x + 1; i := 3; ret :=f(g); } }; w r i t e f( lambda y{ret := 0}); } What gets printed by this (dynamically-scoped) SPL program? Roche (USNA) SI413 - Class 15 Fall 2011 3 / 10 (dynamic scope, shallow binding) (dynamic scope, deep binding) (lexical scope) Example: Central Reference Tables with Lambdas The i in new g := lambda z{ w r i t e i;}; from the previous program could be: The i in scope when the function is actually called. The i in scope when g is passed as p to f The i in scope when g is defined Roche (USNA) SI413 - Class 15 Fall 2011 4 / 10 Example: Central Reference Tables with Lambdas The i in new g := lambda z{ w r i t e i;}; from the previous program could be: The i in scope when the function is actually called.
    [Show full text]