This example handles another important example of DSL use-case.
Making things very simple, symbolic operations are used when we want to manipulate expressions like
xy(z - 5), differentiate them wrt. to
z, evaluate and substitute other expressions for the symbols
Again, the basis of the DSL are specific classes the implementations of which we are going to skip.
The first is
class symbol that denotes a single "unit" of an expression, like an
x, the other is
class expr which may hold any symbolic expression ranging from values like
0.5, through symbols
x to complex expressions like
xy(z - 5).
The main characteristic of the
symbol class is that its instances are uniquely identifiable by their names.
It may be thought of as a string with some special features.