On 2012-03-19 22:00, Andrei Alexandrescu wrote:

I salute creative uses of the language over defining new features.

Andrei

The actual point of user defined attributes it to be able to create domain specific attributes so we don't have to add new features to the language. This is also to have a sane syntax for the attributes.

I think in several cases D could have chose to implement a more general feature but instead implemented a very specific feature or hack.

Example:

If D supported passing delegates to a function after the function call several language features could have been implemented in the library instead.

void synchronized (void delegate () dg)
{
    try
    {
        lock();
        dg();
    }
    finally
        unlock();
}

synchronized {
    // do something
}

In the same way foreach can be implemented in a library function:

void foreach (T) (T[] arr, void delegate (T) dg)
{
    for (size_t i = 0; i < arr.length; i++)
        dg(arr[i]);
}

auto arr = [3, 4, 5];

foreach (arr ; e // this is the parameter to the delegate) {
    writeln(e);
}

--
/Jacob Carlborg

Reply via email to