Re: Opinions: The Best and Worst of D (for a lecture/talk I intend to give)

2014-07-10 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Wednesday, 9 July 2014 at 19:54:47 UTC, H. S. Teoh via Digitalmars-d-learn wrote: [...] The problem is that the function needs to return int, but given two uints, their difference may be greater than int.max, so simply subtracting them will not work. So the best I can come up with is:

Re: Opinions: The Best and Worst of D (for a lecture/talk I intend to give)

2014-07-10 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
Should of course be: int compare2(uint x, int y) { return (x > int.max) ? 1 : (cast(int)x - y); }

Concatenates int

2014-07-10 Thread Sean Campbell via Digitalmars-d-learn
i have the ints 4, 7, 0 and 1 how can i Concatenate them into four thousand seven hundred and one.

Re: How to interact with fortran code

2014-07-10 Thread via Digitalmars-d-learn
On Wednesday, 9 July 2014 at 15:09:08 UTC, Chris wrote: On Wednesday, 9 July 2014 at 15:00:25 UTC, seany wrote: I apologize many times for this question, may be this had already been answered somewhere, but considering today the last of my nerve is broken, I can not really find the soution. S

Re: Concatenates int

2014-07-10 Thread Rikki Cattermole via Digitalmars-d-learn
On 11/07/2014 12:11 a.m., Sean Campbell wrote: i have the ints 4, 7, 0 and 1 how can i Concatenate them into four thousand seven hundred and one. If we talking at compile time definition: int myint = 4_7_0_1; Would work. However I'll assume its at runtime you really want this. I.e. convertin

Re: Concatenates int

