5

The webpage of Converge states that:

Converge has a macro-like facility that can embed domain specific languages with arbitrary syntaxes into source files.

I am most intrigued by the possibility to create domain specific languages. My understanding of the purpose of such languages, is that they enables the developer to become much more efficient when solving domain specific problems.

So, I went on to read the "about" section. There are two examples of usage here, but none of them describe how the developer could save development-time by utilizing Converge. Can anyone come up with an example or refer me to an example? I am happy to read examples in other languages than Converge.

2 Answers 2

2

I can't speak specifically of Converge, but I regularly use the D Programming Language which has very strong meta-programming features.

Here's an example of D library for units of measurement. The programmer can write:

auto dist1 = Meters(5.2);
auto velocity = dist1 / Seconds(2.1);
auto kmPerSecond = cast(Kilometers)velocity;

By using the type-system to create a DSL, the programmer is freed from juggling unit conversions and ensuring that operations make sense (e.g. time + distance would be an error).

Another (old) D example is the Blade library. This library is capable of parsing algebraic expressions at compile-time and generating very precise, fast assembly. For a programming who needs the speed, this sort of thing is a real life-saver.

Finally, check out Ruby on Rails if you haven't already. The whole thing is a giant DSL, though not a compile-time one.

2
  • Can you really cast velocity to Kilometers? Commented Jan 17, 2012 at 16:24
  • Whoops, nope. I meant to show off the automatic unit conversion.
    – user45121
    Commented Jan 18, 2012 at 0:41
4

There are two canonical examples of domain specific languages:

  1. Regular expressions. They are simple language, but language nevertheless and they are compiled to the actual search automaton, so definitely benefit from compiler handling them. Other parsing languages like BNF are similar case.
  2. SQL. While this is normally compiled in the database server and so does not benefit from processing in the compiler this way, there is a huge benefit in support for it from the language if it can automatically bind variables for parameters and results.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.