flâneur — a map of the web's best reading

Reading 19: Little Languages

web.mit.edu · 8,305 words · saved by 1 readers

In this reading we will begin to explore the design of a little language for constructing and manipulating music. Here’s the bottom line: when you need to solve a problem, instead of writing a program to solve just that one problem, build a language that can solve a range of related problems. The goal for this reading is to introduce the idea of representing code as data and familiarize you with an initial version of the music language. In the process, we will introduce the Visitor pattern, which is another example of treating functions as first-class values, and an alternative implementation strategy for operations on recursive data types. Visitors are a common feature of little languages implemented as recursive data types. Recall the Formula data type from Recursive Data Types: We used instances of Formula to take propositional logic formulas, e.g. (p ∧ q), and represent them in a data structure, e.g.: In the parlance of grammars and parsers, formulas are a language, and Formula is

Reading 19: Little Languages > hide Snapdown help Snapdown is a language for drawing snapshot diagrams. Click on the links below to see examples of Snapdown in action! In each example, you'll see a snippet of Snapdown syntax and the corresponding diagram side-by-side. Primitives (click to expand) In this example, we have two variables: i points to the value 5 , and s points to the value "abc" . i -> 5 s -> "abc" Objects (click to expand) In this example, f points to a MyFloat object with the value 5.0 , s points to a MyString object with the value "abc" . f -> (MyFloat 5.0) s -> (MyString "abc

Explore this link on the map →

saved by

related reading