Table Of ContentRACKET PROGRAMMING THE FUN WAY
From Strings to Turing Machines
by James W. Stelly
San Francisco
RACKET PROGRAMMING THE FUN WAY. Copyright © 2021 by James W.
Stelly.
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 written permission
of the copyright owner and the publisher.
ISBN-13: 978-1-7185-0082-2 (print)
ISBN-13: 978-1-7185-0083-9 (ebook)
Publisher: William Pollock
Executive Editor: Barbara Yien
Production Editor: Dapinder Dosanjh
Developmental Editor: Alex Freed
Interior Design: Octopod Studios
Cover Illustration: Gina Redman
Technical Reviewer: Matthew Flatt
Copyeditor: Chris Cartwright
Proofreader: Emelie Battaglia
For information on distribution, translations, or bulk sales, please contact No Starch
Press, Inc. directly:
No Starch Press, Inc.
245 8th 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
Names: Stelly, James W., author.
Title: Racket programming the fun way: from strings to turing machines /
by James W. Stelly.
Description: San Francisco : No Starch Press, [2021]. | Includes
bibliographical references and index.
Identifiers: LCCN 2020022884 (print) | LCCN 2020022885 (ebook) | ISBN
9781718500822 | ISBN 9781718500839 (ebook) | ISBN 1718500822
Subjects: LCSH: Racket (Computer program language) | LISP (Computer
program
language) | Computer programming.
Classification: LCC QA76.73.R33 S 2020 (print) | LCC
QA76.73.R33 (ebook)
| DDC 005.13/3–dc23
LC record available at https://lccn.loc.gov/2020022884
LC ebook record available at https://lccn.loc.gov/2020022885
No Starch Press and the No Starch Press logo are registered trademarks of No Starch
Press, Inc. Other product and company 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.
I dedicate this book to my mom and dad who patiently (and at times not
so patiently) endured my many childhood pranks.
About the Author
James W. Stelly has been dabbling with computers as both a hobbyist
and professional for over four decades. He has degrees in both
computer science and mathematics from the University of Houston. As
a hobbyist, his projects include robotics using Arduino and Raspberry Pi
along with numerous explorations of programming languages ranging
from machine language to C++ (and many others). His day job (now
part time since retirement) is developing a line of business applications
primarily aimed at record keeping and data management.
About the Technical Reviewer
Matthew Flatt is a professor in the School of Computing at the
University of Utah, where he works on extensible programming
languages, run-time systems, and applications of functional
programming. He is one of the developers of the Racket programming
language and a co-author of the introductory programming textbook
How to Design Programs.
BRIEF CONTENTS
Acknowledgments
Introduction
Chapter 1: Racket Basics
Chapter 2: Arithmetic and Other Numerical Paraphernalia
Chapter 3: Function Fundamentals
Chapter 4: Plotting, Drawing, and a Bit of Set Theory
Chapter 5: GUI: Getting Users Interested
Chapter 6: Data
Chapter 7: Searching for Answers
Chapter 8: Logic Programming
Chapter 9: Computing Machines
Chapter 10: TRAC: The Racket Algebraic Calculator
Appendix A: Number Bases
Appendix B: Special Symbols
Bibliography
Index
CONTENTS IN DETAIL
ACKNOWLEDGMENTS
INTRODUCTION
1
RACKET BASICS
Atomic Data
Lists
A First Look at Lists
S-Expressions
List Structure
A Few Useful List Functions
Defines, Assigns, and Variables
Symbols, Identifiers, and Keywords
Equality
Strings and Things
Characters
Useful String Functions
String Conversion and Formatting Functions
Vectors
Accessing Vector Elements
Useful Vector Functions
Using structs
Controlling Output
Summary
2
ARITHMETIC AND OTHER NUMERICAL
PARAPHERNALIA
Booleans
The Numerical Tower
Integers
Rationals
Reals
Complex Numbers
Numeric Comparison
Combining Data Types
Built-in Functions
Infix Notation
Summary
3
FUNCTION FUNDAMENTALS
What Is a Function?
Lambda Functions
Higher-Order Functions
Lexical Scoping
Conditional Expressions: It’s All About Choices
I’m Feeling a Bit Loopy!
Purity
The Power of the Dark Side
The for Family
Time for Some Closure
Applications
I Don’t Have a Queue
The Tower of Hanoi
Fibonacci and Friends
The Insurance Salesman Problem
Summary