Re: Instantiating a class with different types at runtime

2016-11-28 Thread Marduk via Digitalmars-d-learn
On Sunday, 27 November 2016 at 20:57:28 UTC, Namespace wrote: class Example(L, R) { L _left; R _right; this(L l, R r) { _left = l; _right = r; } } That was fast! But I needed the second reply in order to understand yours. Thanks anyway.

Re: Instantiating a class with different types at runtime

2016-11-28 Thread Marduk via Digitalmars-d-learn
On Sunday, 27 November 2016 at 21:06:58 UTC, ag0aep6g wrote: Turn Example into a template, and add a free function for nice construction: class Example(Type_left, Type_right) { /* ... as you had it ... */ } Example!(L, R) makeExample(L, R)(L x, R y) { return new Example!(L, R)(x,

Re: Parsing a string to instantiate classes at runtime

2016-11-28 Thread Marduk via Digitalmars-d-learn
On Monday, 28 November 2016 at 09:33:08 UTC, Jacob Carlborg wrote: It's possible to bypass the constructors [1]. [1] https://github.com/jacob-carlborg/orange/blob/master/orange/util/Reflection.d#L166 Aha! Interesting. Thanks.

Re: Parsing a string to instantiate classes at runtime

2016-11-28 Thread Marduk via Digitalmars-d-learn
On Sunday, 27 November 2016 at 21:28:52 UTC, ag0aep6g wrote: Ok, that's a hypothetical. It's "if D had a 'dynamic mixin', then we could do fancy things with it." D doesn't have a 'dynamic mixin', so you can't do those fancy things, at least not in the envisioned way. You are right. I

Re: Parsing a string to instantiate classes at runtime

2016-11-27 Thread Marduk via Digitalmars-d-learn
On Sunday, 27 November 2016 at 21:10:30 UTC, ag0aep6g wrote: Can you link that post, please? I can't imagine what "dynamic mixin" could refer to. Sure, it's here: http://forum.dlang.org/post/xmnnsdiuwyjrhkasy...@forum.dlang.org In that thread they also mention Object.factory, but the

Parsing a string to instantiate classes at runtime

2016-11-27 Thread Marduk via Digitalmars-d-learn
Dear all, I would like to write a program that: 1. Receives a string from the UI 2. Parses the string 3. Instantiates classes, whose names are contained in the string, passing parts of the string as constructor arguments. From my experience with other programming languages, I suppose I need

Instantiating a class with different types at runtime

2016-11-27 Thread Marduk via Digitalmars-d-learn
Dear all, I would like to have a kind of template class like the following: class Example { this(Type_left x, Type_right y) { this.left = x; this.right = y; } Type_left left; Type_right right; } Such that at runtime I can instantiate it with different types:

Re: Complex numbers are harder to use than in C

2016-11-22 Thread Marduk via Digitalmars-d-learn
On Sunday, 20 November 2016 at 11:46:04 UTC, Marc Schütz wrote: Try placing it outside the function. Method call syntax doesn't work with nested functions, see here: https://dlang.org/spec/function.html#pseudo-member "The reason why local symbols are not considered by UFCS, is to avoid

Re: Complex numbers are harder to use than in C

2016-11-22 Thread Marduk via Digitalmars-d-learn
On Sunday, 20 November 2016 at 12:08:23 UTC, Ilya Yaroshenko wrote: You can use builtin complex numbers (cfloat/cdouble/creal). The idea of std.complex is wrong . Mir GLAS uses builtin complex numbers and I don't think they will be really deprecated. --Ilya Good to know! The builtin syntax

Re: Complex numbers are harder to use than in C

2016-11-19 Thread Marduk via Digitalmars-d-learn
On Saturday, 19 November 2016 at 12:55:57 UTC, Marc Schütz wrote: On Saturday, 19 November 2016 at 11:11:36 UTC, Nordlöw wrote: On Saturday, 19 November 2016 at 09:38:38 UTC, Marduk wrote: The difference is that D is more verbose. Am I missing something? Can we have C's behaviour in D?

Re: Complex numbers are harder to use than in C

2016-11-19 Thread Marduk via Digitalmars-d-learn
On Saturday, 19 November 2016 at 11:11:36 UTC, Nordlöw wrote: On Saturday, 19 November 2016 at 09:38:38 UTC, Marduk wrote: The difference is that D is more verbose. Am I missing something? Can we have C's behaviour in D? Something like auto I(T)(T im) if (isNumeric!T) { return

Re: Using mixin in array declarations

2016-11-19 Thread Marduk via Digitalmars-d-learn
On Saturday, 19 November 2016 at 13:57:26 UTC, Jonathan M Davis wrote: On Saturday, November 19, 2016 09:46:08 Marduk via Digitalmars-d-learn wrote: [...] A string mixin literally puts the code there. So, doing mixin("int n = 10"); double[n][n] m; is identical to int n = 10; doub

Re: Complex numbers are harder to use than in C

2016-11-19 Thread Marduk via Digitalmars-d-learn
On Saturday, 19 November 2016 at 16:17:08 UTC, Meta wrote: On Saturday, 19 November 2016 at 09:38:38 UTC, Marduk wrote: Dear all, I just discovered D and I am translating some numerical code I wrote in C. I was surprised to learn that there are at least two things that are easier in C than

Re: Array operations with multidimensional arrays

2016-11-19 Thread Marduk via Digitalmars-d-learn
On Saturday, 19 November 2016 at 17:37:58 UTC, John Colvin wrote: On Saturday, 19 November 2016 at 10:20:16 UTC, Marduk wrote: Additionally, I would like to assign 2D sub-arrays of a 3D array, i.e. something like the following: int[3][2][2] a; a[0] = [[2,2], [2,2]]; You have the dimensions

Array operations with multidimensional arrays

2016-11-19 Thread Marduk via Digitalmars-d-learn
In the documentation one can learn how to do array operations with 1D arrays. However, this does not scale up for 2D arrays. For example, the following does not work: int[2][2] a,b; a = [[1,1],[1,1]]; b[][] = a[][]*2; Additionally, I would like to assign 2D sub-arrays of a 3D array, i.e.

Re: Using mixin in array declarations

2016-11-19 Thread Marduk via Digitalmars-d-learn
On Saturday, 19 November 2016 at 09:49:48 UTC, rikki cattermole wrote: On 19/11/2016 10:46 PM, Marduk wrote: In C one can do the following: # define N 10 double M[N][N]; In D I would like to achieve the same result. I tried with: mixin("int N = 10;"); double[N][N] M; but the compiler

Missing features from numpy

2016-11-19 Thread Marduk via Digitalmars-d-learn
In order to make D more useful for writing numerical code I would like to suggest the following extensions for built-in functions: 1. Generate random arrays 2. Arithmetic operations with arrays 3. Mathematical functions evaluated element-wise for arrays I am aware of the existence of

Using mixin in array declarations

2016-11-19 Thread Marduk via Digitalmars-d-learn
In C one can do the following: # define N 10 double M[N][N]; In D I would like to achieve the same result. I tried with: mixin("int N = 10;"); double[N][N] M; but the compiler (DMD) complained with Error: variable N cannot be read at compile time. What am I doing wrong?

Complex numbers are harder to use than in C

2016-11-19 Thread Marduk via Digitalmars-d-learn
Dear all, I just discovered D and I am translating some numerical code I wrote in C. I was surprised to learn that there are at least two things that are easier in C than in D: + Writing complex numbers C: complex double z = 2.0 + 3.0*I; D: auto z = complex(2.0, 3.0); + Arrays of complex