www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - [debate] About D's pretension for homoiconicicity

reply Justin Johansson <no spam.com> writes:
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
Oct 21 2010
next sibling parent reply Ellery Newcomer <ellery-newcomer utulsa.edu> writes:
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
Oct 21 2010
parent "Nick Sabalausky" <a a.a> writes:
"Ellery Newcomer" <ellery-newcomer utulsa.edu> wrote in message 
news:i9pnta$21d$1 digitalmars.com...
 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.
I'd love to see D do that (like Nemerle does), although I think the best time to do it would be after DDMD becomes the official DMD. That would eliminate a lot of extra work since the compiler's AST-related types could be made to double as part of the user API.
Oct 21 2010
prev sibling next sibling parent "Simen kjaeraas" <simen.kjaras gmail.com> writes:
Justin Johansson <no spam.com> wrote:

 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."
Hardly true. While it may be possible to Greenspun together a hacky attempt at homoiconicity in D, Doing so would bring but a few of the benefits compared to a language designed from the beginning with homoiconicity in mind. That said, some of the use cases for homoiconicity may be covered by D's capabilities, and this may be closer to what you intended by the above paragraph. Certainly D does not allow one to execute arbitrary strings as if they were D code (D does however allow the execution of arbitrary strings). There certainly are ways to do that, but such could be said for any language. It would certainly be possible to create a system for manipulating ASTs at compile time in D, be they generated by library code or the compiler itself. Converting such a representation to a mixin string should prove no big challenge. However, even such a system would likely lack the elegance of lisp's macros, and I find it unlikely it would find much use. Another problem with this is that it's useless at runtime, unless an interface to the compiler is offered as a library for D. This has been discussed numerous times, and I believe most on this list agree it would a Good Thing=E2=84=A2. -- = Simen
Oct 21 2010
prev sibling parent Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 10/21/10 9:51 CDT, 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
Heh, interesting. I don't think D can claim it's homoiconic in any close meaning of the term. In wake of the duck incident - if anyone on this group says so, naysayers will put it on News at 11. Andrei
Oct 21 2010