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
Today we are going to talk about a concept known as “domain specific languages”, and in particular “embedded domain specific languages”. It may sound like a jargony term, but it’s something that you have definitely come across and you may even use it on a daily basis.
After giving the upfront definitions so that we all understand what a domain specific language is, we will create one right in Swift and progressively add more and more advanced features to it. It’s a toy example, but it contains a lot of the core ideas and it can be a lot of fun to play with.
simplify function to also recognize the following patterns:
cout of this expression:
a * c + b * c.
1 * aand
a * 1to just
0 * aand
a * 0to just
0 + aand
a + 0to just
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.
Implement infix operators
+ to work on
Expr to get rid of the
Implement a function
varCount: (Expr) -> Int that counts the number of
.var’s used in an expression.
Write a pretty printer for
Expr that adds a new line and indentation when printing the sub-expressions