2014-07-10 Thread bearophile via Digitalmars-d-learn
Rikki Cattermole: int myint = to!int("4" ~ "7" ~ "0" ~ "1"); And to concatenate them there is "join" (joiner is not yet usable here, because to!() doesn't yet accept a lazy input, unfortunately). Now they are not strings, and the positions of 10^ doesn't change then: int myint = (1000

Re: Concatenates int

2014-07-10 Thread simendsjo via Digitalmars-d-learn
On 07/10/2014 02:22 PM, Rikki Cattermole wrote: > On 11/07/2014 12:11 a.m., Sean Campbell wrote: >> i have the ints 4, 7, 0 and 1 how can i Concatenate them into four >> thousand seven hundred and one. > > If we talking at compile time definition: > > int myint = 4_7_0_1; > > Would work. > Howev

Re: Opinions: The Best and Worst of D (for a lecture/talk I intend to give)

2014-07-10 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
So at all the implementation will look something like this: int opCmp(T, U)(const(T) a, const(U) b) @primitive if(isIntegral!T && isIntegral!U) { alias CommonType!(Signed!T, Signed!U) C; static if(isSigned!T && isUnsigned!U) { return (b > cast(Unsigned!C)C.max) ? -1 : cast(C)a -

Re: Introspecting a Module with Traits, allMembers

2014-07-10 Thread Adam D. Ruppe via Digitalmars-d-learn
The others have already given some answers, I just want to point out that the (free) sample chapter of my D book covers this topic too: http://www.packtpub.com/discover-advantages-of-programming-in-d-cookbook/book Scanning a whole module and getting everything out takes a few tricks that I ta

Re: Concatenates int

2014-07-10 Thread Sean Campbell via Digitalmars-d-learn
perhaps I'd better state what I'm doing. i have an array of 4 bytes and a want to convert them to a 32 bit int and convert the 32 bit int back into a 4 bytes again.

Re: Opinions: The Best and Worst of D (for a lecture/talk I intend to give)

2014-07-10 Thread JR via Digitalmars-d-learn
On Monday, 7 July 2014 at 23:47:26 UTC, Aerolite wrote: So, if you would be so kind, give me a bullet list of the aspects of D you believe to be good, awesome, bad, and/or ugly. If you have the time, some code examples wouldn't go amiss either! Try not to go in-depth to weird edge cases - remai

Re: How to interact with fortran code

2014-07-10 Thread Chris via Digitalmars-d-learn
On Thursday, 10 July 2014 at 12:12:20 UTC, Marc Schütz wrote: On Wednesday, 9 July 2014 at 15:09:08 UTC, Chris wrote: On Wednesday, 9 July 2014 at 15:00:25 UTC, seany wrote: I apologize many times for this question, may be this had already been answered somewhere, but considering today the las

Re: Concatenates int

2014-07-10 Thread Rikki Cattermole via Digitalmars-d-learn
On 11/07/2014 1:18 a.m., Sean Campbell wrote: perhaps I'd better state what I'm doing. i have an array of 4 bytes and a want to convert them to a 32 bit int and convert the 32 bit int back into a 4 bytes again. Small hack I use in Dakka: union RawConvTypes(T) { T value; ubyte[T

Sum informations in file....

2014-07-10 Thread Alexandre via Digitalmars-d-learn
I have one file with a lot of numeric data... and I need to sum all that data... That is my actual code: module main; import std.stdio; import std.file; import std.conv : to; int main(string[] args) { auto f = File("oi.txt"); auto r = f.byLine(); auto tot = 0;

Re: Sum informations in file....

2014-07-10 Thread bearophile via Digitalmars-d-learn
Alexandre: I want to know if have a more better way to make this... maybe using lambda or tamplates Your code is not bad. This is a bit better (untested): void main() { import std.stdio; import std.conv: to; auto lines = "oi.txt".File.byLine; int tot = 0; foreach (c

Re: Sum informations in file....

2014-07-10 Thread Alexandre via Digitalmars-d-learn
O, real intresting the mode functional style!!! Like linq! hahah Btw, it's work very well, thansk!!! But, how I can insert an ',' comma to separe the decimal place ? ( the last 2 digits ) I can't find a "insert" instruction in std.string or std.array On Thursday, 10 July 2014 at 15:01:52 U

Re: Concatenates int

2014-07-10 Thread Sean Campbell via Digitalmars-d-learn
On Thursday, 10 July 2014 at 13:51:22 UTC, Rikki Cattermole wrote: On 11/07/2014 1:18 a.m., Sean Campbell wrote: perhaps I'd better state what I'm doing. i have an array of 4 bytes and a want to convert them to a 32 bit int and convert the 32 bit int back into a 4 bytes again. Small hack I u

core.exception.InvalidMemoryOperationError

2014-07-10 Thread francesco cattoglio via Digitalmars-d-learn
A code I'm working on stops working and starts printing an infinite loop of core.exception.InvalidMemoryOperationError to the command line output. The code is quite complex and the bug seems to present itself almost in random situation so I would like to try to understand the issue better befor

Re: Concatenates int

2014-07-10 Thread Olivier Pisano via Digitalmars-d-learn
Hello, I may have not understood what you actually want to do, but aren't std.bitmanip.peek or std.bitmanip.read what you are looking for ? http://dlang.org/phobos/std_bitmanip.html#.peek

Insert a char in string

2014-07-10 Thread Alexandre via Digitalmars-d-learn
I have a string X and I need to insert a char in that string... auto X = "100"; And I need to inser a ',' in position 3 of this string..., I try to use the array.insertInPlace, but, not work... I try this: auto X = "100"; auto N = X.insertInPlace(1,'0');

Re: Insert a char in string

2014-07-10 Thread John Colvin via Digitalmars-d-learn
On Thursday, 10 July 2014 at 16:05:51 UTC, Alexandre wrote: I have a string X and I need to insert a char in that string... auto X = "100"; And I need to inser a ',' in position 3 of this string..., I try to use the array.insertInPlace, but, not work... I try this: auto X = "1000

Re: Insert a char in string

2014-07-10 Thread Alexandre via Digitalmars-d-learn
Sorry.. I mean: auto X = "100"; auto N = X.insertInPlace(3,','); On Thursday, 10 July 2014 at 16:05:51 UTC, Alexandre wrote: I have a string X and I need to insert a char in that string... auto X = "100"; And I need to inser a ',' in position 3 of this string..., I tr

Re: Insert a char in string

2014-07-10 Thread Alexandre via Digitalmars-d-learn
I used that solution: string InsertComma(string val) { return val[0 .. $-2] ~ "," ~ val[$-2 .. $]; } On Thursday, 10 July 2014 at 16:23:44 UTC, John Colvin wrote: On Thursday, 10 July 2014 at 16:05:51 UTC, Alexandre wrote: I have a string X and I need to insert a char in that string...

Re: Insert a char in string

2014-07-10 Thread via Digitalmars-d-learn
On Thursday, 10 July 2014 at 16:20:29 UTC, Alexandre wrote: Sorry.. I mean: auto X = "100"; auto N = X.insertInPlace(3,','); On Thursday, 10 July 2014 at 16:05:51 UTC, Alexandre wrote: I have a string X and I need to insert a char in that string... auto X = "100"; And

Re: Concatenates int

2014-07-10 Thread via Digitalmars-d-learn
On Thursday, 10 July 2014 at 13:51:22 UTC, Rikki Cattermole wrote: On 11/07/2014 1:18 a.m., Sean Campbell wrote: perhaps I'd better state what I'm doing. i have an array of 4 bytes and a want to convert them to a 32 bit int and convert the 32 bit int back into a 4 bytes again. Small hack I u

Re: Insert a char in string

2014-07-10 Thread Alexandre via Digitalmars-d-learn
Oh, I used that letters in upper case, just for a simple sample... On Thursday, 10 July 2014 at 16:32:53 UTC, Marc Schütz wrote: On Thursday, 10 July 2014 at 16:20:29 UTC, Alexandre wrote: Sorry.. I mean: auto X = "100"; auto N = X.insertInPlace(3,','); On Thursday, 10 July 2014 a

Re: Concatenates int

2014-07-10 Thread Yota via Digitalmars-d-learn
On Thursday, 10 July 2014 at 15:14:21 UTC, Sean Campbell wrote: On Thursday, 10 July 2014 at 13:51:22 UTC, Rikki Cattermole wrote: On 11/07/2014 1:18 a.m., Sean Campbell wrote: perhaps I'd better state what I'm doing. i have an array of 4 bytes and a want to convert them to a 32 bit int and c

Re: core.exception.InvalidMemoryOperationError

2014-07-10 Thread NCrashed via Digitalmars-d-learn
On Thursday, 10 July 2014 at 15:36:53 UTC, francesco cattoglio wrote: A code I'm working on stops working and starts printing an infinite loop of core.exception.InvalidMemoryOperationError to the command line output. The code is quite complex and the bug seems to present itself almost in random

Re: Sum a lot of numbers...

2014-07-10 Thread Alexandre via Digitalmars-d-learn
PS: that is my code: import std.stdio, std.algorithm, std.range, std.conv; string InsertComma(string val) { return val[0 .. $-2] ~ "," ~ val[$-2 .. $]; } int main(string[] argv) { auto x = "oi.txt" .File .byLine .filter!(line => li

Sum a lot of numbers...

2014-07-10 Thread Alexandre via Digitalmars-d-learn
Hi :) I need to sum a list of numbers... but, when I calculate the sum of this numbers, I got a simplify representation of sum: 2.97506e+,12 How I can make to get the correctly representation of this number ?

Re: Sum a lot of numbers...

2014-07-10 Thread Justin Whear via Digitalmars-d-learn
On Thu, 10 Jul 2014 17:16:00 +, Alexandre wrote: > Hi :) > > I need to sum a list of numbers... but, when I calculate the sum of this > numbers, I got a simplify representation of sum: > > 2.97506e+,12 > > How I can make to get the correctly representation of this number ? A full decimal r

Re: Sum a lot of numbers...

2014-07-10 Thread Justin Whear via Digitalmars-d-learn
On Thu, 10 Jul 2014 17:17:40 +, Justin Whear wrote: > On Thu, 10 Jul 2014 17:16:00 +, Alexandre wrote: > >> Hi :) >> >> I need to sum a list of numbers... but, when I calculate the sum of >> this numbers, I got a simplify representation of sum: >> >> 2.97506e+,12 >> >> How I can make t

Re: Concatenates int

2014-07-10 Thread Sean Campbell via Digitalmars-d-learn
On Thursday, 10 July 2014 at 15:51:11 UTC, Olivier Pisano wrote: Hello, I may have not understood what you actually want to do, but aren't std.bitmanip.peek or std.bitmanip.read what you are looking for ? http://dlang.org/phobos/std_bitmanip.html#.peek std.bitmanip.peek and std.bitmanip.read

Re: Concatenates int

2014-07-10 Thread sigod via Digitalmars-d-learn
On Thursday, 10 July 2014 at 17:30:17 UTC, Sean Campbell wrote: if I need to Concatenate ints I'l just use a recursive pow based on length int ConcatInt(int[] anint){ int total = 0; for(int i=0;i With `foreach_reverse` it looks a little better: ```d int concat_ints(int[] ints)

Re: Insert a char in string

2014-07-10 Thread simendsjo via Digitalmars-d-learn
On 07/10/2014 06:05 PM, Alexandre wrote: > I have a string X and I need to insert a char in that string... > > auto X = "100"; > > And I need to inser a ',' in position 3 of this string..., I try to use > the array.insertInPlace, but, not work... > > I try this: > auto X = "1

Re: Insert a char in string

2014-07-10 Thread Alexandre via Digitalmars-d-learn
basically format I read a cobol struct file... From pos X to Y I have a money value... but, this value don't have any format.. 0041415 The 15 is the cents... bascally I need to put the ( comma ), we use comma to separate the cents, here in Brazil... On Thursday, 10 July 2014 at

Using enum constant from different modules

2014-07-10 Thread Jacob Carlborg via Digitalmars-d-learn
Here's a code example: module main; import foo; enum Get = "GET"; void bar (string a) { assert(a is Get); } void main () { asd(); } module foo; import main; void asd() { bar(Get); } Running the above code will cause an assert error in the function "bar". But if I move the fun

Re: Insert a char in string

2014-07-10 Thread simendsjo via Digitalmars-d-learn
On 07/10/2014 09:58 PM, Alexandre wrote: > basically format > I read a cobol struct file... > > From pos X to Y I have a money value... but, this value don't have any > format.. > > 0041415 > > The 15 is the cents... bascally I need to put the ( comma ), we use > comma to separate th

Re: Using enum constant from different modules

2014-07-10 Thread via Digitalmars-d-learn
On Thursday, 10 July 2014 at 20:27:39 UTC, Jacob Carlborg wrote: Here's a code example: module main; import foo; enum Get = "GET"; void bar (string a) { assert(a is Get); } void main () { asd(); } module foo; import main; void asd() { bar(Get); } Running the above code will c

Re: Using enum constant from different modules

2014-07-10 Thread anonymous via Digitalmars-d-learn
On Thursday, 10 July 2014 at 20:27:39 UTC, Jacob Carlborg wrote: Here's a code example: module main; import foo; enum Get = "GET"; void bar (string a) { assert(a is Get); } void main () { asd(); } module foo; import main; void asd() { bar(Get); } Running the above code will c

Re: Using enum constant from different modules

2014-07-10 Thread simendsjo via Digitalmars-d-learn
On 07/10/2014 10:47 PM, "Marc Schütz" " wrote: > On Thursday, 10 July 2014 at 20:27:39 UTC, Jacob Carlborg wrote: >> Here's a code example: >> >> module main; >> >> import foo; >> >> enum Get = "GET"; >> >> void bar (string a) >> { >> assert(a is Get); >> } >> >> void main () >> { >> asd();

Re: Using enum constant from different modules

2014-07-10 Thread via Digitalmars-d-learn
On Thursday, 10 July 2014 at 20:59:17 UTC, simendsjo wrote: Strings behaves a bit odd with is(). The following passes: import std.stdio; void f(string a, string b) { assert(a is b); // also true } void main() { string a = "aoeu"; string b = "aoeu"; assert(a is b); // true f(a

Re: Using enum constant from different modules

2014-07-10 Thread sigod via Digitalmars-d-learn
On Thursday, 10 July 2014 at 20:59:17 UTC, simendsjo wrote: Strings behaves a bit odd with is(). The following passes: import std.stdio; void f(string a, string b) { assert(a is b); // also true } void main() { string a = "aoeu"; string b = "aoeu"; assert(a is b); // true f(a

Setting dates

2014-07-10 Thread Joel via Digitalmars-d-learn
I've been trying to set a date for my program (a small struct): import std.datetime; auto date = cast(DateTime)Clock.currTime(); setDate(date.day, date.month, date.year); Problem is that day & month are not integers. And date.day.to!int doesn't work either.

Re: Using enum constant from different modules

2014-07-10 Thread simendsjo via Digitalmars-d-learn
On 07/11/2014 01:08 AM, sigod wrote: > On Thursday, 10 July 2014 at 20:59:17 UTC, simendsjo wrote: >> Strings behaves a bit odd with is(). The following passes: >> >> import std.stdio; >> void f(string a, string b) { >> assert(a is b); // also true >> } >> void main() { >> string a = "aoeu"

Re: Using enum constant from different modules

2014-07-10 Thread Jacob Carlborg via Digitalmars-d-learn
On 10/07/14 22:47, "Marc Schütz" " wrote: No, this is equivalent to: void bar (string a) { assert(a is "GET"); } void asd() { bar("GET"); } Enums behave as if their values are copy-n-pasted everywhere they are used (you probably know that). Yes, I was thinking that. Then I was thi

Re: Using enum constant from different modules

2014-07-10 Thread Jacob Carlborg via Digitalmars-d-learn
On 10/07/14 22:48, anonymous wrote: I don't think this is a bug. Remember that enums have copy-paste semantics. So, this is the same as comparing literals from different modules. Apparently, in the same module, a duplicate string literal is optimized out. But that's not done across the module b

Re: Using enum constant from different modules

2014-07-10 Thread Jacob Carlborg via Digitalmars-d-learn
On 10/07/14 23:48, "Marc Schütz" " wrote: Try other immutable variables (int arrays, structs), and non-immutable ones. They will probably behave differently. String literals are put directly in the executable and therefore should be the same. Array literals are dynamically allocated. -- /Ja