Reading 19: Little Languages
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
- Reading 11: Recursive Data Typesweb.mit.edu
- Reading 12: Regular Expressions & Grammarsweb.mit.edu
- Problem Set 3: Memelyweb.mit.edu
- Reading 13: Map, Filter, Reduceweb.mit.edu
- Representing Code · Crafting Interpreterscraftinginterpreters.com
- how I think when I think about programming - alice mazalicemaz.com
- Learnable Programmingworrydream.com
- Lambda calculus - Wikipediaen.wikipedia.org
- adventures in uncertainty: An Introduction to Recursion Schemesblog.sumtypeofway.com
- Design Patternsgrantslatton.com
- 4 A First Taste of Desugaringcs.brown.edu
- Creating a DSL In Python - DEV Communitydev.to