[debate] About D's pretension for homoiconicicity

Ellery Newcomer ellery-newcomer at utulsa.edu
Thu Oct 21 08:58:15 PDT 2010


Doo de doo.. *google homoiconic*... program representation is data 
structure of primitive type of language or somesuch

Hm.

templates are advance metaprogramming capabilities, string mixins are 
quite primitive, and ctfe is too immature to say one way or the other.

In my mind, the advantage of a homoiconic language is not so much the 
ability to generate code (though it is pain when your language doesn't 
have that) as it is the ability to manipulate code. First, that 
presupposes a real data structure which can be manipulated. Second, 
since your code is represented the same way as any other data, your meta 
programming code isn't any different from other code. Two strengths: 1) 
you're working with the language; given the operators and syntactic 
support your meta programming should be fairly eloquent. 2) you get to 
use the same libraries as you do for everything else.

You can probably see where I'm going.

Strings are an able medium for generating code. They're pretty 
fundamental and generating code-as-string is a snap. However, once you 
have that string, you really can't do anything with it except pass it to 
the compiler. You can't even insert or replace some piece of code with 
another (with special cases you can, but special cases are fragile and 
break quickly whenever you want to do something slightly different). 
This limits how you can perform string generation. Whereas with 
templates, you see the top level code with some small pieces which get 
customized, with string generation you have to generate those small 
pieces first, and then progressively concatenate things around them. In 
terms of string operations, that may be eloquent, but in terms of code, 
it is rather unreadable.

Then there's the fact that the compiler doesn't represent code as 
strings. If the compiler exposed the AST, all this might be less of an 
issue. ASTs aren't a primitive type, but D's library capabilities are 
strong enough that you might be able to design an AST such that AST 
manipulation doesn't suck as much as in other c-style languages. It 
wouldn't be much more readable than string generation, though.

At best, its an implementation issue, as is ctfe (unless something's 
changed recently, you can't program ctfe in idiomatic D. bad.)

In short, D isn't there yet.

On 10/21/2010 09:51 AM, Justin Johansson wrote:
> Nothing about this subject line is purported to be
> true or false or otherwise conjectured; the subject is
> simply proposed as a topic for debate.
>
> The formal subject proposed for debate is
> "D's advanced meta-programming capabilities essentially
> makes it (D) as if it were a homoiconic language, and
> brings with it all the advantages of homoiconic languages."
>
> Hoping this is a nice topic for all to enjoy and to participate in.
>
> Cheers
> Justin Johansson


More information about the Digitalmars-d mailing list