Re: Which version of DMD does GDC 10 target

2020-08-19 Thread Arun via Digitalmars-d-learn

On Thursday, 20 August 2020 at 05:07:28 UTC, H. S. Teoh wrote:
On Thu, Aug 20, 2020 at 04:28:41AM +, Arun via 
Digitalmars-d-learn wrote:

Which version of DMD is GDC 10 based on?


Compile the following D program to find out:

-
static assert(0, "Compiler language version: " ~ 
__VERSION__.stringof);

-

I have this line in a file called langver.d, and whenever the 
exact language version isn't obvious, I compile it to find out 
the version. :-)  (And yes it deliberately asserts instead of 
using pragma(msg) so that I don't have to type -o- or -of- or 
-c or whatever to suppress actual code emission, just 
`$compiler langver.d`.)



--T


Nice trick. Thanks. For the benefit of others, GDC 10 is based on 
DMD 2.076. https://dlang.org/changelog/2.076.0.html


Side note, Using $() is better than `` for subshells, as it makes 
nesting much easier. ;-)


Re: Which version of DMD does GDC 10 target

2020-08-19 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Aug 20, 2020 at 04:28:41AM +, Arun via Digitalmars-d-learn wrote:
> Which version of DMD is GDC 10 based on?

Compile the following D program to find out:

-
static assert(0, "Compiler language version: " ~ __VERSION__.stringof);
-

I have this line in a file called langver.d, and whenever the exact
language version isn't obvious, I compile it to find out the version.
:-)  (And yes it deliberately asserts instead of using pragma(msg) so
that I don't have to type -o- or -of- or -c or whatever to suppress
actual code emission, just `$compiler langver.d`.)


--T


Which version of DMD does GDC 10 target

2020-08-19 Thread Arun via Digitalmars-d-learn

Which version of DMD is GDC 10 based on?

2020-08-19 19:36:17 ~/code/es-v2-d (master)
$ gdc --version
gdc (Ubuntu 10-20200411-0ubuntu1) 10.0.1 20200411 (experimental) 
[master revision 
bb87d5cc77d:75961caccb7:f883c46b4877f637e0fa5025b4d6b5c9040ec566]

Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  
There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A 
PARTICULAR PURPOSE.


2020-08-19 21:24:10 ~/code/es-v2-d (master)
$

LDC is smart enough to print the frontend version.

2020-08-19 21:25:39 ~/code/es-v2-d (master)
$ ldc2 --version
LDC - the LLVM D compiler (1.17.0):
  based on DMD v2.087.1 and LLVM 8.0.1
  built with LDC - the LLVM D compiler (1.17.0)
  Default target: x86_64-unknown-linux-gnu
  Host CPU: haswell
  http://dlang.org - http://wiki.dlang.org/LDC

  Registered Targets:
aarch64- AArch64 (little endian)
aarch64_be - AArch64 (big endian)
arm- ARM
arm64  - ARM64 (little endian)
armeb  - ARM (big endian)
mips   - MIPS (32-bit big endian)
mips64 - MIPS (64-bit big endian)
mips64el   - MIPS (64-bit little endian)
mipsel - MIPS (32-bit little endian)
msp430 - MSP430 [experimental]
nvptx  - NVIDIA PTX 32-bit
nvptx64- NVIDIA PTX 64-bit
ppc32  - PowerPC 32
ppc64  - PowerPC 64
ppc64le- PowerPC 64 LE
riscv32- 32-bit RISC-V
riscv64- 64-bit RISC-V
thumb  - Thumb
thumbeb- Thumb (big endian)
wasm32 - WebAssembly 32-bit
wasm64 - WebAssembly 64-bit
x86- 32-bit X86: Pentium-Pro and above
x86-64 - 64-bit X86: EM64T and AMD64
2020-08-19 21:27:35 ~/code/es-v2-d (master)
$

--
Arun


Re: Disjoint slices of an array as reference

2020-08-19 Thread data pulverizer via Digitalmars-d-learn

On Thursday, 20 August 2020 at 03:47:15 UTC, Paul Backus wrote:

double[][] y;
y ~= x[0..5];


Thanks. I might go for a design like this:

```
struct View(T){
  T* data;
  long[2][] ranges;
}
```
The ranges are were the slices are stored and T* (maybe even 
immutable(T*)) is a pointer is to the start of the original 
array. I'll use an opIndex that calculates the correct index in 
the original array to obtain the right data.




Re: Disjoint slices of an array as reference

2020-08-19 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 20 August 2020 at 02:21:15 UTC, data pulverizer 
wrote:

```
double[] y;
y ~= x[0..5];
y ~= x[9..14];
```

But the act of appending results in array copying - breaks the 
reference with the original array. The only other thing I have 
considered is creating an array of references to each of the 
elements of x I would like but that just seems like overkill.


It would be good to know if there is a more straightforward way 
of doing this type of disjoint selection.


Thanks in advance.


double[][] y;
y ~= x[0..5];
y ~= x[9..14];


Re: Disjoint slices of an array as reference

2020-08-19 Thread data pulverizer via Digitalmars-d-learn
On Thursday, 20 August 2020 at 02:38:33 UTC, data pulverizer 
wrote:


I've been thinking about this some more and I don't think it is 
possible. An array in D is effectively two pointers either side 
of a memory block. When you create a slice you are creating 
another array two pointers somewhere in the same memory block. 
A disjoint slice array would need more than two pointers - 
which is not possible since an array only has 2.


p.s.

