Computer ScienceTextbook

Think Raku: How to Think Like a Computer Scientist

Not rated yetRate this book

Think Raku teaches problem solving and computer science through progressively richer Raku programs. Laurent Rosenfeld, with Allen B. Downey, combines small executable examples, debugging discussions, exercises, and extended solutions. This guide follows the January 2020 second edition, version 0.6. The language was formerly named Perl 6, which explains older links and catalog artwork; the linked PDF is explicitly the Raku edition. Reading should be paired with writing, running, explaining, and revising programs.

FormatExternal access
LanguageEnglish
SubjectComputer Science
LevelUndergraduate
No. of pages431
Published2020

Free reading is available at the official source. Opens in a new tab.

Think Raku: How to Think Like a Computer ScientistFree

About this book

Think Raku teaches problem solving and computer science through progressively richer Raku programs. Laurent Rosenfeld, with Allen B. Downey, combines small executable examples, debugging discussions, exercises, and extended solutions. This guide follows the January 2020 second edition, version 0.6. The language was formerly named Perl 6, which explains older links and catalog artwork; the linked PDF is explicitly the Raku edition. Reading should be paired with writing, running, explaining, and revising programs.

Book summary

Think Raku teaches problem solving and computer science through progressively richer Raku programs. Laurent Rosenfeld, with Allen B. Downey, combines small executable examples, debugging discussions, exercises, and extended solutions. This guide follows the January 2020 second edition, version 0.6. The language was formerly named Perl 6, which explains older links and catalog artwork; the linked PDF is explicitly the Raku edition. Reading should be paired with writing, running, explaining, and revising programs.

Chapter-by-chapter summaries

Chapter 1 — The Way of the Program

The first chapter introduces programming as a way to express precise procedures and investigate problems. It distinguishes levels of programming language and kinds of errors, establishing debugging as a normal part of the work. The important habit is to make a prediction, run a small experiment, and explain discrepancies. Write a short description of a task in ordinary language, identify where it is ambiguous, and then refine it into steps. This prepares you to treat code as an explicit model of a solution rather than a collection of commands to memorize.

Chapter 2 — Variables, Expressions, and Statements

Values, types, names, operators, and assignment provide the basic vocabulary of programs. The chapter explains how expressions produce results and statements organize actions, including how order of operations affects meaning. Comments and debugging advice help distinguish a program’s intention from its actual behavior. Trace several short examples by recording each variable’s value after every statement. Explain why assigning a value is different from asserting mathematical equality. Deliberately change one operator or value and predict the resulting behavior before executing the revision.

Chapter 3 — Functions

Functions package operations behind a name and interface, allowing programs to be decomposed and reused. The chapter develops calls, composition, parameters, arguments, local variables, signatures, and the difference between returning a value and performing an action. Stack diagrams make the flow of execution visible. Practice describing each subroutine’s inputs, result, and side effects before writing it. Trace a nested call without running the code, then compare with execution. Understanding scope and the call sequence is more durable than copying the appearance of a function definition.

Chapter 4 — Loops, Conditionals, and Recursion

Control structures let a program choose among alternatives and repeat work. Boolean expressions, logical operators, integer division, modulo, conditional forms, loops, and recursive calls broaden the range of solvable problems. The chapter also introduces input and command-line arguments. For every recursive function, identify a base case and explain how another call approaches it. For a loop, specify what changes and when it stops. Compare alternative solutions by their clarity and behavior on boundary inputs, including zero, empty input, and unexpected values.

Chapter 5 — Fruitful Subroutines

Returning useful values makes subroutines composable. The chapter emphasizes incremental development, Boolean functions, recursion, type checks, and multiple subroutines selected through signatures. Its recurring lesson is to grow a solution from small, verified pieces rather than attempting a finished program in one step. Define a simple contract, test a minimal implementation, and extend it only after explaining the existing result. When recursion appears difficult, reason about what a smaller call promises to return. Keep diagnostic output separate from the final result so intermediate investigation does not obscure the function’s interface.

Chapter 6 — Iteration

Iteration develops the management of changing state through reassignment, variable updates, while loops, scope, and loop-control statements. Numerical examples such as approximating square roots show how repeated improvement becomes an algorithm. Make a trace table with columns for the current state, condition, update, and stopping decision. Explain why a loop terminates and what property remains true during its execution. Compare a numerical tolerance with an exact equality test. Debugging becomes easier when the intended progress of the algorithm is written down explicitly.

Chapter 7 — Strings

Strings introduce sequences, traversal, counting, substring operations, searching, and text transformation. Regular expressions add a concise way to describe patterns using character classes, quantifiers, anchors, alternation, and captures. The chapter connects these ideas to practical extraction and substitution tasks. Build a small set of matching and nonmatching examples before designing a pattern. Check whether you are searching anywhere in a string or validating the whole input. Compare a direct sequence-based solution with a regex-based solution and explain which communicates the requirement more clearly.

Chapter 8 — Case Study: Word Play

Word-list problems combine file input, text processing, predicates, and systematic search. Tasks involving letter restrictions and alphabetical order show how a complicated question can be reduced to a smaller function that is easy to test. Separate reading the data, deciding whether one word qualifies, and collecting results. Try the decision function on a tiny hand-checked dataset before using a full list. The case study demonstrates reuse: solving a general problem once can make several apparently different exercises straightforward applications of the same logic.

