Re: Doubt - Static multidimension arrays

2016-01-19 Thread tsbockman via Digitalmars-d-learn
On Tuesday, 19 January 2016 at 07:46:59 UTC, Mike Parker wrote: It's not that he's seeing them as special, it's just that indexing them in D is different than doing so in C or C++. It trips a lot of people up. No, the difference is actually in C/C++ 's declaration syntax; the way that

Re: Unions and Structs

2016-01-19 Thread Russel Winder via Digitalmars-d-learn
On Mon, 2016-01-18 at 21:50 +0100, Jacob Carlborg via Digitalmars-d- learn wrote: > On 2016-01-18 19:11, Russel Winder via Digitalmars-d-learn wrote: > > > It seems DStep is producing somewhat strange D from complicated C > > unions. > > Please report any issues to [1] with a test case. C code,

Re: foreach( i, e; a) vs ndslice

2016-01-19 Thread Ilya Yaroshenko via Digitalmars-d-learn
On Monday, 18 January 2016 at 23:33:53 UTC, Jay Norwood wrote: I'm playing with the example below. I noticed a few things. 1. The ndslice didn't support the extra index, i, in the foreach, so had to add extra i,j. 2. I couldn't figure out a way to use sliced on the original 'a' array. Is

Can't add ubytes together to make a ubyte... bug or feature?

2016-01-19 Thread Soviet Friend via Digitalmars-d-learn
I just attempted to add one ubyte to another and store the result in a ubyte but apparently ubytes get converted to ints when being added... and converting what becomes an int becomes impossible to store in a ubyte without an explicit cast... ubyte a, b; ubyte c = a + b; // Error: cannot

Re: Doubt - Static multidimension arrays

2016-01-19 Thread tsbockman via Digitalmars-d-learn
On Tuesday, 19 January 2016 at 19:14:30 UTC, alb wrote: So guys: Ali, Mike Parker and tsbockman thanks for all your explanation, in fact looking now I and after making some tests I really got it. So: int[2]a1; // Array of 2 elements of type int int[2][5] a2; // Array of 2 elements

Re: Can't add ubytes together to make a ubyte... bug or feature?

2016-01-19 Thread Daniel Kozak via Digitalmars-d-learn
Soviet Friend píše v Út 19. 01. 2016 v 22:12 +: > I just attempted to add one ubyte to another and store the result  > in a ubyte but apparently ubytes get converted to ints when being  > added... and converting what becomes an int becomes impossible to  > store in a ubyte without an explicit

Re: Doubt - Static multidimension arrays

2016-01-19 Thread alb via Digitalmars-d-learn
So guys: Ali, Mike Parker and tsbockman thanks for all your explanation, in fact looking now I and after making some tests I really got it. So: int[2]a1; // Array of 2 elements of type int int[2][5] a2; // Array of 2 elements of type int divided in 5 rows writeln(a2[0]); // =

Re: core.time Duration how to get units in double/float format?

2016-01-19 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, January 19, 2016 14:07:50 Borislav Kosharov via Digitalmars-d-learn wrote: > On Monday, 18 January 2016 at 12:46:31 UTC, Jonathan M Davis > wrote: > > In general, using floating point values with time is an > > incredibly bad idea. It can certainly make sense when printing > > stuff

Re: core.time Duration how to get units in double/float format?

2016-01-19 Thread Borislav Kosharov via Digitalmars-d-learn
On Tuesday, 19 January 2016 at 15:25:58 UTC, wobbles wrote: On Tuesday, 19 January 2016 at 14:07:50 UTC, Borislav Kosharov wrote: On Monday, 18 January 2016 at 12:46:31 UTC, Jonathan M Davis wrote: [...] I want to use float time in a game where I call the update method passing the delta

Re: Functions that return type

2016-01-19 Thread Timon Gehr via Digitalmars-d-learn
On 01/17/2016 08:09 PM, data pulverizer wrote: On Sunday, 17 January 2016 at 02:08:06 UTC, Timon Gehr wrote: On 01/16/2016 11:50 PM, data pulverizer wrote: I guess the constraints are that of a static language. (This is not true.) Could you please explain? E.g., a few of the systems

Re: Partial application of compile time args type deduction