An array in D is either two pointers or one pointer and a length 
(I don't know which) - but the point still stands.


Re: Disjoint slices of an array as reference

2020-08-19 Thread data pulverizer via Digitalmars-d-learn
On Thursday, 20 August 2020 at 02:21:15 UTC, data pulverizer 
wrote:
However I would like to have disjoint slices, something like 
this:


```
auto y = x[0..5, 9..14];
```


I've been thinking about this some more and I don't think it is 
possible. An array in D is effectively two pointers either side 
of a memory block. When you create a slice you are creating 
another array two pointers somewhere in the same memory block. A 
disjoint slice array would need more than two pointers - which is 
not possible since an array only has 2.


Disjoint slices of an array as reference

2020-08-19 Thread data pulverizer via Digitalmars-d-learn
I have been trying to create a new array from an existing array 
that is effectively a view on the original array. This can be 
done with slices in D:


```
auto x = [1,  2,  3, 4,  5,
   6,  7,  8, 9,  10,
 11, 12, 13, 14, 15];
auto y = [0..5];
```

y a subset of the x array. If I do:

```
y[0] = 11;
```

x[0] will be modified to 11;

However I would like to have disjoint slices, something like this:

```
auto y = x[0..5, 9..14];
```

Which selects different disjoint parts of the array x, but is not 
allowed on T[]. I have tried something like:


```
double[] y;
y ~= x[0..5];
y ~= x[9..14];
```

But the act of appending results in array copying - breaks the 
reference with the original array. The only other thing I have 
considered is creating an array of references to each of the 
elements of x I would like but that just seems like overkill.


It would be good to know if there is a more straightforward way 
of doing this type of disjoint selection.


Thanks in advance.






Re: BetterC + WASM Update

2020-08-19 Thread kinke via Digitalmars-d-learn

On Wednesday, 19 August 2020 at 21:24:23 UTC, Mike Brown wrote:
I have done some tests, and it appears that classes are 
supported (LDC 1.22.0)?


extern(C++) classes are supported by -betterC. With LDC, D 
classes are supported to some extent too since v1.11, but this 
requires a custom object.d (custom Object base class).


Re: Location of core.internal.traits : CoreUnqual in Dlang GitHub repo

2020-08-19 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Aug 19, 2020 at 10:47:19PM +, data pulverizer via 
Digitalmars-d-learn wrote:
> Hi all,
> 
> I've been looking for where `CoreUnqual` is defined in the Dlang
> repos. I've tried searching in dmd and phobos but only found the
> reference usage in std.traits:
> 
> import core.internal.traits : CoreUnqual;
> 
> I'd like to know where it is defined so I can (attempt to!) study the
> code.
[...]

core.* is defined in druntime. So it should be in:

druntime/src/core/internal/traits.d


T

-- 
All men are mortal. Socrates is mortal. Therefore all men are Socrates.


Location of core.internal.traits : CoreUnqual in Dlang GitHub repo

2020-08-19 Thread data pulverizer via Digitalmars-d-learn

Hi all,

I've been looking for where `CoreUnqual` is defined in the Dlang 
repos. I've tried searching in dmd and phobos but only found the 
reference usage in std.traits:


import core.internal.traits : CoreUnqual;

I'd like to know where it is defined so I can (attempt to!) study 
the code.


Thanks in advance.


Re: Creating a pointer array

2020-08-19 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 19 August 2020 at 21:10:00 UTC, data pulverizer 
wrote:
alias is one of those awesome chameleons in D. The template 
equivalent is


```
template P(T) = T*;
```



Correction ...
```
template P(T){
  alias P = T*;
}
```



Re: BetterC + WASM Update

2020-08-19 Thread aberba via Digitalmars-d-learn

On Wednesday, 19 August 2020 at 21:24:23 UTC, Mike Brown wrote:

Hi all,

I'd like to make a WASM project, and looking into options.


It's scattered in several places including
https://gist.github.com/skoppe/7617ceba6afd67b2e20c6be4f922725d

Are you aware of Spasm?
https://github.com/skoppe/spasm



Re: BetterC + WASM Update

2020-08-19 Thread Adam D. Ruppe via Digitalmars-d-learn

On Wednesday, 19 August 2020 at 21:24:23 UTC, Mike Brown wrote:
I can see that LDC supports WASM output, and I believe this 
requires BetterC to be enabled?


Not really but anything beyond -betterC is still kinda diy right 
now.


So I happened to do port my little tetris game in D to wasm just 
last week, you can read about it here:

http://dpldocs.info/this-week-in-d/Blog.Posted_2020_08_10.html

And it uses classes! But... I cheated. I did a minimal custom 
druntime and library port that has just enough to make that 
little game work. This is a viable approach and can lead to 
reasonably small compiled binaries, but it is kinda immature.


For a full druntime, the author of spasm 
 is working on a port. See his 
fork here:


https://github.com/skoppe/druntime/tree/wasm

I say "full" but it will most likely leave some things out. 
Classes, GC (at least of D memory), and other features all should 
work already if you brave building it yourself, but threads do 
not work and exceptions are only partially supported. Read more 
here: 
https://gist.github.com/skoppe/7617ceba6afd67b2e20c6be4f922725d


That may change in the future as wasm gets more standardized 
capabilities.


Other libraries, including interop with javascript, are not 
covered by the druntime goal, but they will probably get easier 
with this.


I have done some tests, and it appears that classes are 
supported (LDC 1.22.0)? Is it possible to get an update on what 
is and still isn't supported in BetterC?


How did you compile it? You can definitely make classes work but 
as far as I knew it didn't "just work" but maybe that changed 
with the recent release.


After a stable experience, so if you can also let me know if 
these features are beta etc too?


but yeah stability is probably a ways out still. Sebastiaan has 
been busy lately so his druntime work is on pause and mine was 
just one weekend so I'd have something to show off on the blog; I 
have no concrete plans of continuing right now.


Good chance we'll get it all working eventually, but I wouldn't 
expect even beta stability - aside from the diy betterC stuff - 
any time soon. Maybe beta quality by the end of the year. Maybe.


BetterC + WASM Update

2020-08-19 Thread Mike Brown via Digitalmars-d-learn

Hi all,

I'd like to make a WASM project, and looking into options.

I can see that LDC supports WASM output, and I believe this 
requires BetterC to be enabled? The documentation states that 
classes are not supported by BetterC, but its preferable/required 
for me.


I have done some tests, and it appears that classes are supported 
(LDC 1.22.0)? Is it possible to get an update on what is and 
still isn't supported in BetterC?


After a stable experience, so if you can also let me know if 
these features are beta etc too?


Kind regards,
Mike



Re: Creating a pointer array

2020-08-19 Thread data pulverizer via Digitalmars-d-learn

On Wednesday, 19 August 2020 at 20:09:31 UTC, bachmeier wrote:
On Wednesday, 19 August 2020 at 13:03:54 UTC, data pulverizer 
wrote:
Maybe I'm the only one, but I think double*[] is hideous, and 
I'd sure hate for someone not used to D to see it. Alias is 
your friend. I think this is much nicer:


void main() {
alias double* DoublePtr;
DoublePtr[] arr;
auto v = [1.0, 2.0, 3.0];
auto w = [4.0, 5.0, 6.0];
arr ~= [v.ptr, w.ptr];
writeln(arr);
}


I know what you mean. I'm using something like this:

```
alias P(T) = T*;
P!(double)[] arr;
```

alias is one of those awesome chameleons in D. The template 
equivalent is


```
template P(T) = T*;
```

In this case I wonder if there is any difference as far as the 
compiler is concerned?


Re: Creating a pointer array

2020-08-19 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Aug 19, 2020 at 08:09:31PM +, bachmeier via Digitalmars-d-learn 
wrote:
[...]
> Maybe I'm the only one, but I think double*[] is hideous, and I'd sure
> hate for someone not used to D to see it.

IMO, double*[] is absolutely logical. It's a natural consequence of type
syntax.


> Alias is your friend. I think this is much nicer:
> 
> void main() {
> alias double* DoublePtr;
> DoublePtr[] arr;
[...]

IMO, this is far too verbose.  If I had 10 arrays of 10 different types
of pointers, I wouldn't want to write 10 aliases just for that. Plus,
hiding things behind an alias means someone who reads your code has to
look up the alias definition to figure out what it means, whereas if
they see double*[] the exact meaning is immediately obvious.

I'd only use an alias for inordinately-long type names, like function
pointers or delegates with lots of parameters, or verbose type names
like const(int[])[string]. (And even in the latter case, only when the
name occurs frequently.)

But as they say, YMMV. :-)


T

-- 
"A man's wife has more power over him than the state has." -- Ralph Emerson


Re: Creating a pointer array

2020-08-19 Thread bachmeier via Digitalmars-d-learn
On Wednesday, 19 August 2020 at 13:03:54 UTC, data pulverizer 
wrote:

Hi all,

How do you create an array of pointers in D? I tried something 
like


```
double* []y;
```

Or

```
(double*) []y;
```

But I get the error:

```
Error: only one index allowed to index double[]
```

Thanks in advance.


Maybe I'm the only one, but I think double*[] is hideous, and I'd 
sure hate for someone not used to D to see it. Alias is your 
friend. I think this is much nicer:


void main() {
alias double* DoublePtr;
DoublePtr[] arr;
auto v = [1.0, 2.0, 3.0];
auto w = [4.0, 5.0, 6.0];
arr ~= [v.ptr, w.ptr];
writeln(arr);
}


Re: how stdin stream works?

2020-08-19 Thread Flade via Digitalmars-d-learn
On Wednesday, 19 August 2020 at 18:11:23 UTC, Steven 
Schveighoffer wrote:

On 8/19/20 1:44 PM, Flade wrote:
Hi everyone! I'm trying to do error handling (with the try 
block) and when I give a wrong value to the variable (it is an 
integer and I give a non-number value), then It doesn't let me 
re get input. The code:



