Crafting Interpreters · Week 11

Ch 13: Inheritance

Updated

About 5 hoursVerified by tests

Summary

Crafting Interpreters chapter 13, Inheritance: Single inheritance: superclass declarations, method lookup through the chain, and super calls, finishing jlox. Budget about 5 hours; the book's chap13_inheritance tests check your code.

Flashcards 6 cards for Anki and AnkiMobile · all decks

Anki deck.tsv

This week's steps

4 steps
  1. Read the chapter

    Implement, then run the full jlox test suite.

  2. Write the code in your lox repo

    Type it into jlox/ (Java) yourself as you read, and get it running.

  3. Do the challenges (1–3)

    Challenge 3 (implement a feature you listed back in chapter 3) is the most rewarding.

  4. Push and let the tests verify it

    Your repo runs the book's chap13_inheritance tests on every push; passing marks this done.

Sign in to track this: tick each step off and it counts toward your week.

Try it in the browser

Optional

jlox as it stands at the end of chapter 13: what this chapter adds works, and anything from a later chapter is the error your own jlox would give. Compare its output with yours. The full playground

Chapter 13: Inheritance

All of jlox: statements, control flow, functions, closures, classes and inheritance.

Output
Run the code to see what it prints.

jlox from Crafting Interpreters by Robert Nystrom, ported to TypeScript (MIT).

Your notes

Only you

Sign in to keep private notes on this guide, in Markdown. They stay yours: never on your profile, and you can export them all.

Discussion

0 posts

Questions about this chapter, tips, and what tripped you up. Hints over answers: full solutions go in a spoiler.

No posts yet. Ask a question or share a tip.

Sign in to postAnyone can read. Posting needs an account with a confirmed email.

Reference

Why it matters

Method resolution order and super are how every OO language reuses code. Finishing jlox is a real milestone.

How to approach it

Implement, then run the full jlox test suite. Celebrate, then take a day before starting C.

Challenges

3 challenges at the end of the chapter.

Challenge 3 (implement a feature you listed back in chapter 3) is the most rewarding. Challenge 2 (BETA-style inner) comes back in chapter 29, so if you skip it now, expect to meet it again. Do challenges that change Lox's behavior on a separate git branch. The cracked.guide check runs the official test suite for this chapter, and a challenge that changes semantics (new syntax, different errors) can make tests fail on main.

Common traps
  • A class inheriting from itself: make sure it is an error.
  • super lookups must use the superclass of the class where the method was defined, not of the instance.

Spot a mistake? Report it

Back to week 11