D and the world

Jari-Matti Mäkelä jmjmak at utu.fi.invalid
Wed Apr 25 15:00:44 PDT 2007


eao197 kirjoitti:
> On Thu, 26 Apr 2007 00:12:19 +0400, Jari-Matti Mäkelä
> <jmjmak at utu.fi.invalid> wrote:
> 
>> eao197 wrote:
>>> On Wed, 25 Apr 2007 23:23:52 +0400, "Jari-Matti Ma"kela""
>>>>> (for example it is possible to open and read files in compile-time,
>>>
>>>> Well, this is possible in D now too.
>>>
>>> May be I miss something. How to do this in D in compile-time?
>>
>> It doesn't implement full I/O, but you can do some stuff with import
>> expressions. Some operating systems (Plan9) are heavily file oriented so
>> it can help a lot. Of course importing regular files is possible in
>> other systems too. Was this what you were looking for?
> 
> I know about the import expression, but I speak about different kind of
> file processing. For example:
> 1) open a x.503 certificate file during compilation, checking it and
> importing a public key from it into a program as byte array;
> 2) open a WSDL file, parsing it and generating stubs or skeletons for
> the described WebService;
> and so on.

> I think I need to describe my own point of view. There isn't need to
> support such DSL via some special language features (like more powerful
> CTFE or syntax extension). All these tasks can be done by external code
> generation tools and the import expression is enough.
> 
> But external code generation has its own drawbacks. It needs external
> software installed, it cannot be used in foreign compile farms (or usage
> may be limited), it needs more advanced build tools.
> 
> However there are other kinds of DSL which require more advanced CTFE
> and, may be, some macro system (like samples from Don Clugston).
> 
> At now I just want to understand what kinds of DSL can be handled by
> different techniques (CTFE and mixins, macros, external code generation
> and so on).
> 

Yeah, I follow you. Simple text imports can be done with the import
expression, but if you need more processing functionality, it can be
done with D without need for external tools. Actually it's quite simple,
you just need to create a custom parser for a DSL. Something like

const char[] file = "foo.bar";

char[] parseX503File(char[] data) {
        return data[1..$-1]; // or something more interesting
}

const certificate = parseX503File(import(file));

void main() {
	setServerCertificate(certificate);
}

This could be done with much cleaner code too, but DMD has now several
bugs in type inference.

CTFE and templates are already Turing complete so you won't get much
more with additional macro features. They can only simplify the syntax
and common idioms. But yes, it has been exciting following the evolution
of metaprogramming features in D. I really don't know what's ahead,
hopefully something that makes EDSLs a piece of cake for everyday coders.


> --Regards,
> Yauheni Akhotnikau



More information about the Digitalmars-d mailing list