Can you do this in D?

Jacob Carlborg doob at me.com
Thu Jul 26 23:50:51 PDT 2012


On 2012-07-27 03:18, Wes wrote:

> 4. It doesn't have a simple prettyprint operator. I think .stringof is a
> big step forward from .ToString() for simplicity, but obviously
> $variable would be more terse.

.stringof is not the equivalent to .ToString(). .stringof is more of a 
compile time language feature. It turns an expression into a string:

import std.stdio;

void main ()
{
     string foo = "bar";
     writeln(foo.stringof);
     writeln((3 + 4).stringof);
}

The above code will print:

foo
3 + 4

The equivalent to .ToString() in D would be .toString() or 
to!(string)(variable).

> 5. It doesn't have a way to iterate over every id in scope.
> I can't think of a good reason to do this anyway.

There could be a couple of reasons for doing this. For example creating 
a DSL.

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list