2016-01-19 Thread Ali Çehreli via Digitalmars-d-learn
On 01/19/2016 03:37 PM, QAston wrote: Hi, I have the following code: auto appendMapped(alias f, R, T)(R r, T elem) { r ~= f(elem); return r; } int minus(int i) { return -i; } unittest { int[] ar; // here I do partial application of minus function alias

Re: Can't add ubytes together to make a ubyte... bug or feature?

2016-01-19 Thread Chris Wright via Digitalmars-d-learn
On Tue, 19 Jan 2016 23:32:57 +0100, Daniel Kozak wrote: > Soviet Friend píše v Út 19. 01. 2016 v 22:12 +: >> I just attempted to add one ubyte to another and store the result in a >> ubyte but apparently ubytes get converted to ints when being added... >> and converting what becomes an int

Re: Partial application of compile time args type deduction

2016-01-19 Thread Ali Çehreli via Digitalmars-d-learn
On 01/19/2016 04:22 PM, QAston wrote: On Wednesday, 20 January 2016 at 00:12:16 UTC, Ali Çehreli wrote: On 01/19/2016 03:37 PM, QAston wrote: Hi, I have the following code: auto appendMapped(alias f, R, T)(R r, T elem) { r ~= f(elem); return r; } int minus(int i) { return -i;

Re: Can't add ubytes together to make a ubyte... bug or feature?

2016-01-19 Thread Ali Çehreli via Digitalmars-d-learn
On 01/19/2016 02:12 PM, Soviet Friend wrote: > ubytes get converted to ints when being added... It's a common feature involving all integral type in languages like C, C++, and D: https://dlang.org/spec/type.html#integer-promotions > On the topic of complaining about casting... array

Re: Functions that return type

2016-01-19 Thread blm768 via Digitalmars-d-learn
On Sunday, 17 January 2016 at 02:08:06 UTC, Timon Gehr wrote: On 01/16/2016 11:50 PM, data pulverizer wrote: I guess the constraints are that of a static language. (This is not true.) I'm playing with the design of such a language myself. Basically, anything can create/use/return type

Re: core.time Duration how to get units in double/float format?

2016-01-19 Thread Borislav Kosharov via Digitalmars-d-learn
On Monday, 18 January 2016 at 12:46:31 UTC, Jonathan M Davis wrote: In general, using floating point values with time is an incredibly bad idea. It can certainly make sense when printing stuff out, but using it in calculations is just asking for trouble given all of the unnecessary imprecision

Re: Doubt - Static multidimension arrays

2016-01-19 Thread Mike Parker via Digitalmars-d-learn
On Tuesday, 19 January 2016 at 08:27:56 UTC, tsbockman wrote: The only relevant difference between the two, is that the order of the row and column specification is swapped in *the declaration*, not when indexing. Newcomers to D tend to think in terms of C when they declare arrays, so the

Re: core.time Duration how to get units in double/float format?

2016-01-19 Thread wobbles via Digitalmars-d-learn
On Tuesday, 19 January 2016 at 14:07:50 UTC, Borislav Kosharov wrote: On Monday, 18 January 2016 at 12:46:31 UTC, Jonathan M Davis wrote: [...] I want to use float time in a game where I call the update method passing the delta time as float seconds. It's more easy to multiply the dt with a

Re: Doubt - Static multidimension arrays

2016-01-19 Thread tsbockman via Digitalmars-d-learn
On Tuesday, 19 January 2016 at 13:00:19 UTC, Mike Parker wrote: Newcomers to D tend to think in terms of C when they declare arrays, so the confusion comes when they find out they have to index it in a way that is the reverse of what they expect. Yes, it's because the declaration syntax is

Re: Doubt - Static multidimension arrays

2016-01-19 Thread Mike Parker via Digitalmars-d-learn
On Tuesday, 19 January 2016 at 14:58:51 UTC, tsbockman wrote: Anyway, I'll give it a rest now. I thought this way of looking at it would make things easier to understand, but I guess not... In my experience, it's focusing on the types in the D array syntax, rather than the actual ordering,

Re: Can't add ubytes together to make a ubyte... bug or feature?

2016-01-19 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 19 January 2016 at 22:12:06 UTC, Soviet Friend wrote: I don't care if my computer needs to do math on a 4 byte basis, I'm not writing assembly. x86 actually doesn't need to do math that way, if you were writing assembly, it would just work. This is just an annoying rule brought

Partial application of compile time args type deduction

2016-01-19 Thread QAston via Digitalmars-d-learn
Hi, I have the following code: auto appendMapped(alias f, R, T)(R r, T elem) { r ~= f(elem); return r; } int minus(int i) { return -i; } unittest { int[] ar; // here I do partial application of minus function alias appendMinus(S,T) =

Re: Partial application of compile time args type deduction

2016-01-19 Thread QAston via Digitalmars-d-learn
On Wednesday, 20 January 2016 at 00:12:16 UTC, Ali Çehreli wrote: On 01/19/2016 03:37 PM, QAston wrote: Hi, I have the following code: auto appendMapped(alias f, R, T)(R r, T elem) { r ~= f(elem); return r; } int minus(int i) { return -i; } unittest { int[] ar;