Pyret is a programming language designed to serve as an outstanding choice for programming education. It works effectively at many levels, with several curricula in active use incorporating Pyret. The language is under active design and development, and free to use or modify.
First Examples Curricula & Books (Course) Developers Major Features
flag = image-url("https://.../pyret-sticker-caps.png") blackout = rectangle(550, 425, "solid", "black") blank-flag = place-image(blackout, 450, 285, flag) bonnie = scale(0.75, image-url("https://.../pyret-logo.png")) fun draw-bonnie(angle :: Number) -> Image: scale(0.5, place-image(rotate(angle, bonnie), 450, 285, blank-flag)) end spinner = reactor: init: 0, on-tick: {(angle): angle + 5}, to-draw: draw-bonnie end spinner.interact()
Pyret is designed from the ground up to run entirely in regular browsers with no installation at all, avoiding frustrating student-hours lost to installers and platform choice and IDE configuration and more. Indeed, Pyret is running right on this very page – check out the examples with the “Run It!” buttons!
Programs that create images give immediate visual feedback. Functions that operate on images enable students to learn about function composition in an medium that is both engaging and educational.
treetop = triangle(60, "solid", "darkgreen") trunk = square(20, "solid", "brown") tree = above(treetop, trunk)
examples "cube function": cb(0) is 0 cb(3) is 27 cb(-5) is -125 end fun cb(n): n * n * n end
Pyret provides a pleasant syntax for writing illustrative examples of how functions should behave. These serve not only as documentation, but are also useful for students to demonstrate their understanding of a problem before they start programming.
Pyret's number system supports exact rational arithmetic for many operations. This avoids having floating point as a curricular dependency early on. When approximations become inevitable, they have an explicit representation: Roughnums.
for each(n from range(0, 10)): print(n) end squares = for map(n from range(0, 5)): n * n end # for filter, fold, and more!
The for
construct provides a familiar syntax for iterating
over elements, and much more.
Pyret provides modules, with a rich set of features to control where they are found and where they are exported. Starter or support code for assignments can be imported directly from services like Github.
import url("https://raw.githubusercontent.com/brownplt/pyret.org/...") as TTT X = TTT.X O = TTT.O Blank = TTT.Blank board-xox = TTT.board( [array: [array: X, Blank, Blank], [array: Blank, O, Blank], [array: Blank, Blank, X]]) TTT.draw-board(board-xox)
And much much more! Check out all the major features of Pyret!
For grades 6-12 (secondary) students, our partners at Bootstrap are the leading designers of integrated computing curricula. All the Bootstrap curricula build primarily atop Pyret. Bootstrap covers numerous areas (with ties to algebra, data science, AI, physics, and more) and provides comprehensive materials that have been tested in thousands of classrooms and by tens of thousands of students every year. Bootstrap is also, by design, modular: you don't have to adopt a whole course, but can instead choose modules that fit best with what you're already teaching. Head over to Bootstrap to learn more!
Our book, Data-Centric Introduction to Computing (DCIC), provides a modern introduction to computing education. You can see some of the research [1, 2, 3] that has driven its design and content.
DCIC takes the position that introductory data science offers an interesting, accessible, and meaningful introduction to programming that addresses many problems that plague current introductory curricula. It then transitions from that to data structures. You can read our critique that inspired the book. Pyret offers various features that support this introduction and transition.
In particular, DCIC takes the position — driven by a significant body of literature in educational and cognitive science — that students learn programming better when they can compare and contrast related but different things. Thus DCIC teaches not one but two programming languages: Python in addition to Pyret. But the progression from Pyret to Python is (a) staged carefully to minimize difficulties, and (b) includes seeing them side-by-side. Pyret, in turn, is designed to facilitate this kind of comparison with Python
Pyret has a Visual Studio Code extension that opens files in the same visual editor as the examples above. It works anywhere Visual Studio Code can run, including on github.dev. Read more in the docs.
Pyret has specific libraries and features for creating and deploying starter code for students seamlessly. We developed these features and workflows in our own courses, with our own TAs, and for our own curricula.
All the examples on this page embed an instance of Pyret through its
embedding
library.
You can embed Pyret on your own websites and projects by
installing that npm
package, which has an API for controlling and
listening to the embedded instance.
const code = `use context starter2024 dot = circle(50, 'solid', 'red')`; pyretEmbed.sendReset({ definitionsAtLastRun: code, interactionsSinceLastRun: ["dot"], editorContents: code, replContents: "" });
Pyret runs from the command line via the pyret-npm
package.
Nearly all libraries (including images) run the same offline and
in-browser. This can be especially important for grading student
code submissions in an automated way.