digitalmars.D - Shortcuts
- Trevor Parscal (35/35) Feb 26 2006 I just wrote a new templated shortcut module for Fusion - and I thought ...
- James Dunne (10/57) Feb 26 2006 Hmm, I don't know. That removes a lot of typing information. Also,
- Trevor Parscal (7/42) Feb 26 2006 OR perphaps not - I was messing with it allot more, using different type...
- James Dunne (5/64) Feb 26 2006 Hehe. Understood.
I just wrote a new templated shortcut module for Fusion - and I thought I would suggest inclusion in phobos - since it's so darn handy. Some might think this isn't their style - but it can be useful in making things look nice and clear IMHO. The idea is that you can have "multi" argument properties like... ///////////////////////////////// class FOO { int[] Range(int[] _values) in { asert(_values.length >= 2); } body { this.start = _values[0]; this.end = _values[1]; return _values; } } ///////////////////////////////// and than you can use the property like... ///////////////////////////////// foo.Range = pair(1, 10); ///////////////////////////////// There are 3 shortcuts. all deal with values of a single type. pair has 2 arguments, and always returns a dynamic array with 2 elements. trio has 3 arguments, and always returns a dynamic array with 3 elements. list is variadic, and always returns a dynamic array with at least 1 element. The code can be seen on the dsource svn... http://svn.dsource.org/projects/terra/trunk/Fusion/Source/Fusion/Composite.d The source is free as in beer - just let your buddies know who gave you the beer! Thanks, Trevor Parscal
Feb 26 2006
Trevor Parscal wrote:I just wrote a new templated shortcut module for Fusion - and I thought I would suggest inclusion in phobos - since it's so darn handy. Some might think this isn't their style - but it can be useful in making things look nice and clear IMHO. The idea is that you can have "multi" argument properties like... ///////////////////////////////// class FOO { int[] Range(int[] _values) in { asert(_values.length >= 2); } body { this.start = _values[0]; this.end = _values[1]; return _values; } } ///////////////////////////////// and than you can use the property like... ///////////////////////////////// foo.Range = pair(1, 10); ///////////////////////////////// There are 3 shortcuts. all deal with values of a single type. pair has 2 arguments, and always returns a dynamic array with 2 elements. trio has 3 arguments, and always returns a dynamic array with 3 elements. list is variadic, and always returns a dynamic array with at least 1 element. The code can be seen on the dsource svn... http://svn.dsource.org/projects/terra/trunk/Fusion/Source/Fusion/Composite.d The source is free as in beer - just let your buddies know who gave you the beer! Thanks, Trevor ParscalHmm, I don't know. That removes a lot of typing information. Also, dynamic memory is allocated per each function call, which makes it look less appealing, not to mention non-performant. And finally, the list method is kinda scary - a silent failure case hidden away in your casting on pointers. What's to be gained here? -- Regards, James Dunne
Feb 26 2006
In article <dtsl1i$1n4e$1 digitaldaemon.com>, Trevor Parscal says...I just wrote a new templated shortcut module for Fusion - and I thought I would suggest inclusion in phobos - since it's so darn handy. Some might think this isn't their style - but it can be useful in making things look nice and clear IMHO. The idea is that you can have "multi" argument properties like... ///////////////////////////////// class FOO { int[] Range(int[] _values) in { asert(_values.length >= 2); } body { this.start = _values[0]; this.end = _values[1]; return _values; } } ///////////////////////////////// and than you can use the property like... ///////////////////////////////// foo.Range = pair(1, 10); ///////////////////////////////// There are 3 shortcuts. all deal with values of a single type. pair has 2 arguments, and always returns a dynamic array with 2 elements. trio has 3 arguments, and always returns a dynamic array with 3 elements. list is variadic, and always returns a dynamic array with at least 1 element. The code can be seen on the dsource svn... http://svn.dsource.org/projects/terra/trunk/Fusion/Source/Fusion/Composite.d The source is free as in beer - just let your buddies know who gave you the beer! Thanks, Trevor ParscalOR perphaps not - I was messing with it allot more, using different types, and allot of casting is needed to support all types.. so - I guess this will never really work on a generic level. Sorry for posting before testing extensively... I get excited sometimes.. :) Thanks, Trevor Parscal
Feb 26 2006
Trevor Parscal wrote:In article <dtsl1i$1n4e$1 digitaldaemon.com>, Trevor Parscal says...Hehe. Understood. -- Regards, James DunneI just wrote a new templated shortcut module for Fusion - and I thought I would suggest inclusion in phobos - since it's so darn handy. Some might think this isn't their style - but it can be useful in making things look nice and clear IMHO. The idea is that you can have "multi" argument properties like... ///////////////////////////////// class FOO { int[] Range(int[] _values) in { asert(_values.length >= 2); } body { this.start = _values[0]; this.end = _values[1]; return _values; } } ///////////////////////////////// and than you can use the property like... ///////////////////////////////// foo.Range = pair(1, 10); ///////////////////////////////// There are 3 shortcuts. all deal with values of a single type. pair has 2 arguments, and always returns a dynamic array with 2 elements. trio has 3 arguments, and always returns a dynamic array with 3 elements. list is variadic, and always returns a dynamic array with at least 1 element. The code can be seen on the dsource svn... http://svn.dsource.org/projects/terra/trunk/Fusion/Source/Fusion/Composite.d The source is free as in beer - just let your buddies know who gave you the beer! Thanks, Trevor ParscalOR perphaps not - I was messing with it allot more, using different types, and allot of casting is needed to support all types.. so - I guess this will never really work on a generic level. Sorry for posting before testing extensively... I get excited sometimes.. :) Thanks, Trevor Parscal
Feb 26 2006