www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Any plans to support .sort in CTFE?

reply Trass3r <un known.com> writes:
The builtin .sort property doesn't work so far: Error: _adSort cannot be  
interpreted at compile time, because it has no available source code

algorithm's sort does neither: dmd: interpret.c:2680: Expression*  
BinExp::interpretAssignCommon(InterState*, CtfeGoal, Expression*  
(*)(Type*, Expression*, Expression*), int): Assertion `(newval->op ==  
TOKarrayliteral || newval->op == TOKassocarrayliteral || newval->op ==  
TOKstring || newval->op == TOKslice || newval->op == TOKnull)' failed.

Any plans to support sorting?
Jul 10 2011
next sibling parent bearophile <bearophileHUGS lycos.com> writes:
Trass3r:

 The builtin .sort property doesn't work so far: Error: _adSort cannot be  
 interpreted at compile time, because it has no available source code

I think .sort is going to be deprecated. (The abilities of CTFE are growing, why don't you write a small CT sort for your purpose?) Bye, bearophile
Jul 10 2011
prev sibling next sibling parent "Daniel Murphy" <yebblies nospamgmail.com> writes:
"Trass3r" <un known.com> wrote in message news:op.vyevsfd03ncmek enigma...
 The builtin .sort property doesn't work so far: Error: _adSort cannot be 
 interpreted at compile time, because it has no available source code

 algorithm's sort does neither: dmd: interpret.c:2680: Expression* 
 BinExp::interpretAssignCommon(InterState*, CtfeGoal, Expression* 
 (*)(Type*, Expression*, Expression*), int): Assertion `(newval->op == 
 TOKarrayliteral || newval->op == TOKassocarrayliteral || newval->op == 
 TOKstring || newval->op == TOKslice || newval->op == TOKnull)' failed.

 Any plans to support sorting?

.sort will probably be going away. std.algorithm.sort will likely work in ctfe by dmd 2.055
Jul 10 2011
prev sibling parent dsimcha <dsimcha yahoo.com> writes:
On 7/10/2011 12:22 PM, Trass3r wrote:
 The builtin .sort property doesn't work so far: Error: _adSort cannot be
 interpreted at compile time, because it has no available source code

 algorithm's sort does neither: dmd: interpret.c:2680: Expression*
 BinExp::interpretAssignCommon(InterState*, CtfeGoal, Expression*
 (*)(Type*, Expression*, Expression*), int): Assertion `(newval->op ==
 TOKarrayliteral || newval->op == TOKassocarrayliteral || newval->op ==
 TOKstring || newval->op == TOKslice || newval->op == TOKnull)' failed.

 Any plans to support sorting?

IMHO .sort should just be deprecated and eventually removed, at least in D2. It's slow (compared to std.algorithm, at least with the optimizations that were added for 2.054), it's inflexible (because you can't specify your own comparison function), and there's no good reason for it to be builtin. Even the syntactic sugar issue is a non-issue now with uniform function call syntax.
Jul 10 2011