DLang Tour : Functions as arguments

2017-12-27 Thread Tony via Digitalmars-d-learn
On this page: https://tour.dlang.org/tour/en/basics/delegates there is: void doSomething(int function(int, int) doer) { // call passed function doer(5,5); } doSomething(add); // use global function `add` here //

Is this an okay representation of a dynamically sized Matrix, to be used for HMM matrices m = (A,B)

2017-12-27 Thread Enjoys Math via Digitalmars-d-learn
Code: module matrix; import std.array; struct Matrix(E) { private: E[][]; this() { } void deleteRow(int i) { E = E[0..i] ~ E[i..$]; } void deleteColumn(int j) { for (int i=0; i < E.length; i++) { E[i] = E[i][0..j] ~ E[i][j..$];

Re: How do I set a class member value by its name in a string?

2017-12-27 Thread Biotronic via Digitalmars-d-learn
On Wednesday, 27 December 2017 at 21:42:53 UTC, Mengu wrote: On Wednesday, 27 December 2017 at 21:39:49 UTC, Mengu wrote: On Wednesday, 27 December 2017 at 20:54:17 UTC, bitwise wrote: [...] there's also a simple workaround for fields with the same type: https://run.dlang.io/is/dsFajq

Re: How do I set a class member value by its name in a string?

2017-12-27 Thread Mengu via Digitalmars-d-learn
On Wednesday, 27 December 2017 at 21:39:49 UTC, Mengu wrote: On Wednesday, 27 December 2017 at 20:54:17 UTC, bitwise wrote: [...] there's also a simple workaround for fields with the same type: https://run.dlang.io/is/dsFajq import std.stdio; struct S { int x; int y; } auto

Re: How do I set a class member value by its name in a string?

2017-12-27 Thread Mengu via Digitalmars-d-learn
On Wednesday, 27 December 2017 at 20:54:17 UTC, bitwise wrote: On Wednesday, 27 December 2017 at 20:04:29 UTC, Marc wrote: I'd like to set the members of a class by its name at runtime, I would do something like this: __traits(getMember, myClass, name) = value; but since name is only know

Re: How do I set a class member value by its name in a string?

2017-12-27 Thread bitwise via Digitalmars-d-learn
On Wednesday, 27 December 2017 at 20:04:29 UTC, Marc wrote: I'd like to set the members of a class by its name at runtime, I would do something like this: __traits(getMember, myClass, name) = value; but since name is only know at runtime, I can't use __traits(). What's a workaround for

Re: BitArray shift left/right confusion.

2017-12-27 Thread Biotronic via Digitalmars-d-learn
On Wednesday, 27 December 2017 at 18:08:19 UTC, Bastiaan Veelo wrote: I suppose the following is not a bug, but confusing it is: ``` void main() { import std.stdio; import std.bitmanip; BitArray ba = [1, 1, 1, 1, 1, 1, 1, 1]; writeln(ba);// [1, 1, 1, 1, 1, 1, 1, 1]

Re: How do I set a class member value by its name in a string?

2017-12-27 Thread Benjamin Thaut via Digitalmars-d-learn
On Wednesday, 27 December 2017 at 20:04:29 UTC, Marc wrote: I'd like to set the members of a class by its name at runtime, I would do something like this: __traits(getMember, myClass, name) = value; but since name is only know at runtime, I can't use __traits(). What's a workaround for

How do I set a class member value by its name in a string?

2017-12-27 Thread Marc via Digitalmars-d-learn
I'd like to set the members of a class by its name at runtime, I would do something like this: __traits(getMember, myClass, name) = value; but since name is only know at runtime, I can't use __traits(). What's a workaround for this?

BitArray shift left/right confusion.

2017-12-27 Thread Bastiaan Veelo via Digitalmars-d-learn
I suppose the following is not a bug, but confusing it is: ``` void main() { import std.stdio; import std.bitmanip; BitArray ba = [1, 1, 1, 1, 1, 1, 1, 1]; writeln(ba);// [1, 1, 1, 1, 1, 1, 1, 1] ba >>= 4; // right shift writeln(ba);// [1, 1,

Re: float.max + 1.0 does not overflow

2017-12-27 Thread Benjamin Thaut via Digitalmars-d-learn
On Wednesday, 27 December 2017 at 13:40:28 UTC, rumbu wrote: Is that normal? use std.math; float f = float.max; f += 1.0; assert(IeeeFlags.overflow) //failure assert(f == float.inf) //failure, f is in fact float.max On the contrary, float.max + float.max will overflow. The behavior is the

float.max + 1.0 does not overflow

2017-12-27 Thread rumbu via Digitalmars-d-learn
Is that normal? use std.math; float f = float.max; f += 1.0; assert(IeeeFlags.overflow) //failure assert(f == float.inf) //failure, f is in fact float.max On the contrary, float.max + float.max will overflow. The behavior is the same for double and real.

Re: Does to!(string)(char[]) do any memory allocation on conversion?

2017-12-27 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, December 25, 2017 15:00:19 aliak via Digitalmars-d-learn wrote: > On Monday, 25 December 2017 at 14:12:32 UTC, Marc wrote: > > Does to!(string)(char[]) do any memory allocation on conversion > > or is this similar to a cast or what else? > > As said it calls idup, which calls

Re: What is 'scope' in function parameter?

2017-12-27 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, December 25, 2017 12:11:58 Mike Franklin via Digitalmars-d-learn wrote: > But we need people to use -dip25 and -dip1000 and provide > feedback, submit bug reports, etc.. so we can move the > implementation forward. Anyone who wishes to play around with those flags is free to do so,