Coffeescript in Action

Total Page:16

File Type:pdf, Size:1020Kb

Coffeescript in Action Patrick Lee MANNING CoffeeScript in Action Licensed to <[email protected]> Licensed to <[email protected]> CoffeeScript in Action PATRICK LEE MANNING SHELTER ISLAND Licensed to <[email protected]> For online information and ordering of this and other Manning books, please visit www.manning.com. The publisher offers discounts on this book when ordered in quantity. For more information, please contact Special Sales Department Manning Publications Co. 20 Baldwin Road PO Box 261 Shelter Island, NY 11964 Email: [email protected] ©2014 by Manning Publications Co. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps. Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end. Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15 percent recycled and processed without the use of elemental chlorine. Manning Publications Co. Development editors: Renae Gregoire, Jennifer Stout 20 Baldwin Road Copyeditor: Linda Recktenwald PO Box 261 Proofreaders: Andy Carroll, Katie Tennant Shelter Island, NY 11964 Technical proofreader: Doug Warren Typesetter: Dennis Dalinnik Illustrator: Nick Marino Cover designer: Marija Tudor ISBN: 9781617290626 Printed in the United States of America 12345678910–EBM–191817161514 Licensed to <[email protected]> brief contents PART 1FOUNDATIONS ..............................................................1 1 ■ The road to CoffeeScript 3 2 ■ Simplified syntax 13 3 ■ First-class functions 45 4 ■ Dynamic objects 76 PART 2COMPOSITION ..........................................................105 5 ■ Composing objects 107 6 ■ Composing functions 144 7 ■ Style and semantics 179 8 ■ Metaprogramming 214 9 ■ Composing the asynchronous 241 PART 3APPLICATIONS...........................................................267 10 ■ Driving with tests 269 11 ■ In the browser 299 12 ■ Modules and builds 321 13 ■ ECMAScript and the future of CoffeeScript 353 v Licensed to <[email protected]> Licensed to <[email protected]> contents preface xv acknowledgments xvi about this book xvii about the cover illustration xxi PART 1FOUNDATIONS...................................................1 The road to CoffeeScript 3 1 1.1 Why CoffeeScript? 4 1.2 Running CoffeeScript 5 1.3 JavaScript 6 C6■ Scheme 7 ■ Self 7 1.4 Evolving JavaScript 8 A little story about language 8 ■ The lesson for JavaScript 9 1.5 Creating CoffeeScript 9 Designing new syntax 9 ■ Achieving new syntax 11 1.6 Summary 12 vii Licensed to <[email protected]> viii CONTENTS Simplified syntax 13 2 2.1 Your first program 14 Comparing CoffeeScript to JavaScript 14 2.2 Simple expressions 16 Literal values 16 ■ Variables 18 2.3 Operators 18 Essentials 19 ■ Types, existential, and combining operators 23 ■ Exercises 25 2.4 Statements 25 Anatomy 25 ■ Statements as expressions 26 Pure statements 30 ■ Exercise 31 2.5 Strings 31 Methods 31 ■ Interpolation 32 ■ Exercise 33 2.6 Arrays 33 length, join, slice, and concat 34 ■ in 35 Ranges 35 ■ Comprehensions 36 ■ Exercise 39 2.7 Heres for comments, docs, and regexes 39 Comments 39 ■ Heredocs 40 ■ Heregexes 41 2.8 Putting it together 41 Running in a browser 41 ■ Running on the command line 42 2.9 Summary 44 First-class functions 45 3 3.1 Computation 46 Basics 46 ■ Custom operations 47 ■ Anatomy 48 Comparison: JavaScript and CoffeeScript 52 ■ Exercises 52 3.2 Events 53 Browser events 53 ■ Using timeouts and intervals to create events 54 3.3 I/O 56 Ajax 56 ■ Event-driven file reading with Node.js 57 Event-driven file serving with Node.js 58 ■ Exercises 59 3.4 Higher-order functions 59 Invoking other functions 60 ■ Example: Counting words in a file 61 ■ Functions as arguments 62 ■ Exercises 65 Licensed to <[email protected]> CONTENTS ix 3.5 Scope 66 Lexical function scope 66 ■ No block scope 66 Implicit variable declarations 67 ■ Nesting 68 3.6 Closures 70 Global state problems 70 ■ Functions as return values 70 Extended example: using closure 72 3.7 Putting it together 73 3.8 Summary 75 Dynamic objects 76 4 4.1 Syntax 77 Literals 77 ■ Properties 77 ■ YAML-style syntax 78 4.2 Key-value stores 78 Data 79 ■ Key-values for named arguments 82 ■ Exercises 84 4.3 Comprehensions 85 Object comprehensions 85 ■ Example 87 4.4 Structured data 89 JSON 89 ■ Trees 89 4.5 Binding 91 this 91 ■ The fat arrow 94 4.6 Prototypes 96 Copy 96 ■ Object creation 97 ■ Exercises 98 4.7 Behavior 98 Refactor 99 ■ Exercise 100 4.8 Classes 100 Declaration 101 ■ Object identity 102 ■ Exercises 103 4.9 Putting it together 103 4.10 Summary 104 PART 2COMPOSITION...............................................105 Composing objects 107 5 5.1 Being classical 108 Raw data 108 ■ Class abstractions 109 5.2 Class inheritance 112 extends 112 ■ How does it work? 114 Licensed to <[email protected]> x CONTENTS 5.3 Class variables and properties 116 Usage 117 ■ Declaring (to keep things together) 119 Exercise 122 5.4 Overriding and super 122 Overriding 122 ■ super 123 5.5 Modifying prototypes 125 How class declarations work 125 ■ How methods work 126 Dynamic classes 127 5.6 Extending built-ins 130 Built-in constructor prototypes 130 ■ Extending date 131 Don’t modify objects you don’t own 134 5.7 Mixins 135 Class inheritance can be awkward 135 ■ Writing a mixin 136 Example: enumerable mixin 137 ■ Mixins from null 139 5.8 Putting it together 140 Exercise 143 5.9 Summary 143 Composing functions 144 6 6.1 Clarity 145 Functions are descriptions 145 ■ Where arguments need parentheses 146 ■ Higher-order functions revisited 147 6.2 State and mutability 152 Variables, assignment, and side effects 152 ■ Local state and shared state 153 ■ Encapsulating state with objects 156 World state 157 6.3 Abstraction 159 Extracting common code 159 ■ Adding common code 163 Recursion 165 6.4 Combinators 168 Compose 169 ■ Before and after 170 ■ Around 172 Working with objects 173 ■ Asynchronous combinators 176 6.5 Summary 178 Style and semantics 179 7 7.1 Rest and spread parameters 180 Rest 180 ■ Spread 181 Licensed to <[email protected]> CONTENTS xi 7.2 Destructuring 183 Arrays 183 ■ Objects 184 ■ Object shorthand 185 Array destructuring expansion 187 ■ Exercises 187 Putting it together 187 7.3 No nulls 188 Null soak 189 ■ Conditional assignment 191 7.4 No types—the duck test 193 Don’t rely on typeof, instanceof, or constructor 194 How to use duck typing 195 7.5 When to use comprehensions (and when not to) 199 map 200 ■ filter 201 ■ reduce 201 ■ Defining functions inside comprehensions 202 7.6 Fluent interfaces 203 Why create them? 203 ■ The indentation problem 205 Creating fluent interfaces 207 ■ Chain 208 7.7 Ambiguity 209 Whitespace and indentation 209 ■ Implicit variables 212 7.8 Summary 213 Metaprogramming 214 8 8.1 Literate CoffeeScript 215 The .litcoffee file extension 215 8.2 Domain-specific languages 218 External DSLs 218 ■ Internal DSLs 219 Object literals 219 ■ Fluent interfaces 221 Function passing 222 ■ Constructing a DSL 223 8.3 How the compiler works 226 Tokenizing 228 ■ Rewriting 229 ■ The abstract syntax tree 230 8.4 Bending code to your ideas 232 Can you just eval? 232 ■ Rewriting the token stream 234 Using the abstract syntax tree 236 ■ It’s just JavaScript 238 8.5 Summary 240 Composing the asynchronous 241 9 9.1 Data processing 242 Reading 242 ■ Sorting 243 ■ Performance 246 Decorate, sort, undecorate 247 Licensed to <[email protected]> xii CONTENTS 9.2 Event loops 248 Events and blackouts 249 ■ Infinite time 251 9.3 Event emitters 252 User events 252 ■ Data as events 253 ■ Using event emitters in Node.js 254 ■ Events as data 256 9.4 Event composition 257 Lazy data handling 257 ■ Lazy event handling 259 Composing event streams 260 ■ Client side 263 Multiple event sources 265 9.5 Summary 266 PART 3APPLICATIONS ...............................................267 Driving with tests 269 10 10.1 No tests? Disaster awaits 270 10.2 How to write tests 271 Assertions 272 ■ How to unit test 273 Rinse and repeat 274 ■ Feedback 276 10.3 Dependencies 278 Why dependencies make testing difficult 278 ■ Test doubles 279 Avoiding dependency injection hell 284 10.4 Testing the asynchronous 286 Live with it 286 ■ Remove it 286 ■ Expect it 287 Exercise 290 10.5 System tests 290 10.6 Test suites 291 Setups and teardowns 292 ■ Test helpers and runners 293 Watchers 295 10.7 Summary 297 In the browser 299 11 11.1 Getting started 300 Manual compilation 301 ■ Browser compilation 301 Automatic compilation 301 11.2 Communicating with the outside world 302 Using XMLHttpRequest 302 ■ Dynamic script insertion 303 Going real time with WebSocket 305 Licensed to <[email protected]> CONTENTS xiii 11.3 Cross-browser compatibility 306 Polyfilling host objects 307 ■ Polyfilling language features 309 11.4 Creating a user interface 309 Retained mode with the DOM 310 ■ Immediate mode with HTML5 canvas 311 11.5 Creating animations 314 Retained mode 315 ■ Immediate mode 315 11.6 Structuring programs 317 Abstraction and APIs 317 ■ Dealing with time 319 11.7 Summary 320 Modules and builds 321 12 12.1 Server-side modules
Recommended publications
  • Interaction Between Web Browsers and Script Engines
    IT 12 058 Examensarbete 45 hp November 2012 Interaction between web browsers and script engines Xiaoyu Zhuang Institutionen för informationsteknologi Department of Information Technology Abstract Interaction between web browser and the script engine Xiaoyu Zhuang Teknisk- naturvetenskaplig fakultet UTH-enheten Web browser plays an important part of internet experience and JavaScript is the most popular programming language as a client side script to build an active and Besöksadress: advance end user experience. The script engine which executes JavaScript needs to Ångströmlaboratoriet Lägerhyddsvägen 1 interact with web browser to get access to its DOM elements and other host objects. Hus 4, Plan 0 Browser from host side needs to initialize the script engine and dispatch script source code to the engine side. Postadress: This thesis studies the interaction between the script engine and its host browser. Box 536 751 21 Uppsala The shell where the engine address to make calls towards outside is called hosting layer. This report mainly discussed what operations could appear in this layer and Telefon: designed testing cases to validate if the browser is robust and reliable regarding 018 – 471 30 03 hosting operations. Telefax: 018 – 471 30 00 Hemsida: http://www.teknat.uu.se/student Handledare: Elena Boris Ämnesgranskare: Justin Pearson Examinator: Lisa Kaati IT 12 058 Tryckt av: Reprocentralen ITC Contents 1. Introduction................................................................................................................................
    [Show full text]
  • Basic Structures: Sets, Functions, Sequences, and Sums 2-2
    CHAPTER Basic Structures: Sets, Functions, 2 Sequences, and Sums 2.1 Sets uch of discrete mathematics is devoted to the study of discrete structures, used to represent discrete objects. Many important discrete structures are built using sets, which 2.2 Set Operations M are collections of objects. Among the discrete structures built from sets are combinations, 2.3 Functions unordered collections of objects used extensively in counting; relations, sets of ordered pairs that represent relationships between objects; graphs, sets of vertices and edges that connect 2.4 Sequences and vertices; and finite state machines, used to model computing machines. These are some of the Summations topics we will study in later chapters. The concept of a function is extremely important in discrete mathematics. A function assigns to each element of a set exactly one element of a set. Functions play important roles throughout discrete mathematics. They are used to represent the computational complexity of algorithms, to study the size of sets, to count objects, and in a myriad of other ways. Useful structures such as sequences and strings are special types of functions. In this chapter, we will introduce the notion of a sequence, which represents ordered lists of elements. We will introduce some important types of sequences, and we will address the problem of identifying a pattern for the terms of a sequence from its first few terms. Using the notion of a sequence, we will define what it means for a set to be countable, namely, that we can list all the elements of the set in a sequence.
    [Show full text]
  • Defensive Javascript Building and Verifying Secure Web Components
    Defensive JavaScript Building and Verifying Secure Web Components Karthikeyan Bhargavan1, Antoine Delignat-Lavaud1, and Sergio Maffeis2 1 INRIA Paris-Rocquencourt, France 2 Imperial College London, UK Abstract. Defensive JavaScript (DJS) is a typed subset of JavaScript that guarantees that the functional behavior of a program cannot be tampered with even if it is loaded by and executed within a malicious environment under the control of the attacker. As such, DJS is ideal for writing JavaScript security components, such as bookmarklets, single sign-on widgets, and cryptographic libraries, that may be loaded within untrusted web pages alongside unknown scripts from arbitrary third par- ties. We present a tutorial of the DJS language along with motivations for its design. We show how to program security components in DJS, how to verify their defensiveness using the DJS typechecker, and how to analyze their security properties automatically using ProVerif. 1 Introduction Since the advent of asynchronous web applications, popularly called AJAX or Web 2.0, JavaScript has become the predominant programming language for client-side web applications. JavaScript programs are widely deployed as scripts in web pages, but also as small storable snippets called bookmarklets, as down- loadable web apps,1 and as plugins or extensions to popular browsers.2 Main- stream browsers compete with each other in providing convenient APIs and fast JavaScript execution engines. More recently, Javascript is being used to program smartphone and desktop applications3, and also cloud-based server ap- plications,4 so that now programmers can use the same idioms and libraries to write and deploy a variety of client- and server-side programs.
    [Show full text]
  • 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]
  • Coffeescript Accelerated Javascript Development.Pdf
    Download from Wow! eBook <www.wowebook.com> What readers are saying about CoffeeScript: Accelerated JavaScript Development It’s hard to imagine a new web application today that doesn’t make heavy use of JavaScript, but if you’re used to something like Ruby, it feels like a significant step down to deal with JavaScript, more of a chore than a joy. Enter CoffeeScript: a pre-compiler that removes all the unnecessary verbosity of JavaScript and simply makes it a pleasure to write and read. Go, go, Coffee! This book is a great introduction to the world of CoffeeScript. ➤ David Heinemeier Hansson Creator, Rails Just like CoffeeScript itself, Trevor gets straight to the point and shows you the benefits of CoffeeScript and how to write concise, clear CoffeeScript code. ➤ Scott Leberknight Chief Architect, Near Infinity Though CoffeeScript is a new language, you can already find it almost everywhere. This book will show you just how powerful and fun CoffeeScript can be. ➤ Stan Angeloff Managing Director, PSP WebTech Bulgaria Download from Wow! eBook <www.wowebook.com> This book helps readers become better JavaScripters in the process of learning CoffeeScript. What’s more, it’s a blast to read, especially if you are new to Coffee- Script and ready to learn. ➤ Brendan Eich Creator, JavaScript CoffeeScript may turn out to be one of the great innovations in web application development; since I first discovered it, I’ve never had to write a line of pure JavaScript. I hope the readers of this wonderful book will be able to say the same. ➤ Dr. Nic Williams CEO/Founder, Mocra CoffeeScript: Accelerated JavaScript Development is an excellent guide to Coffee- Script from one of the community’s most esteemed members.
    [Show full text]
  • Chapter 1: Introduction to the Pencil Code Environment
    Chapter 1: Introduction to the Pencil Code Environment In this manual we will show how to use Pencil Code to explore programming. Pencil Code is a free programming tool available at pencilcode.net. Pencil Code was developed by Google engineer David Bau together with his son Anthony Bau, with open-source contributions from many others. Two Ways of Looking at a Program There are two ways of viewing a program. A computer user sees a program by looking at its output. A programmer works with a program’s source code. In Pencil Code, the screen is split into two halves, with the source code on the left and the output on the right. You run programs by by pressing the “play” button in the middle. The Pencil Code interface splits the screen, showing source code on the left and output on the right. The play button in the center runs the code and produces output. Languages and Libraries in Pencil Code Pencil Code supports code in both blocks and text using mainstream web programming languages and useful libraries including: • HTML, the standard HyperText Markup Language for the web. • JavaScript, the standard programming language of web browsers. • CSS, the standard Cascading Style Sheet language for visual styles on the web. • jQuery, a popular library that simplifies programming interactive websites. • CoffeeScript, a language that lets you do more with less typing than JavaScript. • jQuery-turtle, which extends jQuery to simplify graphics and animation for novices. With Pencil Code, students can use these technologies to create web applications with global visibility and impact while exploring fundamental concepts in computational thinking.
    [Show full text]
  • Coffeescript Accelerated Javascript Development, Second Edition
    Extracted from: CoffeeScript Accelerated JavaScript Development, Second Edition This PDF file contains pages extracted from CoffeeScript, published by the Prag- matic Bookshelf. For more information or to purchase a paperback or PDF copy, please visit http://www.pragprog.com. Note: This extract contains some colored text (particularly in code listing). This is available only in online versions of the books. The printed versions are black and white. Pagination might vary between the online and printed versions; the content is otherwise identical. Copyright © 2015 The Pragmatic Programmers, LLC. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form, or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior consent of the publisher. The Pragmatic Bookshelf Dallas, Texas • Raleigh, North Carolina CoffeeScript Accelerated JavaScript Development, Second Edition Trevor Burnham The Pragmatic Bookshelf Dallas, Texas • Raleigh, North Carolina 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 The Pragmatic Programmers, LLC was aware of a trademark claim, the designations have been printed in initial capital letters or in all capitals. The Pragmatic Starter Kit, The Pragmatic Programmer, Pragmatic Programming, Pragmatic Bookshelf, PragProg and the linking g device are trade- marks of The Pragmatic Programmers, LLC. Every precaution was taken in the preparation of this book. However, the publisher assumes no responsibility for errors or omissions, or for damages that may result from the use of information (including program listings) contained herein. Our Pragmatic courses, workshops, and other products can help you and your team create better software and have more fun.
    [Show full text]
  • Typescript-Handbook.Pdf
    This copy of the TypeScript handbook was created on Monday, September 27, 2021 against commit 519269 with TypeScript 4.4. Table of Contents The TypeScript Handbook Your first step to learn TypeScript The Basics Step one in learning TypeScript: The basic types. Everyday Types The language primitives. Understand how TypeScript uses JavaScript knowledge Narrowing to reduce the amount of type syntax in your projects. More on Functions Learn about how Functions work in TypeScript. How TypeScript describes the shapes of JavaScript Object Types objects. An overview of the ways in which you can create more Creating Types from Types types from existing types. Generics Types which take parameters Keyof Type Operator Using the keyof operator in type contexts. Typeof Type Operator Using the typeof operator in type contexts. Indexed Access Types Using Type['a'] syntax to access a subset of a type. Create types which act like if statements in the type Conditional Types system. Mapped Types Generating types by re-using an existing type. Generating mapping types which change properties via Template Literal Types template literal strings. Classes How classes work in TypeScript How JavaScript handles communicating across file Modules boundaries. The TypeScript Handbook About this Handbook Over 20 years after its introduction to the programming community, JavaScript is now one of the most widespread cross-platform languages ever created. Starting as a small scripting language for adding trivial interactivity to webpages, JavaScript has grown to be a language of choice for both frontend and backend applications of every size. While the size, scope, and complexity of programs written in JavaScript has grown exponentially, the ability of the JavaScript language to express the relationships between different units of code has not.
    [Show full text]
  • Introduction
    Introduction A need shared by many applications is the ability to authenticate a user and then bind a set of permissions to the user which indicate what actions the user is permitted to perform (i.e. authorization). A LocalSystem may have implemented it's own authentication and authorization and now wishes to utilize a federated Identity Provider (IdP). Typically the IdP provides an assertion with information describing the authenticated user. The goal is to transform the IdP assertion into a LocalSystem token. In it's simplest terms this is a data transformation which might include: • renaming of data items • conversion to a different format • deletion of data • addition of data • reorganization of data There are many ways such a transformation could be implemented: 1. Custom site specific code 2. Scripts written in a scripting language 3. XSLT 4. Rule based transforms We also desire these goals for the transformation. 1. Site administrator configurable 2. Secure 3. Simple 4. Extensible 5. Efficient Implementation choice 1, custom written code fails goals 1, 3 and 4, an admin cannot adapt it, it's not simple, and it's likely to be difficult to extend. Implementation choice 2, script based transformations have a lot of appeal. Because one has at their disposal the full power of an actual programming language there are virtually no limitations. If it's a popular scripting language an administrator is likely to already know the language and might be able to program a new transformation or at a minimum tweak an existing script. Forking out to a script interpreter is inefficient, but it's now possible to embed script interpreters in the existing application.
    [Show full text]
  • Understanding the Syntactic Rule Usage in Java
    View metadata, citation and similar papers at core.ac.uk brought to you by CORE provided by UCL Discovery Understanding the Syntactic Rule Usage in Java Dong Qiua, Bixin Lia,∗, Earl T. Barrb, Zhendong Suc aSchool of Computer Science and Engineering, Southeast University, China bDepartment of Computer Science, University College London, UK cDepartment of Computer Science, University of California Davis, USA Abstract Context: Syntax is fundamental to any programming language: syntax defines valid programs. In the 1970s, computer scientists rigorously and empirically studied programming languages to guide and inform language design. Since then, language design has been artistic, driven by the aesthetic concerns and intuitions of language architects. Despite recent studies on small sets of selected language features, we lack a comprehensive, quantitative, empirical analysis of how modern, real-world source code exercises the syntax of its programming language. Objective: This study aims to understand how programming language syntax is employed in actual development and explore their potential applications based on the results of syntax usage analysis. Method: We present our results on the first such study on Java, a modern, mature, and widely-used programming language. Our corpus contains over 5,000 open-source Java projects, totalling 150 million source lines of code (SLoC). We study both independent (i.e. applications of a single syntax rule) and dependent (i.e. applications of multiple syntax rules) rule usage, and quantify their impact over time and project size. Results: Our study provides detailed quantitative information and yields insight, particularly (i) confirming the conventional wisdom that the usage of syntax rules is Zipfian; (ii) showing that the adoption of new rules and their impact on the usage of pre-existing rules vary significantly over time; and (iii) showing that rule usage is highly contextual.
    [Show full text]
  • S-Algol Reference Manual Ron Morrison
    S-algol Reference Manual Ron Morrison University of St. Andrews, North Haugh, Fife, Scotland. KY16 9SS CS/79/1 1 Contents Chapter 1. Preface 2. Syntax Specification 3. Types and Type Rules 3.1 Universe of Discourse 3.2 Type Rules 4. Literals 4.1 Integer Literals 4.2 Real Literals 4.3 Boolean Literals 4.4 String Literals 4.5 Pixel Literals 4.6 File Literal 4.7 pntr Literal 5. Primitive Expressions and Operators 5.1 Boolean Expressions 5.2 Comparison Operators 5.3 Arithmetic Expressions 5.4 Arithmetic Precedence Rules 5.5 String Expressions 5.6 Picture Expressions 5.7 Pixel Expressions 5.8 Precedence Table 5.9 Other Expressions 6. Declarations 6.1 Identifiers 6.2 Variables, Constants and Declaration of Data Objects 6.3 Sequences 6.4 Brackets 6.5 Scope Rules 7. Clauses 7.1 Assignment Clause 7.2 if Clause 7.3 case Clause 7.4 repeat ... while ... do ... Clause 7.5 for Clause 7.6 abort Clause 8. Procedures 8.1 Declarations and Calls 8.2 Forward Declarations 2 9. Aggregates 9.1 Vectors 9.1.1 Creation of Vectors 9.1.2 upb and lwb 9.1.3 Indexing 9.1.4 Equality and Equivalence 9.2 Structures 9.2.1 Creation of Structures 9.2.2 Equality and Equivalence 9.2.3 Indexing 9.3 Images 9.3.1 Creation of Images 9.3.2 Indexing 9.3.3 Depth Selection 9.3.4 Equality and Equivalence 10. Input and Output 10.1 Input 10.2 Output 10.3 i.w, s.w and r.w 10.4 End of File 11.
    [Show full text]
  • Learning HTML5 Game Programming Addison-Wesley Learning Series
    Learning HTML5 Game Programming Addison-Wesley Learning Series Visit informit.com/learningseries for a complete list of available publications. The Addison-Wesley Learning Series is a collection of hands-on programming guides that help you quickly learn a new technology or language so you can apply what you’ve learned right away. Each title comes with sample code for the application or applications built in the text. This code is fully annotated and can be reused in your own projects with no strings attached. Many chapters end with a series of exercises to encourage you to reexamine what you have just learned, and to tweak or adjust the code as a way of learning. Titles in this series take a simple approach: they get you going right away and leave you with the ability to walk off and build your own application and apply the language or technology to whatever you are working on. Learning HTML5 Game Programming A Hands-on Guide to Building Online Games Using Canvas, SVG, and WebGL James L. Williams Upper Saddle River, NJ • Boston • Indianapolis • San Francisco New York • Toronto • Montreal • London • Munich • Paris • Madrid Cape Town • Sydney • Tokyo • Singapore • Mexico City Many of the designations used by manufacturers and sellers to distinguish their products Associate are claimed as trademarks. Where those designations appear in this book, and the publish- Publisher er was aware of a trademark claim, the designations have been printed with initial capital Mark Taub letters or in all capitals. Senior Acquisitions The author and publisher have taken care in the preparation of this book, but make no Editor expressed or implied warranty of any kind and assume no responsibility for errors or omis- Trina MacDonald sions.
    [Show full text]