Domain-specific language pattern

Julia is a general purpose programming language that can be used effectively for any domain problem. However, Julia is also one of the few programming languages that allows the developer to build new syntax to fit a specific domain usage.

So, a DSL is an example of Structured Query Language (SQL). SQL is designed to process data in a two-dimensional table structure. It is very powerful, and yet it is only appropriate when you need to handle data in tables.

There are a few prominent areas in the Julia ecosystem where a DSL is used extensively. The one that stood out the most is the DifferentialEquations package, which allows you to write differential equations in a form that is very close to their original mathematical notation. For example, consider the Lorenz system equations as follows:

The code to define these equations can be written as follows:

@ode_def begin
dx = σ * (y - x)
dy = x * (ρ - z) - y
dz = x * y - β * z
end σ ρ β

As we can see, the syntax almost matches with the mathematical equations.

After this, in the next section, we will explore how to build our own DSL for a practical use case in computer graphics called L-System.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.174.156