Re: 2D matrix operation (subtraction)

2020-02-21 Thread septc via Digitalmars-d-learn
On Friday, 21 February 2020 at 08:51:49 UTC, Andre Pany wrote: Hi, I have a 2D double array and I want to subtract from the first column a value, is this possible with matrix operation in D? ``` void main() { double[][] data = [[0.0, 1.4], [1.0, 5.2], [2.0, 0.8]]; // subtract -2.0

Re: BetterC + startsWith

2020-02-21 Thread SrMordred via Digitalmars-d-learn
The issue is that strings aren't input ranges in betterC [1], due to autodecoding. Normally you'd work around this using std.utf.byCodeUnit, but that's currently broken, because std.utf attempts to import core.exception.UnicodeException from druntime at module scope [2], causing any betterC

Re: BetterC + startsWith

2020-02-21 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 22 February 2020 at 02:01:25 UTC, SrMordred wrote: //-betterC import core.stdc.stdio; import std.algorithm; void main(){ printf( "%d\n",startsWith("a","b") ); } //Fails to compile with betterC, dmd/ldc2 last versions. Any reason for not work with betterC or should i file the

BetterC + startsWith

2020-02-21 Thread SrMordred via Digitalmars-d-learn
//-betterC import core.stdc.stdio; import std.algorithm; void main(){ printf( "%d\n",startsWith("a","b") ); } //Fails to compile with betterC, dmd/ldc2 last versions. Any reason for not work with betterC or should i file the issue ? (Find this on a bindbc lib, so i think that it may have

Re: 2D matrix operation (subtraction)

2020-02-21 Thread jmh530 via Digitalmars-d-learn
On Friday, 21 February 2020 at 14:43:37 UTC, jmh530 wrote: [snip] Actually, I kind of prefer the relevant line as x.byDim!1[0].each!"a -= 2"; which makes it a little clearer that you can easily change [0] to [1] to apply each to the second column instead.

Re: Conditional Attributes

2020-02-21 Thread Marcel via Digitalmars-d-learn
On Thursday, 20 February 2020 at 17:41:54 UTC, Dennis wrote: On Tuesday, 18 February 2020 at 17:11:55 UTC, Marcel wrote: Say I have a struct where every member function can either be static or not depending on a template parameter. Is there a simple way to do this? The best I can think of

Re: Conditional Attributes

2020-02-21 Thread Marcel via Digitalmars-d-learn
On Friday, 21 February 2020 at 01:41:21 UTC, Steven Schveighoffer wrote: On 2/18/20 12:11 PM, Marcel wrote: Hello! Say I have a struct where every member function can either be static or not depending on a template parameter. Is there a simple way to do this? Like, for example: struct

Re: is(typeof(...)) vs __traits(compiles, ...)

2020-02-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/21/20 5:15 AM, drug wrote: Currently this code does not compiles: ``` unittest {     class MyClass     {     T opCall(T)(T p)     {     return p;     }     }     import std.container.array : Array;     Array!MyClass arr; } ``` but if you comment out `opCall`

Re: 2D matrix operation (subtraction)

2020-02-21 Thread jmh530 via Digitalmars-d-learn
On Friday, 21 February 2020 at 11:53:02 UTC, Ali Çehreli wrote: [snip] auto byColumn(R)(R range, size_t n) { return Column!R(range, n); } mir has byDim for something similar (numir also has alongDim). This is how you would do it: import mir.ndslice; void main() { auto x = [0.0, 1.4,

Re: 2D matrix operation (subtraction)

2020-02-21 Thread Andre Pany via Digitalmars-d-learn
On Friday, 21 February 2020 at 11:53:02 UTC, Ali Çehreli wrote: On 2/21/20 12:51 AM, Andre Pany wrote: Hi, I have a 2D double array and I want to subtract from the first column a value, is this possible with matrix operation in D? ``` void main() {     double[][] data = [[0.0, 1.4], [1.0,

Re: GtkD crash

2020-02-21 Thread mark via Digitalmars-d-learn
Thanks for your question, it led me to focus on the Label and now I've solved the problem. I thought that onChangeState was never called before the Label was constructed, but it turns out it is called before. So now I use: if (statusLabel !is null)

Re: 2D matrix operation (subtraction)

2020-02-21 Thread Ali Çehreli via Digitalmars-d-learn
On 2/21/20 12:51 AM, Andre Pany wrote: Hi, I have a 2D double array and I want to subtract from the first column a value, is this possible with matrix operation in D? ``` void main() {     double[][] data = [[0.0, 1.4], [1.0, 5.2], [2.0, 0.8]];     // subtract -2.0 from the first column

Re: betterC CTFE nested switch

2020-02-21 Thread Stefan Koch via Digitalmars-d-learn
On Friday, 21 February 2020 at 09:03:26 UTC, Abby wrote: On Monday, 17 February 2020 at 19:02:50 UTC, Stefan Koch wrote: Sorry I just realized I never published the code. I am going to add it to ctfeutils. Hi Stefan, I'm sorry to bother you, I just wanted to kindly ask if you would upload

is(typeof(...)) vs __traits(compiles, ...)

2020-02-21 Thread drug via Digitalmars-d-learn
Currently this code does not compiles: ``` unittest { class MyClass { T opCall(T)(T p) { return p; } } import std.container.array : Array; Array!MyClass arr; } ``` but if you comment out `opCall` in MyClass this code compiles. This is

Re: State of MIPS

2020-02-21 Thread April via Digitalmars-d-learn
Thanks all, much appreciated!

Re: GtkD crash

2020-02-21 Thread Ron Tarrant via Digitalmars-d-learn
On Friday, 21 February 2020 at 08:55:43 UTC, mark wrote: statusLabel.setText(message); // BUG Where is statusLabel instantiated? Other than that, I see nothing wrong here.

Re: betterC CTFE nested switch

2020-02-21 Thread Abby via Digitalmars-d-learn
On Monday, 17 February 2020 at 19:02:50 UTC, Stefan Koch wrote: Sorry I just realized I never published the code. I am going to add it to ctfeutils. Hi Stefan, I'm sorry to bother you, I just wanted to kindly ask if you would upload the formatter to ctfeutils on github it would help me alot.

GtkD crash

2020-02-21 Thread mark via Digitalmars-d-learn
I'm porting a simple game to GtkD to learn the library and more about D. Unfortunately, I've hit a show-stopping crash. I have a subclass of ApplicationWindow which has this method: private void onChangeState(int score, Board.State state) { import std.format: format;

2D matrix operation (subtraction)

2020-02-21 Thread Andre Pany via Digitalmars-d-learn
Hi, I have a 2D double array and I want to subtract from the first column a value, is this possible with matrix operation in D? ``` void main() { double[][] data = [[0.0, 1.4], [1.0, 5.2], [2.0, 0.8]]; // subtract -2.0 from the first column for every value // Expected output