Domain Specific Languages in D; was: C++, D: Dinosaurs?

Julio César Carrascal Urquijo jcarrascal at gmail.com
Tue Nov 4 06:27:08 PST 2008


Hello Aarti_pl,

> 3. Impossibility to statically control meta language contructs.
> 
> Sql has its own syntax rules and currently they can not be enforced on
> compile time.
> 
> E.g. in select statement you would expect to have OrderBy after Where,
> not other way.

Instead of returning the full query object you could return a "Fragment" 
query. Something like this:

class WhereFragment
{
    this(Query q) {}
    WhereFragment And(Expression e) {}
    OrderByFragment OrderBy(Column[] columns) {}
}


>Currently I can enforce order of clauses only on
> runtime, although it should be probably doable to enforce it on
> compile time. Currently it is also not possible to enforce that e.g.
> some method must be called:
>
> Query query = Select(id).From(table);
> 
> Imagine that you want to enforce that in above query From() must be
> always called (Select is an object, From is method on this object).

You should probably do as LINQ to SQL and start the query with the FROM statement 
instead. That way you can cascade the type and help auto-complete in IDEs. 
But yes, I don't think it's currently possible to enforce a method to be 
called.





More information about the Digitalmars-d mailing list