Metacode mechanics

Don Clugston dac at nospam.com.au
Tue Feb 28 07:27:24 PST 2006


David Medlock wrote:
> Georg Wrede wrote:
> 
> <snip>
>> So I suggest that we:
>>
>>  - continue developing the current D metalanguage
>>  - continue to have both Don's and Phobos' regexps
>>  - in this NG start the development of requirements for KBDM
>>
>> KBDM being Kick-Butt D Metalanguage. :-)
> 
> This is a very good idea, as code-which-generates-code is the heart of 
> some powerful techniques(Lisp/Scheme macros among them).
> 
> To make them truly work however one of the following is really needed:
> 
> 1. Runtime evaluation, as in scripting type languages.  In this case all 
> you need is a function which returns a string.
> 
> 2. A _uniform_ way to represent all the constructs of the language. This 
> works in Lisp because everything is a List(actually a CONS cell), and 
> you can simply walk the tree checking for symbols and generating code as 
> needed.

I'm sure that compile time reflection is the way to go.
We already have the .mangleof property, which maps any type to a string. 
Once we get array literals, you could have an array of strings showing 
all members of a given item.
eg a property
char [][] .membersof
which is valid for any type.

Then with __identifier(char []) you could walk the syntax tree.

Somewhat lacking in syntactic sugar, and doesn't deal with control 
structures, but it gets you to most of the interesting stuff.

I've already written templates that do:
char [] qualifiednameof!(alias x)
char [] symbolnameof!(alias x)
which work for any variable, function, type or module x,
and as a side-effect, you get loads of type info. I don't think too many 
additions would be required to make everything possible. But, you'd 
certainly want some simplified syntax.

> D is much simpler than C++, I will agree wholeheartedly. However, I fear 
> that such a language strapped on to D would be rife with kludges to 
> accomodate its (relatively)complex syntax.
> 
> Cheers.
> -DavidM



More information about the Digitalmars-d-dtl mailing list