logo资料库

realm of racket.pdf

第1页 / 共316页
第2页 / 共316页
第3页 / 共316页
第4页 / 共316页
第5页 / 共316页
第6页 / 共316页
第7页 / 共316页
第8页 / 共316页
资料共316页,剩余部分请下载后查看
Preface: Hello World
Why Would I Want to Learn About Racket?
Who Should Read this Book?
What Teaching Approach Is Used?
Can I Skip Chapters?
Anything Else I Should Know?
Introduction: Open Paren
(.1 What Makes Lisp So Cool and Unusual?
(.2 Where Did Lisp Come From?
(.3 What Does Lisp Look Like?
(.4 Where Does Racket Come From?
(.5 What Is This Book About?
Halt—Chapter Checkpoint
Chapter 1: Getting Started
1.1 Readying Racket
1.2 Interacting with Racket
Raise—Chapter Checkpoint
Chapter 2: A First Racket Program
2.1 The Guess My Number Game
2.2 Defining Variables
2.3 Basic Racket Etiquette
2.4 Defining Functions in Racket
A Function for Guessing
Functions for Closing In
The Main Function
Resume—Chapter Checkpoint
Chapter 3: Basics of Racket
3.1 Syntax and Semantics
3.2 The Building Blocks of Racket Syntax
3.3 The Building Blocks of Racket Semantics
Booleans
Symbols
Numbers
Strings
3.4 Lists in Racket
CONS Cells
Functions for CONS Cells
Lists and List Functions
The CONS Function
The LIST Function
The FIRST and REST Functions
Nested Lists
3.5 Structures in Racket
Structure Basics
Nesting Structures
Structure Transparency
Interrupt—Chapter Checkpoint
Chapter 4: Conditions and Decisions
4.1 How to Ask
4.2 The Conditionals: IF and Beyond
One Thing at a Time with IF
The Special Form that Does It All: COND
A First Taste of Recursion
4.3 Cool Tricks with Conditionals
Using the Stealth Conditionals AND and OR
Using Functions that Return More than Just the Truth
4.4 Equality Predicates, Once More
4.5 Comparing and Testing
Writing a Test
What Is Not a Test
Testing in the Real World
More Testing Facilities
Call-with-current-continuation—Chapter Checkpoint
Chapter 4½: define define 'define
4½.1 Module-Level Definitions
Variable Definitions
Function Definitions
4½.2 Local Definitions
Abort—Chapter Checkpoint
Chapter 5: big-bang
5.1 Graphical User Interface
5.2 Landing a UFO
5.3 Using big-bang: Syntax and Semantics
5.4 Guessing Gooey
The Data
The Main Function
Key-Events
Rendering
Time to Stop
Exit—Chapter Checkpoint
Chapter Challenges
Chapter 6: Recursion Is Easy
6.1 Robot Snake
6.2 A Data Representation for the Snake Game
6.3 The Main Function
6.4 Clock Ticks
Eating and Growing
Slithering
Rotting Goo
6.5 Key-Events
6.6 Rendering
6.7 End Game
6.8 Auxiliary Functions
Return—Chapter Checkpoint
Chapter Challenges
Chapter 7: Land of Lambda
7.1 Functions as Values
7.2 Lambda
7.3 Higher-Order Fun
7.4 Two More Higher-Order Functions
7.5 Derive This!
7.6 apply
Break—Chapter Checkpoint
Chapter 8: Mutant Structs
8.1 Chad’s First Battle
8.2 Orc Battle
8.3 Setting Up the World, a First Step
8.4 Action: How Structs Really Work
8.5 More Actions, Setting Up the World for Good
8.6 Ready, Set, big-bang
8.7 Initializing the Orc World
8.8 Rendering the Orc World
8.9 The End of the World
8.10 Actions, A Final Look
Throw—Chapter Checkpoint
Chapter Challenges
Chapter 9: The Values of Loops
9.1 FOR Loops
9.2 Multiple Values
9.3 Back to FOR/FOLD
9.4 More on Loops
Waitpid—Chapter Checkpoint
Chapter 10: Dice of Doom
10.1 The Game Tree
10.2 Dice of Doom, The Game
10.3 Designing Dice of Doom: Take One
Filling in the Blanks
Simplifying the Rules
End of Game
Controlling the Game
10.4 How Game Trees Work
10.5 Game States and Game Trees for Dice of Doom
10.6 Roll the Dice
10.7 Rendering the Dice World
10.8 Input Handling
10.9 Creating a Game Tree
The Game Tree
Neighbors
Attacks
10.10 The End Game
Kill—Chapter Checkpoint
Chapter Challenges
Chapter 11: Power to the Lazy
11.1 Doomsday
11.2 Lazy Evaluation
11.3 Memoized Computations
11.4 Racket Can Be Lazy
Delay—Chapter Checkpoint
Chapter 12: Artificial Intelligence
12.1 An Intelligent Life-form
12.2 Lazy Evaluation
12.3 Adding Artificial Intelligence
Stop-when—Chapter Checkpoint
Chapter Challenges
Chapter 13: The World Is Not Enough
13.1 What Is a Distributed Game?
13.2 The Data
Messages
Previously Fabricated Structures
Packages
Bundles
Mail
iworld Structures
13.3 The Network Postal Service
13.4 Organizing Your Universe
13.5 Distributed Guess
The State of the Client and the State of the Server
The Server
The Client
Running the Game
Error—Chapter Checkpoint
Chapter Challenges
Chapter 14: Hungry Henry
14.1 King Henry the Hungry
14.2 Hungry Henry, the Game
14.3 Two United States
14.4 Henry’s Universe
Message Data and Structures
Complex Numbers Are Good Positions
A Day in the Life of a Server
A Day in the Life of a Client
14.5 State of the Union
State of Henry
State of the House
14.6 Main, Take Client
The Appetizer State
The Entree State
14.7 Main, Take Server
The Join State and Network Events
The Join State and Tick Events
The Play State and Network Events
The Play State and Tick Events
14.8 See Henry Run
On-disconnect—Chapter Checkpoint
Chapter Challenges
Good-Bye: Close Paren
).1 Run Racket Run
).2 Racket Is a Programming Language
).3 Racket Is a Metaprogramming Language
).4 Racket Is a Programming-Language Programming Language
So Long
Index
Realm of Racket
Realm of Racket learn to Program, one Game at a time! (list Forrest Bice Rose DeMaio Spencer Florence Feng-Yun Mimi Lin Scott Lindeman Nicole Nussbaum Eric Peterson Ryan Plessner David Van Horn Matthias Felleisen Conrad Barski, MD) San Francisco
Realm of Racket. Copyright © 2013 by Matthias Felleisen, David Van Horn, Conrad Barski, M.D., Forrest Bice, Rose DeMaio, Spencer Florence, Feng-Yun Mimi Lin, Scott Lindeman, Nicole Nussbaum, Eric Peterson, Ryan Plessner. All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior writ- ten permission of the copyright owner and the publisher. Printed in USA First printing 17 16 15 14 13 1 2 3 4 5 6 7 8 9 ISBN-10: 1-59327-491-2 ISBN-13: 978-1-59327-491-7 Publisher: William Pollock Production Editor: Alison Law Cover Illustration: Eric Peterson Illustrations: Feng-Yun Mimi Lin and Eric Peterson Interior Design and Composition: Rose DeMaio and Nicole Nussbaum Developmental Editors: Keith Fancher and William Pollock Copyeditor: Marilyn Smith Proofreader: Paula L. Fleming For information on distribution, translations, or bulk sales, please contact No Starch Press, Inc. directly: No Starch Press, Inc. 38 Ringold Street, San Francisco, CA 94103 phone: 415.863.9900; fax: 415.863.9950; info@nostarch.com; www.nostarch.com Library of Congress Cataloging-in-Publication Data: Felleisen, Matthias. Realm of Racket : learn to program, one game at a time! / by Matthias Felleisen, Conrad Barski, Forrest Bice, Rose DeMaio, Spencer Florence, Feng-yun Mimi Lin, Scott Lindeman, Nicole Nussbaum, Eric Peterson, Ryan Plessner, and David Van Horn. pages cm Includes index. ISBN-13: 978-1-59327-491-7 ISBN-10: 1-59327-491-2 1. Racket (Computer program language) 2. LISP (Computer program language) 3. Computer programming. I. Title. QA76.73.R33F45 2013 005.1--dc23 2013002308 No Starch Press and the No Starch Press logo are registered trademarks of No Starch Press, Inc. Other product and com- pany names mentioned herein may be the trademarks of their respective owners. Rather than use a trademark symbol with every occurrence of a trademarked name, we are using the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The information in this book is distributed on an “As Is” basis, without warranty. While every precaution has been taken in the preparation of this work, neither the author nor No Starch Press, Inc. shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in it.
to the memory of John mccarthy September 4, 1927–october 24, 2011
分享到:
收藏