A new Swift video series exploring functional programming and more.
#26 • Monday Aug 20, 2018 • Subscriber-only

Domain Specific Languages: Part 1

We interact with domain specific languages on a daily basis, but what does it take to build your own? After introducing the topic, we will begin building a toy example directly in Swift, which will set the foundation for a future DSL with far-reaching applications.

#26 • Monday Aug 20, 2018 • Subscriber-only

Domain Specific Languages: Part 1

We interact with domain specific languages on a daily basis, but what does it take to build your own? After introducing the topic, we will begin building a toy example directly in Swift, which will set the foundation for a future DSL with far-reaching applications.


Subscribe to Point‑Free

This episode is for subscribers only. To access it, and all past and future episodes, become a subscriber today!

See subscription optionsorLog in

Sign up for our weekly newsletter to be notified of new episodes, and unlock access to any subscriber-only episode of your choosing!

Sign up for free episode


Exercises

  1. Improve the simplify function to also recognize the following patterns:

    • Factorize the c out of this expression: a * c + b * c.
    • Reduce 1 * a and a * 1 to just a.
    • Reduce 0 * a and a * 0 to just 0.
    • Reduce 0 + a and a + 0 to just a.
    • Are there any other simplification patterns you know of that you could implement?
  2. Enhance Expr to allow for any number of variables. The eval implementation will need to change to allow passing values in for all of the variables introduced.

  3. Implement infix operators * and + to work on Expr to get rid of the .add and .mul annotations.

  4. Implement a function varCount: (Expr) -> Int that counts the number of .var’s used in an expression.

  5. Write a pretty printer for Expr that adds a new line and indentation when printing the sub-expressions inside .add and .mul.

Chapters
Introduction
00:05
Definitions
00:42
An arithmetic expression DSL
03:30
Adding multiplication to our DSL
09:38
Transforming our DSL
12:02
Adding a variable to our DSL
19:13
To be continued…
22:31
Credits

Hosted by Brandon Williams and Stephen Celis. Recorded in Brooklyn, NY.