Re: Preventing implicit conversion

2015-11-05 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Thursday, 5 November 2015 at 09:33:40 UTC, ixid wrote: In C++ I can add two shorts together without having to use a cast to assign the result to one of the two shorts. It just seems super clunky not to be able to do basic operations on basic types without casts everywhere. +1 If

Re: Associative array with duplicated keys?

2015-11-05 Thread Andrea Fontana via Digitalmars-d-learn
On Thursday, 5 November 2015 at 09:27:35 UTC, tcak wrote: On Thursday, 5 November 2015 at 08:55:10 UTC, Andrea Fontana wrote: Check this: http://dpaste.dzfl.pl/ebbb3ebac60e It doesn't give any error or warning. And writeln seems confused (do you see that "," at the end?) I am sure the coder

Associative array with duplicated keys?

2015-11-05 Thread Andrea Fontana via Digitalmars-d-learn
Check this: http://dpaste.dzfl.pl/ebbb3ebac60e It doesn't give any error or warning. And writeln seems confused (do you see that "," at the end?)

Re: Preventing implicit conversion

2015-11-05 Thread ixid via Digitalmars-d-learn
On Thursday, 5 November 2015 at 05:41:46 UTC, Jonathan M Davis wrote: On Wednesday, November 04, 2015 21:22:02 ixid via Digitalmars-d-learn wrote: On Wednesday, 4 November 2015 at 19:09:42 UTC, Maxim Fomin wrote: > On Wednesday, 4 November 2015 at 14:27:49 UTC, ixid wrote: >> Is there an

Re: Associative array with duplicated keys?

2015-11-05 Thread tcak via Digitalmars-d-learn
On Thursday, 5 November 2015 at 08:55:10 UTC, Andrea Fontana wrote: Check this: http://dpaste.dzfl.pl/ebbb3ebac60e It doesn't give any error or warning. And writeln seems confused (do you see that "," at the end?) I am sure the coder of writeln was lazy to prevent putting ", " after last

Re: looking for sdl2 based application skeleton

2015-11-05 Thread CraigDillabaugh via Digitalmars-d-learn
On Thursday, 5 November 2015 at 07:26:08 UTC, drug wrote: It seems to me I saw somewhere the project like this. I don't want to make another one if there is something like that. Where you thinking of Derelict? https://github.com/DerelictOrg/DerelictSDL2 or perhaps Dgame:

Re: Help with Concurrency

2015-11-05 Thread Dmitri via Digitalmars-d-learn
On Tuesday, 3 November 2015 at 23:16:59 UTC, bertg wrote: I am having trouble with a simple use of concurrency. Running the following code I get 3 different tid's, multiple "sock in" messages printed, but no receives. I am supposed to get a "received!" for each "sock in", but I am getting

Re: Associative array with duplicated keys?

2015-11-05 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 5 November 2015 at 10:04:02 UTC, Andrea Fontana wrote: Anyway: are duplicated keys on declaration allowed? They shouldn't be...

Re: Align a variable on the stack.

2015-11-05 Thread Marc Schütz via Digitalmars-d-learn
On Thursday, 5 November 2015 at 03:52:47 UTC, TheFlyingFiddle wrote: I don't really know where to go from here to figure out the underlying cause. Does anyone have any suggestions? Can you publish two compilable and runnable versions of the code that exhibit the difference? Then we can have a

Re: Preventing implicit conversion

2015-11-05 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
And I want to have small number litterals automatically choosing the smallest fitting type. If I write ubyte b = 1u; auto c = b + 1u; I expect the 1u to be of type ubyte - and also c.

Re: Associative array with duplicated keys?

2015-11-05 Thread Marc Schütz via Digitalmars-d-learn
https://issues.dlang.org/show_bug.cgi?id=15290

Re: Associative array with duplicated keys?

2015-11-05 Thread Gary Willoughby via Digitalmars-d-learn
On Thursday, 5 November 2015 at 10:04:02 UTC, Andrea Fontana wrote: Anyway: are duplicated keys on declaration allowed? IMHO This should at least be a warning.

Re: Associative array with duplicated keys?

2015-11-05 Thread Marc Schütz via Digitalmars-d-learn
On Thursday, 5 November 2015 at 08:55:10 UTC, Andrea Fontana wrote: Check this: http://dpaste.dzfl.pl/ebbb3ebac60e It doesn't give any error or warning. And writeln seems confused (do you see that "," at the end?) This is an outright bug, please report on issues.dlang.org: void main() {

