Re: FYI my experience with D' version

2012-07-30 Thread Tobias Pankrath
The biggest downside is if you add a function, you have to go back to ALL the config files and add it in to make the project compile. enum bool wantsNewFeature = false; which can be a hassle if you have like 20 config files. But, this is good and bad because it does make you think about it

Re: FYI my experience with D' version

2012-07-30 Thread torhu
On 28.07.2012 22:55, Adam D. Ruppe wrote: After some experience, I've come to the conclusion that using D's version() with custom things is usually a mistake. Not always - I think it is still good for platform like tweaks, version(X86) or version(Windows), or even version(Custom_Library), (note,

Re: FYI my experience with D' version

2012-07-30 Thread Jacob Carlborg
On 2012-07-30 12:30, torhu wrote: version is good for global options that you set with -version on the command line. And can also be used internally in a module, but doesn't work across modules. But it seems you have discovered this the hard way already. I think there was a discussion about t

sorting failed error

2012-07-30 Thread maarten van damme
For fun I started implementing a program that uses genetics algorithm's to solve the travelling salesman problem. I want to sort an array of chromosome structures according to their fitness. I now get the error: core.exception.AssertError@C:\D\dmd2\windows\bin\..\..\src\phobos\std\algorithm. d(671

Re: FYI my experience with D' version

2012-07-30 Thread Don Clugston
On 30/07/12 14:32, Jacob Carlborg wrote: On 2012-07-30 12:30, torhu wrote: version is good for global options that you set with -version on the command line. And can also be used internally in a module, but doesn't work across modules. But it seems you have discovered this the hard way alread

Re: sorting failed error

2012-07-30 Thread monarch_dodra
On Monday, 30 July 2012 at 12:36:21 UTC, maarten van damme wrote: For fun I started implementing a program that uses genetics algorithm's to solve the travelling salesman problem. I want to sort an array of chromosome structures according to their fitness. I now get the error: core.exception.

Re: sorting failed error

2012-07-30 Thread maarten van damme
My cmp is : bool fitnessCompare(chromosome first,chromosome second){ return fitness(first)>fitness(second); } float fitness(chromosome victim){ city[] cities=victim.dna; //we need to start from home and return to home cities=city(0,0) ~ cities;

Re: sorting failed error

2012-07-30 Thread monarch_dodra
On Monday, 30 July 2012 at 13:27:58 UTC, maarten van damme wrote: My cmp is : bool fitnessCompare(chromosome first,chromosome second){ return fitness(first)>fitness(second); } float fitness(chromosome victim){ city[] cities=victim.dna; //we need to start

Re: FYI my experience with D' version

2012-07-30 Thread Adam D. Ruppe
On Monday, 30 July 2012 at 10:30:12 UTC, torhu wrote: I think there was a discussion about this a few years ago, Walter did it this way on purpose. Can't remember the details, though. Hell, that might have been me. I first realized version doesn't work for what I was using it for a couple yea

Re: FYI my experience with D' version

2012-07-30 Thread Adam D. Ruppe
On Sunday, 29 July 2012 at 19:20:30 UTC, Jacob Carlborg wrote: You could use versions which sets bool variables and use static-if. I don't know if that's any better. It'd still have the problem of the global name. Consider: -version=use_foo but then lib a and lib b both have: version(use_foo

Re: sorting failed error

2012-07-30 Thread bearophile
maarten van damme: I have no idea what is wrong with my code and the error is not very informative. As first step I suggest to add a space after commas, before brackets, around operators, etc. The improved readability helps spot the bugs. Adding Contracts and other asserts sometimes helps.

Re: sort strings by interpreting them as integrals

2012-07-30 Thread Andrej Mitrovic
On 7/30/12, Jonathan M Davis wrote: > Boost. Cool. Boost is so large I never noticed it (and maybe because I don't use C++ that much). > In any case, whatever the pros and cons are of a path object rather than > strings, it was discussed for Phobos at one point and decided that it just > wasn't

Re: Why must butfields sum to a multiple of a byte?

2012-07-30 Thread monarch_dodra
On Monday, 30 July 2012 at 14:19:56 UTC, Andrej Mitrovic wrote: It says for std.bitmanip.bitfields: "The sum of all bit lengths in one bitfield instantiation must be exactly 8, 16, 32, or 64." It has a static assert to verify this. But why does this limitation exist? I was thinking of cases

Re: sorting failed error

2012-07-30 Thread maarten van damme
it is guaranteed to never be 0 because it always contains all cities so it will always travel something unless there are no cities or when all cities are in the same place (in which case the task to solve is senseless). I'll create an array containing all finesses and try sorting using that. And

Re: Why must butfields sum to a multiple of a byte?

2012-07-30 Thread Andrej Mitrovic
On 7/30/12, monarch_dodra wrote: > I think you are supposed to explicitly pad the field yourself: You're right, I missed that part of the documentation. :)

Re: Implementing a Monitor

2012-07-30 Thread Sean Kelly
You need to lock the mutex to synchronize access to the shared data. On Jul 27, 2012, at 2:31 PM, Minas Mina wrote: > > class Monitor > { > Cond cond; Mutex mutex; > > char[] buffer; > ulong sz; > > this() > { > // necessary:

Has AA .keys the same order as .values?

2012-07-30 Thread Rene Zwanenburg
Hi, I need to interleave multiple arrays stored in an AA into a single array, and the keys of the AA need to be stored separately in the same order as the interleaved data. As an example: auto aa = [ "1" : [1, 2], "2" : [3, 4], "3" : [5, 6], "4" : [7, 8] ] auto values = aa.values; au

Re: Why must butfields sum to a multiple of a byte?

2012-07-30 Thread Ali Çehreli
On 07/30/2012 07:19 AM, Andrej Mitrovic wrote: > I was thinking of cases where I'm wrapping a C++ POD struct which has > bitfields and is packed on a 1-byte boundary. It is inherently unportable because unlike D, bitfields in C and C++ give too much freedom to the compiler. The compiler can mov

Re: Has AA .keys the same order as .values?

2012-07-30 Thread Alex Rønne Petersen
On 30-07-2012 18:00, Rene Zwanenburg wrote: Hi, I need to interleave multiple arrays stored in an AA into a single array, and the keys of the AA need to be stored separately in the same order as the interleaved data. As an example: auto aa = [ "1" : [1, 2], "2" : [3, 4], "3" : [5, 6],

Re: Has AA .keys the same order as .values?

2012-07-30 Thread bearophile
Rene Zwanenburg: I did a quick test and values has the same order as keys, but is this guaranteed to be the case? In Python they they are guaranteed to have the same order (if you don't modify the associative array in the loops). In D the current implementation gives them in the same order

Re: Has AA .keys the same order as .values?

2012-07-30 Thread Rene Zwanenburg
Ordering is not guaranteed at all in AAs. I don't want .keys and .values to have the same order as the order in which it was filled, I understand this is impossible. What I'd like is to have aa.values[i] == aa[aa.keys[i]]. I think this is easy to guarantee with typical AA implementations.

Re: Has AA .keys the same order as .values?

2012-07-30 Thread Rene Zwanenburg
On Monday, 30 July 2012 at 16:21:17 UTC, bearophile wrote: Rene Zwanenburg: I did a quick test and values has the same order as keys, but is this guaranteed to be the case? In Python they they are guaranteed to have the same order (if you don't modify the associative array in the loops). I

Re: Why must butfields sum to a multiple of a byte?

2012-07-30 Thread Andrej Mitrovic
On 7/30/12, Ali Çehreli wrote: > It is inherently unportable because unlike D, bitfields in C and C++ > give too much freedom to the compiler. The compiler can move the fields > around at will. I really need to figure out a reliable way to extract this information, at least for the target platfor

Detector for unused variables

2012-07-30 Thread Namespace
I wrote a short programm which detect and list unused variables. I'm sure it isn't perfect but it passed most of my test cases, but I think at the moment it isn't good enough to present it in announce. Maybe some of you have interest to help me. IMO something like this should be integrated into

Re: Detector for unused variables

2012-07-30 Thread bearophile
Namespace: I wrote a short programm which detect and list unused variables. I suggest to attach both code and testcases to: http://d.puremagic.com/issues/show_bug.cgi?id=3960 Even if your code will never be used, it shows Walter&Andrei that there is interest in having this warning, and test c

Re: Detector for unused variables

2012-07-30 Thread Andrej Mitrovic
On 7/30/12, Namespace wrote: > IMO something like this should be integrated into the D compiler. As long as it's togglable via a compiler switch. :)

Re: Why must butfields sum to a multiple of a byte?

2012-07-30 Thread Ali Çehreli
On 07/30/2012 09:44 AM, Andrej Mitrovic wrote: > On 7/30/12, Ali Çehreli wrote: >> It is inherently unportable because unlike D, bitfields in C and C++ >> give too much freedom to the compiler. The compiler can move the fields >> around at will. > > I really need to figure out a reliable way to e

Re: Detector for unused variables

2012-07-30 Thread Namespace
On Monday, 30 July 2012 at 16:47:32 UTC, bearophile wrote: Namespace: I wrote a short programm which detect and list unused variables. I suggest to attach both code and testcases to: http://d.puremagic.com/issues/show_bug.cgi?id=3960 Even if your code will never be used, it shows Walter&Andre

Re: Why must butfields sum to a multiple of a byte?

2012-07-30 Thread Andrej Mitrovic
On 7/30/12, Ali Çehreli wrote: > The program should be able to detect the placements of the fields. You > can expect a certain bit pattern for a given set of values of the bit > fields, set those values, read them on the D side, detect potential > inconsistencies, and fail the execution (or hopefu

Re: Detector for unused variables

2012-07-30 Thread bearophile
Namespace: I think my english isn't good enough to make a persuasive comment there, but i will try it this evening. I will simply copy my post above. Your English skills seems enough, but in the end what's important is to show that some people care to have for this warning. Walter is usually

Re: Detector for unused variables

2012-07-30 Thread Namespace
I suggest to attach both code and testcases to: http://d.puremagic.com/issues/show_bug.cgi?id=3960 Done.

Re: Detector for unused variables

2012-07-30 Thread bearophile
Namespace: I suggest to attach both code and testcases to: http://d.puremagic.com/issues/show_bug.cgi?id=3960 Done. I see no attachments :-( Only ephemeral links. Bye, bearophile

Re: Why must butfields sum to a multiple of a byte?

2012-07-30 Thread Ali Çehreli
On 07/30/2012 10:15 AM, Andrej Mitrovic wrote: > import std.bitmanip; > struct Foo > { > mixin(bitfields!( > uint, "bits1", 32, > )); > } > > D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\bitmanip.d(76): Error: > shift by 32 is outside the range 0..31 > > Should I file this? Ye

Re: sorting failed error

2012-07-30 Thread Jonathan M Davis
On Monday, July 30, 2012 14:36:07 maarten van damme wrote: > I have no idea what is wrong with my code and the error is not very > informative. Does anyone have any idea as to what the problem could be? My first guess would be that your sorting function is not antisymmetric. I ran into such an is

Re: Detector for unused variables

2012-07-30 Thread Jonathan M Davis
On Monday, July 30, 2012 18:50:08 Andrej Mitrovic wrote: > On 7/30/12, Namespace wrote: > > IMO something like this should be integrated into the D compiler. > > As long as it's togglable via a compiler switch. :) Walter doesn't like compiler switches like that, and he doesn't like it when the

Re: Why must butfields sum to a multiple of a byte?

2012-07-30 Thread monarch_dodra
On Monday, 30 July 2012 at 17:15:54 UTC, Andrej Mitrovic wrote: On 7/30/12, Ali Çehreli wrote: The program should be able to detect the placements of the fields. You can expect a certain bit pattern for a given set of values of the bit fields, set those values, read them on the D side, detect

Re: Why must butfields sum to a multiple of a byte?

2012-07-30 Thread Andrej Mitrovic
On 7/30/12, monarch_dodra wrote: > By the way, what's a "butfield"? LOL I haven't even noticed.

Re: sorting failed error

2012-07-30 Thread maarten van damme
About float not beeing deterministic, would this behavior also exist when I use doubles? I've changed everything to use doubles now and the same error comes up. My sorting function used < so I guess it can never return on (a,b) when (b,a) was true. But on the other hand, it can return false twice.

Re: Detector for unused variables

2012-07-30 Thread Andrej Mitrovic
On 7/30/12, Jonathan M Davis wrote: > Walter doesn't like compiler switches like that Walter is a big fat phony, count the number of switches here: http://www.digitalmars.com/ctg/sc.html#switches :D

Re: sorting failed error

2012-07-30 Thread bearophile
maarten van damme: I really dislike contracts, they kind off blow your function up while adding not that much. I'll add some unit tests. They make your programs more robust. Contracts are used to spot bugs in your code and not to validate data coming from the "outside world". As most other

Re: Detector for unused variables

2012-07-30 Thread Jonathan M Davis
On Monday, July 30, 2012 20:08:12 Andrej Mitrovic wrote: > On 7/30/12, Jonathan M Davis wrote: > > Walter doesn't like compiler switches like that > > Walter is a big fat phony, count the number of switches here: > http://www.digitalmars.com/ctg/sc.html#switches That may be part of _why_ he does

Re: sorting failed error

2012-07-30 Thread maarten van damme
2012/7/30 bearophile : > maarten van damme: > > >> I really dislike contracts, they kind off blow your function up while >> adding not that much. I'll add some unit tests. > > > They make your programs more robust. Contracts are used to spot bugs in your > code and not to validate data coming from

Re: Detector for unused variables

2012-07-30 Thread Namespace
On Monday, 30 July 2012 at 17:39:31 UTC, bearophile wrote: Namespace: I suggest to attach both code and testcases to: http://d.puremagic.com/issues/show_bug.cgi?id=3960 Done. I see no attachments :-( Only ephemeral links. Bye, bearophile Sorry, but i can upload only one file. I will uplo

Re: Detector for unused variables

2012-07-30 Thread Jonathan M Davis
On Monday, July 30, 2012 20:39:02 Namespace wrote: > Jonathan M Davis: > Walter hates so much things, nearly all what the community wishes > for: not null types, warnings for unused variables, warnings for > unused imports and so on. > It does not only count what he wants but what is useful, IMO.

Re: sorting failed error

2012-07-30 Thread bearophile
maarten van damme: Still my sorting problem isn't sorted out. Another possible cause: in D if you sort structs that contain dynamic arrays, the actual contents of the arrays is ignored. This is a HUGE bug in DMD. Bye, bearophile

Re: Detector for unused variables

2012-07-30 Thread Namespace
Plenty of the community agrees with him too, much as there may be some vocal folks who don't. Regardless, because he's the gatekeeper of the reference compiler, he has to be convinced if you want a feature added to either the language or the compiler. He's generally quite reasonable, but he als

Re: sorting failed error

2012-07-30 Thread monarch_dodra
On Monday, 30 July 2012 at 18:50:24 UTC, bearophile wrote: maarten van damme: Still my sorting problem isn't sorted out. Another possible cause: in D if you sort structs that contain dynamic arrays, the actual contents of the arrays is ignored. This is a HUGE bug in DMD. Bye, bearophile

Re: sorting failed error

2012-07-30 Thread bearophile
monarch_dodra: struct S { int opCmp(S b) { if(v[0] < b.v[0]) return -1; if(v[0] > b.v[0]) return 1; return 0; } int[] v; } ... Or did you mean something else? I meant without a definend opCmp. So this is not your problem. Bye, bearophile

Re: sorting failed error

2012-07-30 Thread monarch_dodra
On Monday, 30 July 2012 at 12:36:21 UTC, maarten van damme wrote: For fun I started implementing a program that uses genetics algorithm's to solve the travelling salesman problem. I want to sort an array of chromosome structures according to their fitness. I now get the error: core.exception.

BitArray/BitFields - Reworking with templates

2012-07-30 Thread Era Scarecrow
On Sunday, 29 July 2012 at 12:39:13 UTC, Era Scarecrow wrote: But having them statically separated by name/type seems much more likely to be safer in the long run with reliable results. A question regarding templates. A template with different parameters is completely incompatible correct? S

Re: sorting failed error

2012-07-30 Thread maarten van damme
Great, with that workaround everything works correctly now. I can finally start playing around with my salesman's dna :p There is one little problem left, the comparing problem. I can't really define an opcmp because a city isn't smaller or bigger than another city, it's simply another city. I tr

Re: Detector for unused variables

2012-07-30 Thread Namespace
BTW: Has anyone test my detector and could give me some suggestions or critism?

Re: Detector for unused variables

2012-07-30 Thread Dmitry Olshansky
On 31-Jul-12 00:02, Namespace wrote: BTW: Has anyone test my detector and could give me some suggestions or critism? I haven't tested it but offhand I call it inaccurate :) I had only cursory look at it but: regexes are way underpowered to do the task and thus false positives and false negativ

Re: BitArray/BitFields - Reworking with templates

2012-07-30 Thread Dmitry Olshansky
On 30-Jul-12 23:50, Era Scarecrow wrote: On Sunday, 29 July 2012 at 12:39:13 UTC, Era Scarecrow wrote: But having them statically separated by name/type seems much more likely to be safer in the long run with reliable results. A question regarding templates. A template with different parame

Re: Detector for unused variables

2012-07-30 Thread Jonathan M Davis
On Monday, July 30, 2012 21:02:14 Namespace wrote: > That's right. But the majority of programming languages has this > feature, but D does not. This feature is undeniable effective, so > IMO there is no reason which stands against a warning for unused > variables. Or can you tell me some personal

Re: sorting failed error

2012-07-30 Thread Jonathan M Davis
On Monday, July 30, 2012 21:17:29 bearophile wrote: > I meant without a definend opCmp. So this is not your problem. I'd actually argue that structs without opCmp shouldn't have it implicitly defined. It's just begging for bugs otherwise. - Jonathan M Davis

Re: Detector for unused variables

2012-07-30 Thread Ali Çehreli
On 07/30/2012 12:02 PM, Namespace wrote: > there is no reason which stands against a warning for unused variables. > Or can you tell me some personal reasons, without quoting Walter? People comment-out parts of code during development and debugging, leaving unused variables behind (just for a w

Re: sorting failed error

2012-07-30 Thread monarch_dodra
On Monday, 30 July 2012 at 20:01:59 UTC, maarten van damme wrote: Great, with that workaround everything works correctly now. I can finally start playing around with my salesman's dna :p There is one little problem left, the comparing problem. I can't really define an opcmp because a city isn't

Re: sorting failed error

2012-07-30 Thread monarch_dodra
On Monday, 30 July 2012 at 19:17:30 UTC, bearophile wrote: monarch_dodra: struct S { int opCmp(S b) { if(v[0] < b.v[0]) return -1; if(v[0] > b.v[0]) return 1; return 0; } int[] v; } ... Or did you mean something else? I meant without a definend opCmp. So this is no

Top level array constness discarding and Variant

2012-07-30 Thread cybevnm
During initializing Variant, D discards top level const of array, which leads to little unintuitive behaviour. Consider code: import std.stdio; import std.variant; void main() { const int[] arr; Variant v = Variant( arr ); writeln( v.peek!( typeof( arr ) )() ); writeln( v.peek!( const(in

Re: BitArray/BitFields - Reworking with templates

2012-07-30 Thread Philippe Sigaud
On Mon, Jul 30, 2012 at 9:50 PM, Era Scarecrow wrote: > A question regarding templates. A template with different parameters is > completely incompatible correct? Correct. They have no reason, in general, too even generate the same code: template Chameleon(T) { static if (is(T == struct))

Re: Detector for unused variables

2012-07-30 Thread Namespace
On Monday, 30 July 2012 at 20:06:42 UTC, Dmitry Olshansky wrote: On 31-Jul-12 00:02, Namespace wrote: BTW: Has anyone test my detector and could give me some suggestions or critism? I haven't tested it but offhand I call it inaccurate :) I had only cursory look at it but: regexes are way unde

Re: Top level array constness discarding and Variant

2012-07-30 Thread Jonathan M Davis
On Monday, July 30, 2012 23:44:56 cybevnm wrote: > During initializing Variant, D discards top level const of array, which > leads to little unintuitive behaviour. Consider code: > > import std.stdio; > import std.variant; > void main() > { > const int[] arr; > Variant v = Variant( arr ); > writel

Re: BitArray/BitFields - Reworking with templates

2012-07-30 Thread Era Scarecrow
On Monday, 30 July 2012 at 20:19:51 UTC, Dmitry Olshansky wrote: Not sure what you would like to accomplish here. Than an example... struct BitArray { //assume template... ref BitArray opSliceAssign(T)(const T ba, int start, int end) if ( //if T is type bitArray but only a different cha

Re: Detector for unused variables

2012-07-30 Thread Dmitry Olshansky
On 31-Jul-12 00:45, Namespace wrote: On Monday, 30 July 2012 at 20:06:42 UTC, Dmitry Olshansky wrote: On 31-Jul-12 00:02, Namespace wrote: BTW: Has anyone test my detector and could give me some suggestions or critism? I haven't tested it but offhand I call it inaccurate :) I had only cursory

Re: Detector for unused variables

2012-07-30 Thread Andrej Mitrovic
On 7/30/12, Namespace wrote: > BTW: Has anyone test my detector and could give me some > suggestions or critism? > I've tried it out and it didn't find any unused variables, but I doubt this is true, I'm not very tidy when it comes to using variables. I do use a lot of templates so maybe the scri

Re: BitArray/BitFields - Reworking with templates

2012-07-30 Thread Era Scarecrow
On Monday, 30 July 2012 at 21:03:39 UTC, Era Scarecrow wrote: Alright... Considered a major (Maybe even blocking). http://d.puremagic.com/issues/show_bug.cgi?id=8475

Re: BitArray/BitFields - Reworking with templates

2012-07-30 Thread Era Scarecrow
On Monday, 30 July 2012 at 20:48:26 UTC, Philippe Sigaud wrote: Now if all that is correct, say I want to make two functions that both use X, but are not compatible, but template functions will allow it. So... I'm not sure I understand what you're trying to do. Do you mean you want a function

Re: sorting failed error

2012-07-30 Thread Ellery Newcomer
On 07/30/2012 05:36 AM, maarten van damme wrote: I have no idea what is wrong with my code and the error is not very informative. Does anyone have any idea as to what the problem could be? Congratulations, it looks like you've hit a compiler bug. http://d.puremagic.com/issues/show_bug.cgi?id

Re: Detector for unused variables

2012-07-30 Thread Namespace
On Monday, 30 July 2012 at 21:13:42 UTC, Andrej Mitrovic wrote: On 7/30/12, Namespace wrote: BTW: Has anyone test my detector and could give me some suggestions or critism? I've tried it out and it didn't find any unused variables, but I doubt this is true, I'm not very tidy when it comes t

Re: Detector for unused variables

2012-07-30 Thread bearophile
Jonathan M Davis: This is the sort of thing that's better left to a lint-like tool IMHO. Putting it in a lint means people have to know what a lint is, desire to search it, install, and add its running to their compilation ways. It also means the lint needs to contain part of a D compiler.

Re: Detector for unused variables

2012-07-30 Thread Dmitry Olshansky
On 31-Jul-12 01:37, bearophile wrote: Jonathan M Davis: This is the sort of thing that's better left to a lint-like tool IMHO. Putting it in a lint means people have to know what a lint is, desire to search it, install, and add its running to their compilation ways. Just run it once on each

Re: BitArray/BitFields - Reworking with templates

2012-07-30 Thread Dmitry Olshansky
On 31-Jul-12 01:03, Era Scarecrow wrote: On Monday, 30 July 2012 at 20:19:51 UTC, Dmitry Olshansky wrote: Not sure what you would like to accomplish here. Than an example... You can go for simpler separation: struct BitArray{ //() - is an empty template spec ref BitArrayopSliceAssi

Re: Detector for unused variables

2012-07-30 Thread bearophile
Dmitry Olshansky: "Most people I know" is hardly good enough argument. The point is that this warning is a basic thing, other compilers have it and I enjoy it in those languages and putting this feature into external tools is not going to help most D programmers. I know but DMD won't ha

Re: sorting failed error

2012-07-30 Thread maarten van damme
monarch_dodra, I'm not trying to order cities, I'm trying to filter out duplicate's in my dna chromosomes and "==" isn't working on structs that encapsulates dynamic arrays. And I can compare elements without defining opCmp. I've written a function that calculates the distance travelled when going

Re: BitArray/BitFields - Reworking with templates

2012-07-30 Thread Era Scarecrow
On Monday, 30 July 2012 at 21:56:20 UTC, Dmitry Olshansky wrote: You can go for simpler separation: struct BitArray{ //() - is an empty template spec ref BitArrayopSliceAssign()(const BitArray ba, int start, int end) { //two bit array can try balk mode etc. I'll give it a try, it may very

Re: sorting failed error

2012-07-30 Thread Timon Gehr
On 07/30/2012 02:36 PM, maarten van damme wrote: For fun I started implementing a program that uses genetics algorithm's to solve the travelling salesman problem. I want to sort an array of chromosome structures according to their fitness. I now get the error: core.exception.AssertError@C:\D\dmd

Re: sorting failed error

2012-07-30 Thread Timon Gehr
On 07/30/2012 03:52 PM, monarch_dodra wrote: ... Your looks OK, and I doubt you are mutating. I only see floating point gotchas: If a chromosome travels nothing, then his fitness is 1/0 = NaN. 1/0 evaluates to Inf NaN then compares false with everything, making it un-transitive, and potentia

Re: sorting failed error

2012-07-30 Thread maarten van damme
2012/7/31 Timon Gehr : > I realize that the code is just for fun, but I have some comments: > > - don't .dup stuff just in order to index directly. it never has > any effect other than performance degradation. (this could be a > compiler warning) > > - crossOver and mutate mutate their parameters i

AES decrypt/encrypt Stream

2012-07-30 Thread David
Hello, I have to encrypt/decrypt all data which is sent through a stream (socketstream). The current design is: TCP socket → SocketStream → EndianStream Now I have to integrate some sort of AESStream: TCP socket → SocketStream → AESStream → EndianStream That is what I thought of, but there

Re: BitArray/BitFields - Reworking with templates

2012-07-30 Thread Era Scarecrow
On Monday, 30 July 2012 at 22:23:46 UTC, Era Scarecrow wrote: On Monday, 30 July 2012 at 21:56:20 UTC, Dmitry Olshansky wrote: in == scope const not sure what scope buys here but couldn't hurt. If it can avoid making a new copy, then it likely would help. I'll need to test it. I actually am n

Re: BitArray/BitFields - Reworking with templates

2012-07-30 Thread Dmitry Olshansky
On 31-Jul-12 02:40, Era Scarecrow wrote: On Monday, 30 July 2012 at 22:23:46 UTC, Era Scarecrow wrote: On Monday, 30 July 2012 at 21:56:20 UTC, Dmitry Olshansky wrote: in == scope const not sure what scope buys here but couldn't hurt. If it can avoid making a new copy, then it likely would he

Re: Detector for unused variables

2012-07-30 Thread Dmitry Olshansky
On 31-Jul-12 02:02, bearophile wrote: Dmitry Olshansky: "Most people I know" is hardly good enough argument. The point is that this warning is a basic thing, other compilers have it and I enjoy it in those languages and putting this feature into external tools is not going to help I'm seein

Re: sorting failed error

2012-07-30 Thread Timon Gehr
On 07/31/2012 12:30 AM, maarten van damme wrote: 2012/7/31 Timon Gehr: ... further comments whose application does not lead to immediate benefit: - in contracts are better specified in their dedicated section to push the requirements onto the caller. - consider for(;;) as a means for indefinit

Re: BitArray/BitFields - Reworking with templates

2012-07-30 Thread Era Scarecrow
On Monday, 30 July 2012 at 22:44:21 UTC, Dmitry Olshansky wrote: Fixed : void func(bool smth)(X!(smth).XT x){ By default XT is deduced as X!(current value of smth).XT Doesn't really fix it... a.func(b); //65 - doesn't match declaration. a.func(ba); //66 //other template test

Re: Detector for unused variables

2012-07-30 Thread bearophile
Dmitry Olshansky: I'm seeing the same argument over and over again :) most D programmers. What do you look for? A language designed for 5-10% of its users? No thanks. Bye, bearophile

Re: sorting failed error

2012-07-30 Thread Andrej Mitrovic
On 7/31/12, Timon Gehr wrote: > I like it more because it says "loop". I'd love to have "loop { }". But keyword bloat yada yada. :)

Re: Why must bitfields sum to a multiple of a byte?

2012-07-30 Thread Era Scarecrow
On Monday, 30 July 2012 at 17:43:28 UTC, Ali Çehreli wrote: On 07/30/2012 10:15 AM, Andrej Mitrovic wrote: > import std.bitmanip; > struct Foo > { > mixin(bitfields!( > uint, "bits1", 32, > )); > } > > D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\bitmanip.d(76): Error: > shift

Re: Why must bitfields sum to a multiple of a byte?

2012-07-30 Thread Andrej Mitrovic
On 7/31/12, Era Scarecrow wrote: > And likely one I'll be working on fairly soon. I've been > concentrating on the BitArray, but I'll get more of the bitfields > very very soon. > Cool. What about the max limit of 64bits per bitfield instantiation? I don't suppose this is common in C++ but I wo

Re: Why must bitfields sum to a multiple of a byte?

2012-07-30 Thread Era Scarecrow
On Monday, 30 July 2012 at 23:41:39 UTC, Andrej Mitrovic wrote: On 7/31/12, Era Scarecrow wrote: And likely one I'll be working on fairly soon. I've been concentrating on the BitArray, but I'll get more of the bitfields very very soon. Cool. What about the Max limit of 64bits per bitfield i

Re: Why must bitfields sum to a multiple of a byte?

2012-07-30 Thread Era Scarecrow
On Tuesday, 31 July 2012 at 00:00:24 UTC, Era Scarecrow wrote: Corrections: So, 2 variables using 4 bit ints would be void a(int v) @property { value &= ~(0x7 << 4); value |= (v & 0x7) << 4; } the second setter should be void b(int v) @property {

Re: sorting failed error

2012-07-30 Thread bearophile
Jonathan M Davis: I'd actually argue that structs without opCmp shouldn't have it implicitly defined. It's just begging for bugs otherwise. For reference, this is the issue we are talking about: http://d.puremagic.com/issues/show_bug.cgi?id=3789 The current situation is totally not acceptable

Re: Why must bitfields sum to a multiple of a byte?

2012-07-30 Thread Andrej Mitrovic
On 7/31/12, Era Scarecrow wrote: > It assumes the largest type we can currently use which is ulong Ah yes, it makes sense now. Thanks for the brain cereal. :p

Re: BitArray/BitFields - Reworking with templates

2012-07-30 Thread Philippe Sigaud
On Mon, Jul 30, 2012 at 11:19 PM, Era Scarecrow wrote: >> void func(T)(X!T x) >> {} >> >> void main() >> { >> X!bool b; >> X!int i; >> func(b); >> func(i); >> } > > > Hmmm i do think that seems right... but if it contains multiple parameters, > then...? > > template X(x1, x2, x3)

Re: sorting failed error

2012-07-30 Thread monarch_dodra
On Tuesday, 31 July 2012 at 00:21:59 UTC, bearophile wrote: Jonathan M Davis: I'd actually argue that structs without opCmp shouldn't have it implicitly defined. It's just begging for bugs otherwise. For reference, this is the issue we are talking about: http://d.puremagic.com/issues/show_bug

Re: sorting failed error

2012-07-30 Thread monarch_dodra
On Monday, 30 July 2012 at 22:58:28 UTC, Timon Gehr wrote: On 07/31/2012 12:30 AM, maarten van damme wrote: 2012/7/31 Timon Gehr: ... further comments whose application does not lead to immediate benefit: - in contracts are better specified in their dedicated section to push the requiremen

Re: BitArray/BitFields - Reworking with templates

2012-07-30 Thread Era Scarecrow
On Tuesday, 31 July 2012 at 05:27:58 UTC, Philippe Sigaud wrote: No. Use a 3-params template or a tuple: void func(A,B,C)(X!(A,B,C) x) {} or void func(Ts...)(X!(Ts) x) {} I don't know how many arguments it will have (depends on how many options I give it), and I honestly don't; It should be

Re: sorting failed error

2012-07-30 Thread monarch_dodra
On Monday, 30 July 2012 at 22:23:10 UTC, Timon Gehr wrote: On 07/30/2012 03:52 PM, monarch_dodra wrote: ... NaN then compares false with everything, making it un-transitive, and potentially breaking your cmp. COuld you try the algo with "return 1/(1+travelled)". That, or because of the non-d