int x;

bool not_accepted = false;

while (!not_accepted) {

     try {

     write("x: ");

     readf("%d\n", x);

     not_accepted = true;

} catch (Exception msg) {

     writeln("Please give a right coordinate");

     }


Probably readf stops as soon as it encounters an error, meaning 
that your input is still present.


Try instead getting a line via readln, and then trying to read 
that into your expected input.


-Steve


Thanks Steve! I will get the input a string then as you said and 
then I'll try to convert it! Thanks a lot, have a nice day!


Re: how stdin stream works?

2020-08-19 Thread Steven Schveighoffer via Digitalmars-d-learn

On 8/19/20 1:44 PM, Flade wrote:
Hi everyone! I'm trying to do error handling (with the try block) and 
when I give a wrong value to the variable (it is an integer and I give a 
non-number value), then It doesn't let me re get input. The code:



int x;

bool not_accepted = false;

while (!not_accepted) {

     try {

     write("x: ");

     readf("%d\n", x);

     not_accepted = true;

} catch (Exception msg) {

     writeln("Please give a right coordinate");

     }


Probably readf stops as soon as it encounters an error, meaning that 
your input is still present.


Try instead getting a line via readln, and then trying to read that into 
your expected input.


-Steve


how stdin stream works?

2020-08-19 Thread Flade via Digitalmars-d-learn
Hi everyone! I'm trying to do error handling (with the try block) 
and when I give a wrong value to the variable (it is an integer 
and I give a non-number value), then It doesn't let me re get 
input. The code:



int x;

bool not_accepted = false;

while (!not_accepted) {

try {

write("x: ");

readf("%d\n", x);

not_accepted = true;

} catch (Exception msg) {

writeln("Please give a right coordinate");

}


Re: `enum x;` - what is it?

2020-08-19 Thread FeepingCreature via Digitalmars-d-learn

On Wednesday, 19 August 2020 at 14:43:22 UTC, Victor Porton wrote:
On Wednesday, 19 August 2020 at 14:06:16 UTC, Victor Porton 
wrote:

This declaration does compile:

enum x;

But what is it? Is it an equivalent of

enum x { }

?

What in the specification allows this looking a nonsense

enum x;

?


Oh, found: "An empty enum body (For example enum E;) signifies 
an opaque enum - the enum members are unknown."


But what this "unknown" does mean? How "unknown" differs from 
"none" in this context?


The specification is unclear. It does not define the meaning of 
unknown. I will submit a bug report.


It means exactly what it says. The compiler doesn't know what 
members are in the enum. So you can't declare a variable of it, 
you can't use it directly.. you can p much only use it in 
pointers.


Re: `enum x;` - what is it?

2020-08-19 Thread Victor Porton via Digitalmars-d-learn

On Wednesday, 19 August 2020 at 14:06:16 UTC, Victor Porton wrote:

This declaration does compile:

enum x;

But what is it? Is it an equivalent of

enum x { }

?

What in the specification allows this looking a nonsense

enum x;

?


Oh, found: "An empty enum body (For example enum E;) signifies an 
opaque enum - the enum members are unknown."


But what this "unknown" does mean? How "unknown" differs from 
"none" in this context?


The specification is unclear. It does not define the meaning of 
unknown. I will submit a bug report.


Re: `enum x;` - what is it?

2020-08-19 Thread Steven Schveighoffer via Digitalmars-d-learn

On 8/19/20 10:06 AM, Victor Porton wrote:

This declaration does compile:

enum x;

But what is it? Is it an equivalent of

enum x { }

?

What in the specification allows this looking a nonsense

enum x;

?


I use it as a symbol for UDAs.

enum required;

struct S
{
   @required int x;
}

which can then easily be found.

What is it? I have no idea. I'm just using the name.

I think it's treated as a forward declaration. Kind of like

void foo();

-Steve


Re: `enum x;` - what is it?

2020-08-19 Thread FeepingCreature via Digitalmars-d-learn

On Wednesday, 19 August 2020 at 14:06:16 UTC, Victor Porton wrote:

This declaration does compile:

enum x;

But what is it? Is it an equivalent of

enum x { }

?

What in the specification allows this looking a nonsense

enum x;

?


It's an enum type whose members we don't know.

So we can't declare "x var;" but we can declare "x* var;".

It's the enum version of "struct SomeExternCStruct;".


`enum x;` - what is it?

2020-08-19 Thread Victor Porton via Digitalmars-d-learn

This declaration does compile:

enum x;

But what is it? Is it an equivalent of

enum x { }

?

What in the specification allows this looking a nonsense

enum x;

?


Re: Creating a pointer array

2020-08-19 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 19 August 2020 at 13:12:21 UTC, data pulverizer 
wrote:
On Wednesday, 19 August 2020 at 13:08:37 UTC, Adam D. Ruppe 
wrote:
On Wednesday, 19 August 2020 at 13:03:54 UTC, data pulverizer 
wrote:
How do you create an array of pointers in D? I tried 
something like


```
double* []y;
```


I'd write it

double*[] y;

but yeah that's it.


Error: only one index allowed to index double[]


That must be at the usage point where you prolly just need 
parens or something.


Argh, Sorry! The error was from the line before! False alarm. I 
was wandering why something so obvious wasn't working. Thanks 
anyway.


For the record using:

```
(double*)[] data;
```

gives an error

```
Error: found * when expecting . following double
Error: found ) when expecting identifier following double.
Error: found data when expecting )
```

the other version was fine.


Re: Creating a pointer array

2020-08-19 Thread data pulverizer via Digitalmars-d-learn

On Wednesday, 19 August 2020 at 13:08:37 UTC, Adam D. Ruppe wrote:
On Wednesday, 19 August 2020 at 13:03:54 UTC, data pulverizer 
wrote:
How do you create an array of pointers in D? I tried something 
like


```
double* []y;
```


I'd write it

double*[] y;

but yeah that's it.


Error: only one index allowed to index double[]


That must be at the usage point where you prolly just need 
parens or something.


Argh, Sorry! The error was from the line before! False alarm. I 
was wandering why something so obvious wasn't working. Thanks 
anyway.


Re: Creating a pointer array

2020-08-19 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 19 August 2020 at 13:03:54 UTC, data pulverizer 
wrote:
How do you create an array of pointers in D? I tried something 
like


```
double* []y;
```


I'd write it

double*[] y;

but yeah that's it.


Error: only one index allowed to index double[]


That must be at the usage point where you prolly just need parens 
or something.


Creating a pointer array

2020-08-19 Thread data pulverizer via Digitalmars-d-learn

Hi all,

How do you create an array of pointers in D? I tried something 
like


```
double* []y;
```

Or

```
(double*) []y;
```

But I get the error:

```
Error: only one index allowed to index double[]
```

Thanks in advance.


Re: How to sort a multidimensional ndslice?

2020-08-19 Thread 9il via Digitalmars-d-learn

On Tuesday, 18 August 2020 at 13:07:56 UTC, Arredondo wrote:

On Tuesday, 18 August 2020 at 04:07:56 UTC, 9il wrote:

To reorder the columns data according to precomputed index:
auto index = a.byDim!1.map!sum.slice;


Hello Ilya, thanks for the answer!

Unfortunately I can't use it because I don't have (and can't 
define) a sorting index for my columns. I only have a predicate 
`larger(c1, c2)` that compares two columns to decide which one 
is "larger".


Cheers!
Armando.


This should work. But reallocates the data.

/+dub.sdl:
dependency "mir-algorithm" version="~>3.9.24"
+/
import std.stdio;

import mir.array.allocation;
import mir.ndslice;
import mir.ndslice.sorting;

void main() {
auto a = [[1, -1, 3, 2],
  [0, -2, 3, 1]].fuse;

writeln(a);
auto b = a.byDim!1.array;
b.sort!larger;
auto c = b.fuse!1;
writeln(c);
}

auto larger(C)(C u, C v) {
import mir.math.sum : sum;
return sum(u) > sum(v);
}



Re: Since DMD 2.089.0 and later, compiled .exe showing SFX zip and opening with winRar when use resource.

2020-08-19 Thread Kagamin via Digitalmars-d-learn

On Tuesday, 18 August 2020 at 19:01:17 UTC, Marcone wrote:

SFX zip in it is properties: https://i.imgur.com/dH7jl5n.png
Opening with winRar: https://i.imgur.com/s7C9mZn.png


Probably winrar messing with your file manager. Try to uninstall 
ungerister winrar from your file manager or try a different file 
manager.