Archive for the ‘D Programming’ Category

const(FAQ)

Saturday, March 29th, 2008

Even more on constness. Walter has put up a FAQ to help clarify the D2 const regime. Bookmark it. It’s bound to grow over the coming months.

Technorati Tags: ,

Walter on const

Friday, March 28th, 2008

One of the most confusing aspects of D 2.0 is the const regime, the keywords and concepts involved in supporting read-only and immutable data. The basic premise of this system in 2.0 is that no language has yet gotten it right, including C++ and even D 1.0. I’ve not touched D2 yet and the discussions of const and friends in the NG have left my head spinning on more than one occasion.

Walter recently responded to a post on the NG with some insightful comments on the const regime in D2. His post doesn’t serve to explain the mechanics of the system to those who don’t understand it, but does explain the problems of implementing it and the reasons why it needs to be implemented correctly. I admit to being one of those Walter mentions in the post who have come to believe “const is bad” after all of the mess surrounding its implementation. After reading it, though, I’m inclined to give const a chance. If you are in the same boat, I recommend you give it a read as well.

This topic is certainly a good candidate for a post on Walter’s blog. Might we see one soon?

Technorati Tags: ,

Why D Got Const

Monday, January 7th, 2008

If you’ve ever wondered why Walter added const to D in 2.0, he has added an entry to the FAQ with two items explaining why. The second item gives a bit of insight into D’s future, for the curious.

Technorati Tags:

A Book About D and Tango

Wednesday, December 5th, 2007

We were hoping to keep this under the radar for a little bit longer, but thanks to comments in a post at reddit the cat is already out of the bag. A couple of times on this blog I’ve mentioned, in passing, a project I was involved in but didn’t give any details about it. Kris Bell, Lars Ivar Igesund, Sean Kelly, and myself have been collaborating over the past few months on a book to be published by Apress, Learn to Tango with D.

The book is part of an Apress series called firstPress. Books in this series are rather short and serve as an introduction to  and overview of emerging tech. Successful firstPress books potentially open the door for more in-depth books to be published by Apress down the road. We had a limited budget of pages to squeeze everything into, so much of the book is a fairly rapid, high-level view of what D and Tango are all about. We did, though, meet the primary goal of introducing both D and Tango and went into enough detail to get newcomers started.

We hadn’t announced the book yet for a couple of reasons. First, while it has been available for preorder on both the Apress site and Amazon for some time, we were wanting to get the information describing the book, and the author histories, updated first. That hasn’t happened quite yet, though it is in the pipe. Secondly, the book was originally scheduled for publication in December as both pages indicate, but a few weeks ago publication was pushed back to early 2008. We haven’t yet gotten a firm date, so we wanted to have that before saying anything about it. larsivi had wanted to announce at the D Conference, but the lack of a date was why he didn’t.

Walter wrote the foreward and Don Clugston was our technical reviewer. There are a total of eight chapters, each author having contributed two. The first half of the book covers D and the second half Tango. Personally, I’m quite happy with the result. With each of us being first time authors, it’s been quite the learning experience. The people at Apress have been great in putting up with us. In hindsight, I can think of a handful of things I wish I had mentioned in my chapter on the basics of D, but it’s already the longest chapter in the book!

I hope the book will be on the shelves in January, but that’s not for me to say. As soon as I get a firm date, I’ll be sure to post it here. In the meantime, you can preorder Learn to Tango With D from Amazon at a discount off of the list price. I should also mention that all of the authors agreed to donate all royalties from Apress to the Tango project, so purchases will ultimately benefit the project directly (though, that doesn’t apply to anything I make from Amazon when you purchase through the link above ;) ).

I’ll post any news related to the book here as I get it. I’ve added a new tag so that you can easily find updates about it. The editing process is ongoing, so I’ll wait until I’m certain about the final chapter titles and such before posting a TOC.

Technorati Tags: , ,

Don Clugston’s Compile-Time SyntaxTree

Wednesday, September 12th, 2007

Don Clugston, the D community’s resident CTFE guru, has put his considerable talent to work in order to create a module which performs lexing, parsing, and semantic analysis on D expressions at compile-time. This is mind-boggling stuff. What’s more, he did it in under 300 lines of code. From the NG announcement:

contains one publicly usable function:

char [] syntaxtreeof(char [] expression).

When mixed in, this lexes and parses the expression, determines precedence and associativity, creating an object of type AbstractSyntaxTree, which contains a standardized ‘placeholder expression’ (eg “A+=(B*C)”)
and a symbol table for the variables, constants and functions A,B,C,…
The symbol table includes the type and value for each symbol.
All aliases and compile-time constants are resolved and converted to a standard form.
All symbols must be reachable from the scope where syntaxtreeof() is mixed into.

The created AbstractSyntaxTree is a compile-time constant, so it can be used for further compile-time operations and code generation.

Works for almost any expression (templates, functions, strings, slicing, struct literals,…); the biggest omission is relational operators.

And example usage:

import SyntaxTree;

const foo = “abc”;
int bar(real x, char [] s) { return 0; }
struct Duck{};
Duck duck;

AbstractSyntaxTree a = mixin(syntaxtreeof(`foo* bar(2.18_3242e+45L, “xyz”) in duck`));

I guess there’s a reason that the first letter in Don is ‘D’.

Technorati Tags: ,