Re: How is D doing?
On Tuesday, 22 December 2015 at 11:42:42 UTC, bachmeier wrote: 1. Downloads of the DMD compiler have been fluctuating between 1000 and 1600 per day: http://erdani.com/d/downloads.daily.png To this you can add 75dl per day for ldc: http://www.somsubhra.com/github-release-stats/?username=ldc-developers=ldc They'll reach 60K (overlall) this week.
Re: Is it possible to use an UDA to generate a struct inside a class ?
On Tuesday, 30 December 2014 at 19:18:41 UTC, Basile Burg wrote: On Tuesday, 30 December 2014 at 19:05:23 UTC, Ali Çehreli wrote: On 12/30/2014 09:42 AM, Basile Burg wrote: Ok, thx. I see the trick: mixin (propertyInjections!C); Introspection inside each class. I don't find this solution ugly btw. I think there is no other way to do this. i've chosen another way to do that but it unleashes an ICE (every compiler crash is an ICE right ?), not tested on trunk: http://dpaste.dzfl.pl/70ab707b21e4 e.g I try to get the getter delegate in order to set a new izPropDescriptor in an AA.
Re: Is it possible to use an UDA to generate a struct inside a class ?
On Thursday, 1 January 2015 at 21:15:27 UTC, Ali Çehreli wrote: On 01/01/2015 09:35 AM, Basile Burg wrote: On Tuesday, 30 December 2014 at 19:18:41 UTC, Basile Burg wrote: an ICE (every compiler crash is an ICE right ?), Yes, the compiler should never crash but produce an error message. Please report it preferably with a reduced code sample: The report is filed. I was not sure of its validity or if it could be a dup. - You realize, all of those foreach'es are processed at compile-time for code generation. There will be no 'o' at run time; so its address cannot be used. Instead, Can I get the *relative offset* of a particular member at compile-time ? Then at run-time I could easily define the delegate, eg: // the AA or some arrays filled at compile-time ptrdiff_t[string] gettersOffset; ptrdiff_t[string] settersOffset; // a delegate, set at run-time, for example in this(). myDelegate.funcptr = gettersOffset[propIdentifier]; myDelegate.ptr = cast(void*) this; If so then the problem is solved...even if other problems could appends, for example if the methods are final, if they are inlined... Actually I'd be surprised that nobody has already designed something similar for properties (kind of published attribute as defined in Pascal-like languages.)
Is it possible to use an UDA to generate a struct inside a class ?
I have a struct used to describe a property[1]. Its standard usage is represented in this simple example: |class Bar { |private uint fField0; |private izPropDescriptor!uint descrField0; |this() { |descrField0.define(field0, field0, field0); |} |public void field0(uint aValue) {fField0 = aValue;} |public uint field0(){return fField0;} |} The descriptor is used by a property binding system or a serializer. The problem is that declaring a property descriptor is **very** repetitive. I've always wanted to find a way to generate a descriptor automatically, and finally today, while reading some random things on GH, I've found that the annotation system used in HibernateD[2] could be used. So far I didnt get the point of UDA and never used them. So I've created a basic UDA but, and then ? Can a descriptor be created using my attribute ? How ? |struct Setter { |const char[] propertyName; |} |struct Getter { |const char[] propertyName; |} |class Foo { |private uint fField0; |public @Setter(field0) void field0(uint aValue) { |fField0 = aValue; |} |public @Getter(field0) uint field0(){ |return fField0; |} |} [1]:https://github.com/BBasile/Iz/blob/master/import/iz/properties.d#L27 [2]:https://github.com/buggins/hibernated/blob/master/source/hibernated/annotations.d#L15
Re: Is it possible to use an UDA to generate a struct inside a class ?
On Tuesday, 30 December 2014 at 19:05:23 UTC, Ali Çehreli wrote: On 12/30/2014 09:42 AM, Basile Burg wrote: Can a descriptor be created using my attribute ? How ? Here is a quick and dirty solution: import std.string; struct PropertyDescriptor { string type; string name; string memberName() @property const { return name ~ _; } string definition() @property const { return format(%s %s;, type, memberName); } string getter() @property const { return format(%s %s() @property const { return %s; }, type, name, memberName); } string setter() @property const { return format(void %s(%s value) @property { %s = value; }, name, type, memberName); } } unittest { const descr = PropertyDescriptor(int, foo); assert(descr.memberName == foo_); assert(descr.definition == q{int foo_;}); assert(descr.getter == q{int foo() @property const { return foo_; }}); assert(descr.setter == q{void foo(int value) @property { foo_ = value; }}); } struct Property { PropertyDescriptor[] properties; string propertyCode() @property const { string result; foreach (property; properties) { result ~= property.definition ~ property.getter ~ property.setter; } return result; } } string propertyInjections(T)() { string result; foreach (attr; __traits(getAttributes, T)) { static if (is (typeof(attr) == Property)) { result ~= attr.propertyCode; } } return result; } @Property([ PropertyDescriptor(int, i), PropertyDescriptor(double, d) ]) class C { mixin (propertyInjections!C); } void main() { auto c = new C(); c.i = 42; assert(c.i == 42); } Ali Ok, thx. I see the trick: mixin (propertyInjections!C); Introspection inside each class. I don't find this solution ugly btw. I think there is no other way to do this.
Re: alias overloaded function template
On Tuesday, 11 November 2014 at 19:36:12 UTC, Lemonfiend wrote: D is fine with alias this overloaded function: --- void foo(int t) {} void foo(int t, int i) {} alias bar = foo; --- But isn't as happy aliasing these function templates: --- void foo(T)(T t) {} void foo(T)(T t, int i) {} alias bar = foo!int; --- Is there some way/other syntax to make an alias like this work? Or specify in the alias which function template to use (ie. alias bar = foo!int(int)). The problem is not the alias. The error message is about using the same identifier for two different things: C:\...\temp_0186F968.d(13,1): Error: declaration foo(T)(T t, int i) is already defined. 1/ === What you seem to forget is that the declarations: - void foo(T)(T t) {} void foo(T)(T t, int i) {} - are actually a two **Eponymous template** with the same name: - template foo(T){ void foo(T t) {} } template foo(T){ void foo(T t, int i) {} } - This produces the same error message: C:\...\temp_0186F968.d(13,1): Error: declaration foo(T)(T t, int i) is already defined. 2/ === You can make it working by renaming the template name anf by grouping the members: - template hip(T) { void bud(T t) {} void bud(T t, int i) {} } alias baz = hip!int.bud; writeln(typeof(baz).stringof); // void(int t) or void(int t, int i) if you invert bud order. -
The D2 dictionary chalenge.
Try to make a faster one than http://dpaste.dzfl.pl/aa2ad03cb0dd Post your reply here, existing entries must be included.