Chapter 9 — Arrays and Lists

Collections extend programs beyond single values. The chapter distinguishes lists and mutable arrays, then develops traversal, insertion and removal, stacks, queues, sorting, multidimensional structures, and map/filter/reduce patterns. Trace which operations modify an existing array and which produce another collection. Compare a loop with a transformation pipeline that expresses the same task. When debugging, check the collection’s shape as well as its values: a nested structure or an unintended flattening can change the meaning of later operations even when the printed output initially looks plausible.

Chapter 10 — Hashes

Hashes map unique keys to values, making them useful for counters, lookups, memoization, and dispatch tables. They encourage thinking about a problem’s relationships rather than only its sequence of elements. The chapter also compares reverse lookup with ordinary key lookup and discusses scope and global variables. Implement a word-frequency task conceptually by identifying what the key represents and what each value stores. Explain what happens when a key is absent or repeated. Compare the hash solution with an array search in terms of clarity and expected work.

Chapter 11 — Choosing the Right Data Structure

This chapter brings together arrays, hashes, and compound structures through problems whose representations strongly influence the solution. Choosing how to store information can simplify later processing more than adding complicated control flow. Begin each exercise by listing the questions the program needs to answer, then select a structure that supports those questions naturally. Sketch a small example before coding. Explain how you will traverse, search, update, and display the data, and consider whether ordering, uniqueness, or grouping is part of the actual requirement.

Chapter 12 — Classes and Objects

Object-oriented programming groups related state and behavior through classes and objects. The chapter introduces the vocabulary needed to design and use these abstractions rather than passing loosely related values through every function. Identify what an object represents, which operations belong to it, and what conditions its state must satisfy. Compare a procedural solution with an object-based version of the same small problem. The aim is a clearer model and interface, not creating classes for their own sake. Test behavior through the public operations rather than depending on incidental internal representation.

Chapter 13 — Regexes and Grammars

The later treatment of text processing develops Raku’s pattern tools into more structured parsing. Grammars let related recognition rules describe nested or organized input more clearly than an oversized single pattern. Separate the syntax you want to recognize from the data you want to extract or compute. Build a progression of valid and invalid examples, including incomplete input and misleading near matches. Explain how smaller named rules contribute to the whole. This chapter connects language features with a general computer-science idea: making a formal structure explicit can improve both correctness and explanation.

Chapter 14 — Functional Programming

Functional techniques make functions and transformations central to program organization. The chapter extends earlier experience with higher-order operations, composition, and expressive collection processing. Compare a solution organized around changing variables with one organized around transforming values. Track where side effects occur, and judge the result by clarity as well as brevity. Rewrite a familiar exercise in a second style and explain the advantages and limitations of each. The purpose is to expand your problem-solving choices rather than treating one paradigm as universally superior.

Chapter 15 — Some Final Advice

The concluding advice returns to the habits that make continued learning possible: practice, decomposition, experimentation, reading code, and approaching difficulties systematically. Completing a language textbook is a beginning rather than proof of mastery. Review an early exercise and improve its names, structure, tests, and explanation using later concepts. Choose a modest independent project with a clear user and finish a small useful version. Document the assumptions and unresolved questions so future changes can be made deliberately rather than by trial and error.

Appendix — Solutions to the Exercises

The solutions appendix is an extension of the teaching, often showing alternative approaches and additional discussion. Attempt each problem before reading its solution, then compare the reasoning rather than only checking whether the outputs match. Reconstruct a solution without looking and explain why it works for boundary cases. Where multiple approaches appear, compare representation, decomposition, and readability. Keep a record of errors you understood and corrected; that record is stronger evidence of learning than a folder of copied examples that have never been changed.

Study instructions

  1. Read with a working Raku environment, entering and varying small examples rather than copying whole chapters at once.
  2. Before each run, write the expected output or state change; after it, explain any difference.
  3. Attempt exercises independently, then use the appendix to compare methods and rebuild a solution from memory.
  4. Keep a debugging journal organized by symptom, hypothesis, smallest experiment, and verified cause.
  5. Finish with a small text-processing project that uses functions, files, collections, clear interfaces, and boundary-case checks.

Questions for reflection

  • When does changing the data representation simplify the algorithm?
  • How do local scope and explicit return values improve reasoning about a program?
  • What is the difference between recognizing a text pattern and validating a complete input?
  • Which parts of your project are best expressed with iteration, objects, or functional transformations?

Sources and coverage

This original reading guide follows the linked source edition’s chapter, module, unit, or lesson structure. Consult the source for full arguments, cases, worked examples, exercises, illustrations, and references. Coverage follows Think Raku, second edition, version 0.6, January 2020. Older publisher links may use the former Think Perl 6 title. Read the source edition.

About access & copyright

This page provides book information and study material. Full-text access is provided by the original publisher or authorised source; a listing does not grant permission to republish the book.

Read our Library Access & Copyright policy

Explore the contents

Check the chapters covered in this edition.

Visit the official source

See reading, preview or purchase options.

Save for later

Keep this textbook in your saved collection.

Reader ratings & reviews

Be the first to rate

No ratings yet

0%0%
0%0%
0%0%
0%0%
0%0%

Share your thoughts

Your review helps other students choose the right resources.

Rate this book

How helpful was this book?No sign-up needed. Your rating appears instantly.