<div dir="ltr"><div>2013/1/25 Jonathan M Davis <span dir="ltr"><<a href="mailto:jmdavisProg@gmx.com" target="_blank">jmdavisProg@gmx.com</a>></span><br></div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class="im">On Friday, January 25, 2013 11:09:15 kenji hara wrote:<br>
> That is more serious than (a). If we adopt this rule, we will *really*<br>
> get lost the way to distinguish property functions and raw data fields.<br>
> (Note that: In current typeof(foo) already returns int. So AddressExp is<br>
> only one way to getting (normal|property) function information by its<br>
> type.) From the view of meta-programming, I think this makes a serious flaw.<br>
<br>
</div>We could add a __trait which detected whether a field was an actual variable or<br>
not.</blockquote><div><br></div><div>OK, let's think.</div><div><br></div><div>When a property function exists:</div><div>@property int foo();</div><div><br></div><div>#1 Only check whether it is a property function or not.</div>
static assert(__traits(isProperty, foo) == true);</div><div class="gmail_quote"><div class="gmail_extra">Pros: We can get minimum information.</div><div class="gmail_extra">Cons: We cannot check whether the foo is other function attributes: pure, nothrow, @safe.</div>
<div class="gmail_extra"><br><div>#2 Returns a type from __traits.</div>static assert(__traits(getPropertyType, foo).stringof == "@property int()");</div><div class="gmail_extra">Pros: We can access all information about property function.</div>
<div class="gmail_extra">Cons: __traits() is parsed as an expression, so we cannot use it as a type directly.</div><div class="gmail_extra"> __traits(getPropertyType, foo)* fp; // declaring function pointer</div><div class="gmail_extra">
Instead, some template should be required.</div><div class="gmail_extra"> TypeTuple!(__traits(getPropertyType, foo))[0]* fp;</div><div class="gmail_extra"><br></div><div class="gmail_extra">#3 Adding a special case in CastExpression</div>
<div class="gmail_extra">auto fp = &foo; // Not allowed, because property function foo returns an rvalue.<br></div><div class="gmail_extra">auto fp = cast(function)&foo; //New, Gets a function pointer of foo</div>
<div class="gmail_extra">Pros1: Can access fully information of foo from typeof(fp).</div><div class="gmail_extra">Pros2: We can call a property function indirectly through function pointer.</div><div class="gmail_extra">
Pros3: Newly syntax and semantics has no conflict with existings.<br></div><div class="gmail_extra">Cons: cast(function) and cast(delegete) necessary.</div><div class="gmail_extra"><br></div><div class="gmail_extra">#4 An extension from #3</div>
<div class="gmail_extra">auto p = cast(@property)&foo; // p is a function pointer.</div><div class="gmail_extra">auto p = cast(@property)&s.foo; // p is a delegate.<br></div><div class="gmail_extra">Pros: Only one new syntax is necessary.</div>
<div class="gmail_extra">Cons: Ugly...</div><div class="gmail_extra"><br></div><div class="gmail_extra">---</div><div class="gmail_extra"><br class="">In basic, I don't like adding new __traits for this purpose, like #1 and #2.</div>
<div class="gmail_extra">In the compile world of D, a function type is already a first class object to carry the information related function. Similarly, function pointer and delegate are widely used as a runtime container to make runtime bindings to function symbols.</div>
<div class="gmail_extra">From these facts, creating an escape hatch from property function to normal function type/pointer is enough worthwhile to me. It makes it possible to reuse a number of meta-programming operations for normal function/function type/function pointers.</div>
<div class="gmail_extra"><br></div><div class="gmail_extra">#3 and #4 are comes from an existing feature, which picking up one from overloaded functions by CastExpression.</div><div class="gmail_extra">void foo() {}</div>
<div class="gmail_extra">void foo(int) {}</div><div class="gmail_extra">auto fp = cast(void function())&foo; <br></div><div class="gmail_extra">// fp is equal to the address of first foo.</div><div class="gmail_extra">
<br></div><div class="gmail_extra">So, I prefer adding newly meanings to CastExp.</div><div class="gmail_extra"><br></div><div class="gmail_extra">Kenji Hara</div></div></div></div>