Example of Rust code

Walter Bright newshound2 at digitalmars.com
Fri Aug 10 17:59:37 PDT 2012


On 8/10/2012 5:19 PM, David Piepgrass wrote:
> Your version is basically a very long-winded way to say "auto x = 5 - (3 + 1);"
> so it really has nothing to do with the example.
>
> The point of the example was to represent a simple AST and store it on the
> stack, not to represent + and - operators as plus() and minus() functions.

I see that now, and I presented a D way of doing it using "expression 
templates", a technique pioneered by C++ programmers.

Expression templates have been used before in D, in particular to implement a 
regular expression engine. Dmitry Olshansky has since shown how fantastic this 
is for generating incredibly fast regex engines.

As far as I know, only C++ and D have sufficiently powerful abstraction 
mechanisms to make this possible.


> Really? And here I genuinely thought D was good enough for all the things C and
> FORTRAN are used for.

If you're going to write C code, use a C compiler. It's possible to use D as a C 
compiler, but kinda pointless except as a transitory state towards using D 
capabilities.


> I hope someday to have a programming system whose features are not limited to
> whatever features the language designers saw fit to include -- a language where
> the users can add their own features, all the while maintaining "native
> efficiency" like D. That language would potentially allow Rust-like code, D-like
> code, Ruby-like code and even ugly C-like code.
>
> I guess you don't want to be the one to kickstart that PL. I've been planning to
> do it myself, but so far the task seems just too big for one person.

Andrei originally proposed to me a language like that. I talked him out of it :-)



More information about the Digitalmars-d mailing list