DIP64: Attribute Cleanup

H. S. Teoh via Digitalmars-d digitalmars-d at puremagic.com
Fri Jun 20 12:47:07 PDT 2014


On Fri, Jun 20, 2014 at 07:22:02PM +0000, Brian Schott via Digitalmars-d wrote:
> http://wiki.dlang.org/DIP64
> 
> Attributes in D have two problems:
> 1. There are too many of them and declarations are getting too verbose
> 2. New attributes use @ and the old ones do not.
> 
> I've created a DIP to address these issues.

And while we're at it, why not also fix holes in attribute semantics on
top of just fixing syntax?

First, there is no way to mark a function as *impure* as opposed to pure
(leaving out "pure" is not an option in template functions due to
automatic attribute inference). Also, there's an inconsistency between
positive attributes (pure, safe) vs. negative attributes (nothrow,
nogc). So ideally, the new syntax should allow you to specify both pure
and impure, and ideally, it should not special-case on peculiarities of
the English language (pure/impure vs. throw/nothrow). So it should be
something like @pure, @!pure, @throw, @!throw, @gc, @!gc, etc., for
maximum consistency.

I also like your attribute sets idea. This could be the solution we're
looking for with transitive attributes (aka inout(pure), inout(nothrow),
etc.). If there was some syntax for attribute set intersection, say
@a*@b, then we could specify that the attribute set of some given
function f() is the intersection of the attribute sets of its input
delegates. For example:

	// This is hypothetical syntax, I'm sure you can think of a
	// better way to write this.
	int dgCaller(int delegate(int) @a dg1, int delegate(int) @b dg2)
		@this = @a*@b // specifies that this function's
			      // attributes is the intersection of @a and @b
	{
		if (someCondition)
			return dg1(1);
		else
			return dg2(2);
	}


T

-- 
Heads I win, tails you lose.


More information about the Digitalmars-d mailing list