The Scheme Programming Language, 4Th Edition

Total Page:16

File Type:pdf, Size:1020Kb

The Scheme Programming Language, 4Th Edition The Scheme Programming Language, 4th Edition The Scheme Programming Language, 4th Edition Table of Contents Table of Contents................................................................................................................................................1 Preface..................................................................................................................................................................5 Chapter 1. Introduction......................................................................................................................................9 Section 1.1. Scheme Syntax...................................................................................................................11 Section 1.2. Scheme Naming Conventions.....................................................................................12 Section 1.3. Typographical and Notational Conventions................................................................13 Chapter 2. Getting Started...............................................................................................................................15 Section 2.1. Interacting with Scheme....................................................................................................15 Section 2.2. Simple Expressions.....................................................................................................17 Section 2.3. Evaluating Scheme Expressions..................................................................................22 Section 2.4. Variables and Let Expressions....................................................................................23 Section 2.5. Lambda Expressions....................................................................................................25 Section 2.6. Top-Level Definitions.................................................................................................29 Section 2.7. Conditional Expressions..............................................................................................32 Section 2.8. Simple Recursion........................................................................................................37 Section 2.9. Assignment..................................................................................................................42 Chapter 3. Going Further................................................................................................................................51 Section 3.1. Syntactic Extension............................................................................................................51 Exercise 3.1.1..................................................................................................................................54 Section 3.2. More Recursion...........................................................................................................55 Section 3.3. Continuations...............................................................................................................62 Section 3.4. Continuation Passing Style..........................................................................................66 Section 3.5. Internal Definitions......................................................................................................68 Section 3.6. Libraries.......................................................................................................................72 Chapter 4. Procedures and Variable Bindings...............................................................................................75 Section 4.1. Variable References...........................................................................................................75 Section 4.2. Lambda........................................................................................................................75 Section 4.3. Case-Lambda...............................................................................................................76 Section 4.4. Local Binding..............................................................................................................78 Section 4.5. Multiple Values...........................................................................................................81 Section 4.6. Variable Definitions....................................................................................................81 Section 4.7. Assignment..................................................................................................................83 Chapter 5. Control Operations........................................................................................................................87 Section 5.1. Procedure Application.......................................................................................................87 Section 5.2. Sequencing..................................................................................................................88 Section 5.3. Conditionals.................................................................................................................88 Section 5.4. Recursion and Iteration...............................................................................................93 Section 5.5. Mapping and Folding..................................................................................................95 Section 5.6. Continuations...............................................................................................................99 Section 5.7. Delayed Evaluation...................................................................................................103 Section 5.8. Multiple Values.........................................................................................................105 Section 5.9. Eval............................................................................................................................110 Chapter 6. Operations on Objects.................................................................................................................113 Section 6.1. Constants and Quotation..................................................................................................113 Section 6.2. Generic Equivalence and Type Predicates................................................................115 i The Scheme Programming Language, 4th Edition Table of Contents Chapter 6. Operations on Objects Section 6.3. Lists and Pairs...........................................................................................................124 Section 6.4. Numbers....................................................................................................................133 Section 6.5. Fixnums.....................................................................................................................152 Section 6.6. Flonums.....................................................................................................................160 Section 6.7. Characters..................................................................................................................167 Section 6.8. Strings........................................................................................................................170 Section 6.9. Vectors.......................................................................................................................176 Section 6.10. Bytevectors..............................................................................................................179 Section 6.11. Symbols...................................................................................................................189 Section 6.12. Booleans..................................................................................................................191 Section 6.13. Hashtables...............................................................................................................191 Section 6.14. Enumerations...........................................................................................................196 Chapter 7. Input and Output.........................................................................................................................201 Section 7.1. Transcoders......................................................................................................................202 Section 7.2. Opening Files............................................................................................................203 Section 7.3. Standard Ports............................................................................................................205 Section 7.4. String and Bytevector Ports.......................................................................................206 Section 7.5. Opening Custom Ports...............................................................................................208 Section 7.6. Port Operations..........................................................................................................210 Section 7.7. Input Operations........................................................................................................212 Section 7.8. Output Operations.....................................................................................................216 Section 7.9. Convenience I/O........................................................................................................217 Section 7.10. Filesystem Operations.............................................................................................221
Recommended publications
  • DC Console Using DC Console Application Design Software
    DC Console Using DC Console Application Design Software DC Console is easy-to-use, application design software developed specifically to work in conjunction with AML’s DC Suite. Create. Distribute. Collect. Every LDX10 handheld computer comes with DC Suite, which includes seven (7) pre-developed applications for common data collection tasks. Now LDX10 users can use DC Console to modify these applications, or create their own from scratch. AML 800.648.4452 Made in USA www.amltd.com Introduction This document briefly covers how to use DC Console and the features and settings. Be sure to read this document in its entirety before attempting to use AML’s DC Console with a DC Suite compatible device. What is the difference between an “App” and a “Suite”? “Apps” are single applications running on the device used to collect and store data. In most cases, multiple apps would be utilized to handle various operations. For example, the ‘Item_Quantity’ app is one of the most widely used apps and the most direct means to take a basic inventory count, it produces a data file showing what items are in stock, the relative quantities, and requires minimal input from the mobile worker(s). Other operations will require additional input, for example, if you also need to know the specific location for each item in inventory, the ‘Item_Lot_Quantity’ app would be a better fit. Apps can be used in a variety of ways and provide the LDX10 the flexibility to handle virtually any data collection operation. “Suite” files are simply collections of individual apps. Suite files allow you to easily manage and edit multiple apps from within a single ‘store-house’ file and provide an effortless means for device deployment.
    [Show full text]
  • Clostridium Difficile Infection: How to Deal with the Problem DH INFORMATION RE ADER B OX
    Clostridium difficile infection: How to deal with the problem DH INFORMATION RE ADER B OX Policy Estates HR / Workforce Commissioning Management IM & T Planning / Finance Clinical Social Care / Partnership Working Document Purpose Best Practice Guidance Gateway Reference 9833 Title Clostridium difficile infection: How to deal with the problem Author DH and HPA Publication Date December 2008 Target Audience PCT CEs, NHS Trust CEs, SHA CEs, Care Trust CEs, Medical Directors, Directors of PH, Directors of Nursing, PCT PEC Chairs, NHS Trust Board Chairs, Special HA CEs, Directors of Infection Prevention and Control, Infection Control Teams, Health Protection Units, Chief Pharmacists Circulation List Description This guidance outlines newer evidence and approaches to delivering good infection control and environmental hygiene. It updates the 1994 guidance and takes into account a national framework for clinical governance which did not exist in 1994. Cross Ref N/A Superseded Docs Clostridium difficile Infection Prevention and Management (1994) Action Required CEs to consider with DIPCs and other colleagues Timing N/A Contact Details Healthcare Associated Infection and Antimicrobial Resistance Department of Health Room 528, Wellington House 133-155 Waterloo Road London SE1 8UG For Recipient's Use Front cover image: Clostridium difficile attached to intestinal cells. Reproduced courtesy of Dr Jan Hobot, Cardiff University School of Medicine. Clostridium difficile infection: How to deal with the problem Contents Foreword 1 Scope and purpose 2 Introduction 3 Why did CDI increase? 4 Approach to compiling the guidance 6 What is new in this guidance? 7 Core Guidance Key recommendations 9 Grading of recommendations 11 Summary of healthcare recommendations 12 1.
    [Show full text]
  • Project1: Build a Small Scanner/Parser
    Project1: Build A Small Scanner/Parser Introducing Lex, Yacc, and POET cs5363 1 Project1: Building A Scanner/Parser Parse a subset of the C language Support two types of atomic values: int float Support one type of compound values: arrays Support a basic set of language concepts Variable declarations (int, float, and array variables) Expressions (arithmetic and boolean operations) Statements (assignments, conditionals, and loops) You can choose a different but equivalent language Need to make your own test cases Options of implementation (links available at class web site) Manual in C/C++/Java (or whatever other lang.) Lex and Yacc (together with C/C++) POET: a scripting compiler writing language Or any other approach you choose --- must document how to download/use any tools involved cs5363 2 This is just starting… There will be two other sub-projects Type checking Check the types of expressions in the input program Optimization/analysis/translation Do something with the input code, output the result The starting project is important because it determines which language you can use for the other projects Lex+Yacc ===> can work only with C/C++ POET ==> work with POET Manual ==> stick to whatever language you pick This class: introduce Lex/Yacc/POET to you cs5363 3 Using Lex to build scanners lex.yy.c MyLex.l lex/flex lex.yy.c a.out gcc/cc Input stream a.out tokens Write a lex specification Save it in a file (MyLex.l) Compile the lex specification file by invoking lex/flex lex MyLex.l A lex.yy.c file is generated
    [Show full text]
  • GNU M4, Version 1.4.7 a Powerful Macro Processor Edition 1.4.7, 23 September 2006
    GNU M4, version 1.4.7 A powerful macro processor Edition 1.4.7, 23 September 2006 by Ren´eSeindal This manual is for GNU M4 (version 1.4.7, 23 September 2006), a package containing an implementation of the m4 macro language. Copyright c 1989, 1990, 1991, 1992, 1993, 1994, 2004, 2005, 2006 Free Software Foundation, Inc. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled “GNU Free Documentation License.” i Table of Contents 1 Introduction and preliminaries ................ 3 1.1 Introduction to m4 ............................................. 3 1.2 Historical references ............................................ 3 1.3 Invoking m4 .................................................... 4 1.4 Problems and bugs ............................................. 8 1.5 Using this manual .............................................. 8 2 Lexical and syntactic conventions ............ 11 2.1 Macro names ................................................. 11 2.2 Quoting input to m4........................................... 11 2.3 Comments in m4 input ........................................ 11 2.4 Other kinds of input tokens ................................... 12 2.5 How m4 copies input to output ................................ 12 3 How to invoke macros........................
    [Show full text]
  • GNU M4, Version 1.4.19 a Powerful Macro Processor Edition 1.4.19, 28 May 2021
    GNU M4, version 1.4.19 A powerful macro processor Edition 1.4.19, 28 May 2021 by Ren´eSeindal, Fran¸coisPinard, Gary V. Vaughan, and Eric Blake ([email protected]) This manual (28 May 2021) is for GNU M4 (version 1.4.19), a package containing an implementation of the m4 macro language. Copyright c 1989{1994, 2004{2014, 2016{2017, 2020{2021 Free Software Foundation, Inc. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled \GNU Free Documentation License." i Table of Contents 1 Introduction and preliminaries ::::::::::::::::: 3 1.1 Introduction to m4 :::::::::::::::::::::::::::::::::::::::::::::: 3 1.2 Historical references :::::::::::::::::::::::::::::::::::::::::::: 3 1.3 Problems and bugs ::::::::::::::::::::::::::::::::::::::::::::: 4 1.4 Using this manual :::::::::::::::::::::::::::::::::::::::::::::: 5 2 Invoking m4::::::::::::::::::::::::::::::::::::::: 7 2.1 Command line options for operation modes ::::::::::::::::::::: 7 2.2 Command line options for preprocessor features ::::::::::::::::: 8 2.3 Command line options for limits control ::::::::::::::::::::::: 10 2.4 Command line options for frozen state ::::::::::::::::::::::::: 11 2.5 Command line options for debugging :::::::::::::::::::::::::: 11 2.6 Specifying input files on the command line :::::::::::::::::::::
    [Show full text]
  • Unix (And Linux)
    AWK....................................................................................................................................4 BC .....................................................................................................................................11 CHGRP .............................................................................................................................16 CHMOD.............................................................................................................................19 CHOWN ............................................................................................................................26 CP .....................................................................................................................................29 CRON................................................................................................................................34 CSH...................................................................................................................................36 CUT...................................................................................................................................71 DATE ................................................................................................................................75 DF .....................................................................................................................................79 DIFF ..................................................................................................................................84
    [Show full text]
  • 5 Command Line Functions by Barbara C
    ADAPS: Chapter 5. Command Line Functions 5 Command Line Functions by Barbara C. Hoopes and James F. Cornwall This chapter describes ADAPS command line functions. These are functions that are executed from the UNIX command line instead of from ADAPS menus, and that may be run manually or by automated means such as “cron” jobs. Most of these functions are NOT accessible from the ADAPS menus. These command line functions are described in detail below. 5.1 Hydra Although Hydra is available from ADAPS at the PR sub-menu, Edit Time Series Data using Hydra (TS_EDIT), it can also be started from the command line. However, to start Hydra outside of ADAPS, a DV or UV RDB file needs to be available to edit. The command is “hydra rdb_file_name.” For a complete description of using Hydra, refer to Section 4.5.2 Edit Time-Series Data using Hydra (TS_EDIT). 5.2 nwrt2rdb This command is used to output rating information in RDB format. It writes RDB files with a table containing the rating equation parameters or the rating point pairs, with all other information contained in the RDB comments. The following arguments can be used with this command: nwrt2rdb -ooutfile -zdbnum -aagency -nstation -dddid -trating_type -irating_id -e (indicates to output ratings in expanded form; it is ignored for equation ratings.) -l loctzcd (time zone code or local time code "LOC") -m (indicates multiple output files.) -r (rounding suppression) Rules • If -o is omitted, nwrt2rdb writes to stdout; AND arguments -n, -d, -t, and -i must be present. • If -o is present, no other arguments are required, and the program will use ADAPS routines to prompt for them.
    [Show full text]
  • An AWK to C++ Translator
    An AWK to C++ Translator Brian W. Kernighan Bell Laboratories Murray Hill, NJ 07974 [email protected] ABSTRACT This paper describes an experiment to produce an AWK to C++ translator and an AWK class definition and supporting library. The intent is to generate efficient and read- able C++, so that the generated code will run faster than interpreted AWK and can also be modified and extended where an AWK program could not be. The AWK class and library can also be used independently of the translator to access AWK facilities from C++ pro- grams. 1. Introduction An AWK program [1] is a sequence of pattern-action statements: pattern { action } pattern { action } ... A pattern is a regular expression, numeric expression, string expression, or combination of these; an action is executable code similar to C. The operation of an AWK program is for each input line for each pattern if the pattern matches the input line do the action Variables in an AWK program contain string or numeric values or both according to context; there are built- in variables for useful values such as the input filename and record number. Operators work on strings or numbers, coercing the types of their operands as necessary. Arrays have arbitrary subscripts (‘‘associative arrays’’). Input is read and input lines are split into fields, called $1, $2, etc. Control flow statements are like those of C: if-else, while, for, do. There are user-defined and built-in functions for arithmetic, string, regular expression pattern-matching, and input and output to/from arbitrary files and processes.
    [Show full text]
  • An Attribute- Grammar Compiling System Based on Yacc, Lex, and C Kurt M
    View metadata, citation and similar papers at core.ac.uk brought to you by CORE provided by Digital Repository @ Iowa State University Computer Science Technical Reports Computer Science 12-1992 Design, Implementation, Use, and Evaluation of Ox: An Attribute- Grammar Compiling System based on Yacc, Lex, and C Kurt M. Bischoff Iowa State University Follow this and additional works at: http://lib.dr.iastate.edu/cs_techreports Part of the Programming Languages and Compilers Commons Recommended Citation Bischoff, Kurt M., "Design, Implementation, Use, and Evaluation of Ox: An Attribute- Grammar Compiling System based on Yacc, Lex, and C" (1992). Computer Science Technical Reports. 23. http://lib.dr.iastate.edu/cs_techreports/23 This Article is brought to you for free and open access by the Computer Science at Iowa State University Digital Repository. It has been accepted for inclusion in Computer Science Technical Reports by an authorized administrator of Iowa State University Digital Repository. For more information, please contact [email protected]. Design, Implementation, Use, and Evaluation of Ox: An Attribute- Grammar Compiling System based on Yacc, Lex, and C Abstract Ox generalizes the function of Yacc in the way that attribute grammars generalize context-free grammars. Ordinary Yacc and Lex specifications may be augmented with definitions of synthesized and inherited attributes written in C syntax. From these specifications, Ox generates a program that builds and decorates attributed parse trees. Ox accepts a most general class of attribute grammars. The user may specify postdecoration traversals for easy ordering of side effects such as code generation. Ox handles the tedious and error-prone details of writing code for parse-tree management, so its use eases problems of security and maintainability associated with that aspect of translator development.
    [Show full text]
  • Make a Jump Start Together with Software Ag
    Software AG Fast Startup FAST STARTUP PROGRAM MAKE A JUMP START TOGETHER WITH SOFTWARE AG You have great ideas, a clear vision and the drive to build something really cool. You are smart, you are fast, you are innovative and you are determined to become a rock star of the startup community. Need some free software to build your solution on? Here’s the secret. When it comes to software partnership, the key differentiators are: technology leadership, ease of use, total cost of ownership and—most importantly—reliability. Why Software AG? Why not just freeware? The key to your success is a brilliant business idea, a sustainable For a homegrown, non-mission-critical application, there is business model, openhanded investors and finally paying nothing wrong with choosing freeware. But if you need best-in- customers. class functionality and reliability to build your business on, you It’s a strong partnership that can be the differentiator in the should think twice about the software you use. success of your business. What is your innovation? What do you require as the foundation That’s why you should partner with Software AG. for your intellectual property? Why should you spend time re- Building on 45 years of customer-centric innovation, we are inventing what professional developers invented and optimized ranked as a leader in key market categories, year after year. Our over many years for their paying customers? Do you want to grow solutions are faster to implement and easier to use than anything your business or just your development team? How reliable are else on the market.
    [Show full text]
  • The Cool Reference Manual∗
    The Cool Reference Manual∗ Contents 1 Introduction 3 2 Getting Started 3 3 Classes 4 3.1 Features . 4 3.2 Inheritance . 5 4 Types 6 4.1 SELF TYPE ........................................... 6 4.2 Type Checking . 7 5 Attributes 8 5.1 Void................................................ 8 6 Methods 8 7 Expressions 9 7.1 Constants . 9 7.2 Identifiers . 9 7.3 Assignment . 9 7.4 Dispatch . 10 7.5 Conditionals . 10 7.6 Loops . 11 7.7 Blocks . 11 7.8 Let . 11 7.9 Case . 12 7.10 New . 12 7.11 Isvoid . 12 7.12 Arithmetic and Comparison Operations . 13 ∗Copyright c 1995-2000 by Alex Aiken. All rights reserved. 1 8 Basic Classes 13 8.1 Object . 13 8.2 IO ................................................. 13 8.3 Int................................................. 14 8.4 String . 14 8.5 Bool . 14 9 Main Class 14 10 Lexical Structure 14 10.1 Integers, Identifiers, and Special Notation . 15 10.2 Strings . 15 10.3 Comments . 15 10.4 Keywords . 15 10.5 White Space . 15 11 Cool Syntax 17 11.1 Precedence . 17 12 Type Rules 17 12.1 Type Environments . 17 12.2 Type Checking Rules . 18 13 Operational Semantics 22 13.1 Environment and the Store . 22 13.2 Syntax for Cool Objects . 24 13.3 Class definitions . 24 13.4 Operational Rules . 25 14 Acknowledgements 30 2 1 Introduction This manual describes the programming language Cool: the Classroom Object-Oriented Language. Cool is a small language that can be implemented with reasonable effort in a one semester course. Still, Cool retains many of the features of modern programming languages including objects, static typing, and automatic memory management.
    [Show full text]
  • Usability Improvements for Products That Mandate Use of Command-Line Interface: Best Practices
    Usability improvements for products that mandate use of command-line interface: Best Practices Samrat Dutta M.Tech, International Institute of Information Technology, Electronics City, Bangalore Software Engineer, IBM Storage Labs, Pune [email protected] ABSTRACT This paper provides few methods to improve the usability of products which mandate the use of command-line interface. At present many products make command-line interfaces compulsory for performing some operations. In such environments, usability of the product becomes the link that binds the users with the product. This paper provides few mechanisms like consolidated hierarchical help structure for the complete product, auto-complete command-line features, intelligent command suggestions. These can be formalized as a pattern and can be used by software companies to embed into their product's command-line interfaces, to simplify its usability and provide a better experience for users so that they can adapt with the product much faster. INTRODUCTION Products that are designed around a command-line interface (CLI), often strive for usability issues. A blank prompt with a cursor blinking, waiting for input, does not provide much information about the functions and possibilities available. With no click-able option and hover over facility to view snippets, some users feel lost. All inputs being commands, to learn and gain expertise of all of them takes time. Considering that learning a single letter for each command (often the first letter of the command is used instead of the complete command to reduce stress) is not that difficult, but all this seems useless when the command itself is not known.
    [Show full text]