Re: conver BigInt to string

2015-11-05 Thread Meta via Digitalmars-d-learn
On Thursday, 5 November 2015 at 16:29:30 UTC, Namal wrote: Hello I am trying to convert BigInt to string like that while trying to sort it: string s1 = to!string(a).dup.sort; and get an error cannot implicitly convert expression (_adSortChar(dup(to(a of type char[] to string what do I

Re: conver BigInt to string

2015-11-05 Thread Namal via Digitalmars-d-learn
On Thursday, 5 November 2015 at 16:35:01 UTC, BBasile wrote: On Thursday, 5 November 2015 at 16:29:30 UTC, Namal wrote: Hello I am trying to convert BigInt to string like that while trying to sort it: string s1 = to!string(a).dup.sort; and get an error cannot implicitly convert expression

Re: conver BigInt to string

2015-11-05 Thread Namal via Digitalmars-d-learn
On Thursday, 5 November 2015 at 17:13:07 UTC, Ilya Yaroshenko wrote: string s1 = to!string(a).dup.sort.idup; well, but I was just told not to use sort ??

Re: conver BigInt to string

2015-11-05 Thread Namal via Digitalmars-d-learn
On Thursday, 5 November 2015 at 16:45:10 UTC, Meta wrote: On Thursday, 5 November 2015 at 16:29:30 UTC, Namal wrote: Hello I am trying to convert BigInt to string like that while trying to sort it: string s1 = to!string(a).dup.sort; and get an error cannot implicitly convert expression

conver BigInt to string

2015-11-05 Thread Namal via Digitalmars-d-learn
Hello I am trying to convert BigInt to string like that while trying to sort it: string s1 = to!string(a).dup.sort; and get an error cannot implicitly convert expression (_adSortChar(dup(to(a of type char[] to string what do I do wrong?

Re: conver BigInt to string

2015-11-05 Thread BBasile via Digitalmars-d-learn
On Thursday, 5 November 2015 at 16:39:03 UTC, Namal wrote: On Thursday, 5 November 2015 at 16:35:01 UTC, BBasile wrote: On Thursday, 5 November 2015 at 16:29:30 UTC, Namal wrote: Hello I am trying to convert BigInt to string like that while trying to sort it: string s1 =

Re: conver BigInt to string

2015-11-05 Thread Ilya Yaroshenko via Digitalmars-d-learn
On Thursday, 5 November 2015 at 16:53:50 UTC, Namal wrote: On Thursday, 5 November 2015 at 16:45:10 UTC, Meta wrote: On Thursday, 5 November 2015 at 16:29:30 UTC, Namal wrote: Hello I am trying to convert BigInt to string like that while trying to sort it: string s1 = to!string(a).dup.sort;

cast(T) documentation

2015-11-05 Thread Carl Sturtivant via Digitalmars-d-learn
Hello, Is cast(T) documented all in one place somewhere? I'd like to understand exactly what it does and does not do.

Re: good reasons not to use D?

2015-11-05 Thread Ilya Yaroshenko via Digitalmars-d-learn
On Monday, 2 November 2015 at 17:07:33 UTC, Laeeth Isharc wrote: On Sunday, 1 November 2015 at 09:07:56 UTC, Ilya Yaroshenko wrote: On Friday, 30 October 2015 at 10:35:03 UTC, Laeeth Isharc wrote: Any other thoughts? Floating point operations can be extended automatically (without some kind

Re: conver BigInt to string

2015-11-05 Thread BBasile via Digitalmars-d-learn
On Thursday, 5 November 2015 at 16:29:30 UTC, Namal wrote: Hello I am trying to convert BigInt to string like that while trying to sort it: string s1 = to!string(a).dup.sort; and get an error cannot implicitly convert expression (_adSortChar(dup(to(a of type char[] to string what do I

Re: conver BigInt to string

2015-11-05 Thread bearophile via Digitalmars-d-learn
Namal: Hello I am trying to convert BigInt to string like that while trying to sort it: void main() { import std.stdio, std.algorithm, std.conv, std.bigint, std.string; auto n = 17.BigInt ^^ 179; n.text.dup.representation.sort().release.assumeUTF.writeln; } Bye, bearophile

Re: conver BigInt to string

2015-11-05 Thread bearophile via Digitalmars-d-learn
void main() { import std.stdio, std.algorithm, std.conv, std.bigint, std.string; auto n = 17.BigInt ^^ 179; n.text.dup.representation.sort().release.assumeUTF.writeln; } Better: n.to!(char[]).representation.sort().release.assumeUTF.writeln; Bye, bearophile

Re: bearophile is back! :) was: Re: conver BigInt to string

2015-11-05 Thread Chris via Digitalmars-d-learn
On Thursday, 5 November 2015 at 19:38:23 UTC, Ali Çehreli wrote: Good one! ;) I'm really happy that he is still around. Ali So am I! The more, the merrier!

Re: cast(T) documentation

2015-11-05 Thread Ali Çehreli via Digitalmars-d-learn
On 11/05/2015 07:51 AM, Carl Sturtivant wrote: Hello, Is cast(T) documented all in one place somewhere? I'd like to understand exactly what it does and does not do. This is what I can find: http://dlang.org/expression.html#CastExpression Ali

bearophile is back! :) was: Re: conver BigInt to string

2015-11-05 Thread Ali Çehreli via Digitalmars-d-learn
On 11/05/2015 09:40 AM, bearophile wrote: Bye, bearophile Were you immersed in another language? Rust? Ali

Re: bearophile is back! :) was: Re: conver BigInt to string

2015-11-05 Thread Ali Çehreli via Digitalmars-d-learn
On 11/05/2015 11:35 AM, Chris wrote: On Thursday, 5 November 2015 at 19:30:02 UTC, Ali Çehreli wrote: On 11/05/2015 09:40 AM, bearophile wrote: Bye, bearophile Were you immersed in another language? Rust? Ali His D doesn't seem to be Rusty though! Good one! ;) I'm really happy that he

Re: bearophile is back! :) was: Re: conver BigInt to string

2015-11-05 Thread Chris via Digitalmars-d-learn
On Thursday, 5 November 2015 at 19:30:02 UTC, Ali Çehreli wrote: On 11/05/2015 09:40 AM, bearophile wrote: Bye, bearophile Were you immersed in another language? Rust? Ali His D doesn't seem to be Rusty though!

Re: Operator implicit conversion difference

2015-11-05 Thread Ali Çehreli via Digitalmars-d-learn
On 11/05/2015 05:20 AM, ixid wrote: > This seems very inconsistent, does a += b not lower to a = a + b? Apparently not: http://dlang.org/expression.html#AssignExpression It says "The right operand is implicitly converted to the type of the left operand". So, the rules are different. Ali

Re: parallel

2015-11-05 Thread anonymous via Digitalmars-d-learn
On 05.11.2015 21:30, Handyman wrote: Seems that 4 cores go all out on first 4 dishes, then 1 core deals with the last dish. With 4 cores I expect diner is ready after 5/4 = 1.25 secs though. What did I do wrong? You describe the situation correctly. The unit of work is a dish. That is, the

Re: parallel

2015-11-05 Thread Ali Çehreli via Digitalmars-d-learn
On 11/05/2015 12:58 PM, Handyman wrote: > On Thursday, 5 November 2015 at 20:54:37 UTC, anonymous wrote: >> There is not attempt to split the `prepare` action up and run parts of >> it in parallel. > > So 1.25 secs is impossible? For the given example, yes, impossible. However, as mentioned

Re: Align a variable on the stack.

2015-11-05 Thread TheFlyingFiddle via Digitalmars-d-learn
On Thursday, 5 November 2015 at 21:24:03 UTC, TheFlyingFiddle wrote: On Thursday, 5 November 2015 at 21:22:18 UTC, TheFlyingFiddle wrote: On Thursday, 5 November 2015 at 11:14:50 UTC, Marc Schütz wrote: ~10x slowdown... I forgot to mention this but I am using DMD 2.069.0-rc2 for x86

Re: Align a variable on the stack.

2015-11-05 Thread rsw0x via Digitalmars-d-learn
On Thursday, 5 November 2015 at 23:37:45 UTC, TheFlyingFiddle wrote: On Thursday, 5 November 2015 at 21:24:03 UTC, TheFlyingFiddle wrote: [...] I reduced it further: [...] these run at the exact same speed for me and produce identical assembly output from a quick glance dmd 2.069, -O

Re: conver BigInt to string

2015-11-05 Thread TheGag96 via Digitalmars-d-learn
On Thursday, 5 November 2015 at 16:45:10 UTC, Meta wrote: The second issue is that using .sort instead of .sort() (note the parentheses) calls the built-in sort instead of std.algorithm.sort, which is strongly discouraged. You should always use std.algorithm.sort over the built-in sort, which

Re: parallel

2015-11-05 Thread Ali Çehreli via Digitalmars-d-learn
On 11/05/2015 12:43 PM, Handyman wrote: On Thursday, 5 November 2015 at 20:40:00 UTC, anonymous wrote: So one of your four cores has to make two dishes. That takes two seconds. So make fine-grained? foreach (i; 0..50) Thread.sleep(20.msecs); But then my program still says: '2 secs'.

Re: parallel

2015-11-05 Thread Alex Parrill via Digitalmars-d-learn
On Thursday, 5 November 2015 at 20:30:05 UTC, Handyman wrote: Seems that 4 cores go all out on first 4 dishes, then 1 core deals with the last dish. With 4 cores I expect diner is ready after 5/4 = 1.25 secs though. What did I do wrong? The first four dishes get scheduled, all of them sleep

Re: parallel

2015-11-05 Thread Handyman via Digitalmars-d-learn
On Thursday, 5 November 2015 at 20:40:00 UTC, anonymous wrote: So one of your four cores has to make two dishes. That takes two seconds. So make fine-grained? foreach (i; 0..50) Thread.sleep(20.msecs); But then my program still says: '2 secs'. Please enlighten me.

Re: parallel

2015-11-05 Thread anonymous via Digitalmars-d-learn
On 05.11.2015 21:43, Handyman wrote: foreach (i; 0..50) Thread.sleep(20.msecs); But then my program still says: '2 secs'. Please enlighten me. Let's look at the line that does the `parallel` call: foreach (dish; parallel(dishes, 1)) dish.prepare(); This means that `dishes` is

Re: parallel

2015-11-05 Thread Handyman via Digitalmars-d-learn
On Thursday, 5 November 2015 at 20:45:25 UTC, Ali Çehreli wrote: That's still 1 second per task. The function prepare() cannot be executed by more than one core. Thanks. OK. So 'prepare' is atomic? Then let's turn it around: how can I make the cores prepare a meal of 5 dishes in 1.25 secs?

Re: parallel

2015-11-05 Thread Handyman via Digitalmars-d-learn
On Thursday, 5 November 2015 at 20:54:37 UTC, anonymous wrote: There is not attempt to split the `prepare` action up and run parts of it in parallel. So 1.25 secs is impossible?

Re: parallel

2015-11-05 Thread anonymous via Digitalmars-d-learn
On 05.11.2015 21:52, Handyman wrote: On Thursday, 5 November 2015 at 20:45:25 UTC, Ali Çehreli wrote: That's still 1 second per task. The function prepare() cannot be executed by more than one core. Thanks. OK. So 'prepare' is atomic? Then let's turn it around: how can I make the cores

Re: Align a variable on the stack.

2015-11-05 Thread TheFlyingFiddle via Digitalmars-d-learn
On Thursday, 5 November 2015 at 11:14:50 UTC, Marc Schütz wrote: On Thursday, 5 November 2015 at 03:52:47 UTC, TheFlyingFiddle wrote: Can you publish two compilable and runnable versions of the code that exhibit the difference? Then we can have a look at the generated assembly. If there's

Re: parallel

2015-11-05 Thread Handyman via Digitalmars-d-learn
On Thursday, 5 November 2015 at 21:10:16 UTC, anonymous wrote: parallel(iota(50))) Wow. I have dealt with ranges and 'iota' (and with parallel), but I admit I have to think hard about this example. Thanks a bunch all for your patience.

parallel

2015-11-05 Thread Handyman via Digitalmars-d-learn
import std.stdio; import core.thread; import std.datetime; // for stopwatch import std.parallelism; void say(string s) { // write and flush writeln(s); stdout.flush(); } struct Dish { string name; void prepare() { say("Start with the " ~ name ~ ".");

Re: Preventing implicit conversion

2015-11-05 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Thursday, 5 November 2015 at 13:23:34 UTC, Adam D. Ruppe wrote: On Thursday, 5 November 2015 at 10:07:30 UTC, Dominikus Dittes Scherkl wrote: ubyte b = 1u; auto c = b + 1u; I expect the 1u to be of type ubyte - and also c. This won't work because of the one-expression rule. In the

Re: Align a variable on the stack.

2015-11-05 Thread TheFlyingFiddle via Digitalmars-d-learn
On Thursday, 5 November 2015 at 21:22:18 UTC, TheFlyingFiddle wrote: On Thursday, 5 November 2015 at 11:14:50 UTC, Marc Schütz wrote: ~10x slowdown... I forgot to mention this but I am using DMD 2.069.0-rc2 for x86 windows.

Re: Preventing implicit conversion

2015-11-05 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Thursday, 5 November 2015 at 22:15:46 UTC, Dominikus Dittes Scherkl wrote: On Thursday, 5 November 2015 at 13:23:34 UTC, Adam D. Ruppe wrote: On Thursday, 5 November 2015 at 10:07:30 UTC, Dominikus Dittes Scherkl wrote: ubyte d = b + (ubyte)1; Sorry, should of course be: ubyte d = b +

Re: conver BigInt to string

2015-11-05 Thread Meta via Digitalmars-d-learn
On Thursday, 5 November 2015 at 20:45:45 UTC, TheGag96 wrote: Whoa whoa whoa... This is the first time I've heard about this difference, and I've used .sort plenty of times... That seems like really, REALLY bad design, especially considering the language allows functions to be called without

Re: Unittest in a library

2015-11-05 Thread TheFlyingFiddle via Digitalmars-d-learn
On Friday, 6 November 2015 at 03:59:07 UTC, Charles wrote: Is it possible to have unittest blocks if I'm compiling a library? I've tried having this: test.d: class Classy { unittest { assert(0, "failed test"); } } and then build it with `dmd test.d -lib -unittest` and it

Re: cast(T) documentation

2015-11-05 Thread Carl Sturtivant via Digitalmars-d-learn
On Thursday, 5 November 2015 at 18:52:05 UTC, Ali Çehreli wrote: On 11/05/2015 07:51 AM, Carl Sturtivant wrote: Hello, Is cast(T) documented all in one place somewhere? I'd like to understand exactly what it does and does not do. This is what I can find:

Unittest in a library

2015-11-05 Thread Charles via Digitalmars-d-learn
Is it possible to have unittest blocks if I'm compiling a library? I've tried having this: test.d: class Classy { unittest { assert(0, "failed test"); } } and then build it with `dmd test.d -lib -unittest` and it doesn't fail the unittest.

Re: Align a variable on the stack.

2015-11-05 Thread TheFlyingFiddle via Digitalmars-d-learn
On Friday, 6 November 2015 at 00:43:49 UTC, rsw0x wrote: On Thursday, 5 November 2015 at 23:37:45 UTC, TheFlyingFiddle wrote: On Thursday, 5 November 2015 at 21:24:03 UTC, TheFlyingFiddle wrote: [...] I reduced it further: [...] these run at the exact same speed for me and produce

Re: Align a variable on the stack.

2015-11-05 Thread rsw0x via Digitalmars-d-learn
On Friday, 6 November 2015 at 01:17:20 UTC, TheFlyingFiddle wrote: On Friday, 6 November 2015 at 00:43:49 UTC, rsw0x wrote: On Thursday, 5 November 2015 at 23:37:45 UTC, TheFlyingFiddle wrote: On Thursday, 5 November 2015 at 21:24:03 UTC, TheFlyingFiddle wrote: [...] I reduced it further:

Re: Preventing implicit conversion

2015-11-05 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, November 05, 2015 09:33:39 ixid via Digitalmars-d-learn wrote: > In C++ I can add two shorts together without having to use a cast > to assign the result to one of the two shorts. It just seems > super clunky not to be able to do basic operations on basic types > without casts

Operator implicit conversion difference

2015-11-05 Thread ixid via Digitalmars-d-learn
This may have been overlooked in my other thread so I wanted to ask again: This seems very inconsistent, does a += b not lower to a = a + b? I guess not based on the below: ushort a = ushort.max, b = ushort.max; a += b; // Compiles fine a = a + b; // Error: cannot implicitly

Re: Align a variable on the stack.

2015-11-05 Thread BBasile via Digitalmars-d-learn
On Thursday, 5 November 2015 at 03:52:47 UTC, TheFlyingFiddle wrote: [...] I solved the problem by changing the struct to look like this. align(16) struct Pos { float x = float.nan; float y = float.nan; float z = float.nan; float w = float.nan; } wow that's quite strange. FP

Re: Preventing implicit conversion

2015-11-05 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 5 November 2015 at 10:07:30 UTC, Dominikus Dittes Scherkl wrote: And I want to have small number litterals automatically choosing the smallest fitting type. It does, that's the value range propagation at work. Inside one expression, if the compiler can prove it fits in a smaller