save and load a 2d array to a file

2022-04-18 Thread Chris Katko via Digitalmars-d-learn

D
struct map_t{
int data[50][50];
} map;

//save
std.file.write("save.map", map.data); // compiles

//load
map.data = std.file.read("save.map", map.data.sizeof); // error

main.d(536): Error: cannot implicitly convert expression 
`read("save.map", 2500LU)` of type `void[]` to `ubyte[50][]`



I'm guessing here, that internally we've got an array of arrays 
(which means array of pointers), and D doesn't know how to split 
by one of the axis. So how do I do that? If I know it's exactly 
packed as it was before, can I smash it somehow by direct writing 
a bunch of ubytes?


What is the 'smash' way to do it, and if better, what's the 
elegant way to do it? (In case I need either going forward).


Thanks,
--Chris


Re: DUB issues

2022-04-18 Thread Marcone via Digitalmars-d-learn
The dub creator shouldn't even remember creating this anymore. It 
makes me sad when I see that things in D are old, forgotten, 
outdated, abandoned. D is the best programming language in the 
world. But nobody appreciates it. It makes me sad when I see the 
repositories for over 10 years without an update, most things in 
dub are for Dlang 1 still.


Re: Can Enums be integral types?

2022-04-18 Thread Era Scarecrow via Digitalmars-d-learn

On Sunday, 17 April 2022 at 18:25:32 UTC, Bastiaan Veelo wrote:

On Saturday, 16 April 2022 at 11:39:01 UTC, Manfred Nowak wrote:
In the specs(17) about enums the word "integral" has no match. 
But because the default basetype is `int`, which is an 
integral type, enums might be integral types whenever their 
basetype is an integral type.


The reason is in [17.1.5](https://dlang.org/spec/enum.html):  
“EnumBaseType types cannot be implicitly cast to an enum type.”


The 'integral' or numeric value is used for uniqueness, not for 
math or some other effect, anymore than a primary int key in a 
SQL database is used to identify someone's birthday. (*Maybe 
that's the wrong analogy, comparing apples to oranges perhaps*).


 We will indeed have to explicitly cast to get around it, though 
it doesn't mean much. If you have say true=1, blue=2, what is 
blue+true? Numerically it's 3 but there's no value 3, or value 3 
could be say potato...


 Few years ago i made an enum type flag/library storage library, 
which would take an int and convert to N flags, or N flags to an 
int for compactly storing said values. But it's been quite a 
while, though i do recall a lot of casting and binary 
AND/OR/XOR's involved for it to work the way it was intended.


Re: Static struct initialization syntax behavior & it being disabled upon adding a constructor

2022-04-18 Thread Ali Çehreli via Digitalmars-d-learn

On 4/18/22 09:17, Ali Çehreli wrote:

> shared static ~this():   0
> static ~this():   0
>~this():   8

Apologies for omitting 'scope' statements:

   scope(exit): 34
scope(success):  6
scope(failure):  8

Ali



Re: Install D lang on Windows 10 : an installation step by step tutorial made by a beginner who loves D !

2022-04-18 Thread SMAOLAB via Digitalmars-d-learn

On Monday, 18 April 2022 at 16:20:38 UTC, SMAOLAB wrote:
After I noticed that if you don't install VisualD and Microsoft 
Visual Studio you may have issues (you don't see the DMD 
extension for instance, the PATH is not set)


 you should read :

After I noticed that if you don't install **in the right order** 
VisualD and Microsoft Visual Studio you may have issues (you 
don't see the DMD extension for instance, the PATH is not set).


sorry :-)


Re: Install D lang on Windows 10 : an installation step by step tutorial made by a beginner who loves D !

2022-04-18 Thread SMAOLAB via Digitalmars-d-learn

Dear Community,
Thanks for your reactions/feedbacks.


What went wrong when you used the DMD installer?


Nothing really, the thing that went really wrong is the Microsoft 
Visual Studio (which licence I should install to get my D / Dplug 
program work). Next, I use LDC rather than DMD (but this only for 
my goal to develop DPLUG codes).


After I noticed that if you don't install VisualD and Microsoft 
Visual Studio you may have issues (you don't see the DMD 
extension for instance, the PATH is not set)


On Monday, 18 April 2022 at 09:04:24 UTC, Dennis wrote:
I don't see the guide (explicitly) installing git, but I recall 
dub needing it to install packages. Is that covered?

Yeap, I will add it and update the D-idioms.
Thanks !


Re: Static struct initialization syntax behavior & it being disabled upon adding a constructor

2022-04-18 Thread Ali Çehreli via Digitalmars-d-learn

On 4/17/22 17:35, Ali Çehreli wrote:

> compared to C++, the amount of constructor, destructor, copy
> constructor, etc. that I do *not* write in D is very liberating to me.
> It feels like I just write what is needed and it mostly just works.

The following is a quick and dirty grep-based stats from a largish 
successful project that implements multiple libraries and binaries. The 
figures are numbers of times each construct appears in source code:


   struct: 231
interface:   3
class:  12
union:   0

  this(/* ... */):  72 [1]
 shared static this():   8
static this():   1 [2]

shared static ~this():   0
   static ~this():   0
  ~this():   8

   this(this):   0 [3]

[1] Most operations in most constructors are trivial assignments to members.

[2] It contains just an enforce expression to ensure the environment is 
as expected. (It is an oversight that this is not a 'shared static this' 
as well.)


[3] There are no copy constructors either because the project started 
with an older compiler.


It is remarkable that I did not implement a single copy or move behavior 
ever. Compare that to countless C++ articles on attempting to teach how 
to deal with fundamental operations of object. Forgotten to be called or 
not, there are no 'move' (which does not move in C++) or 'forward' 
(which does not forward in C++) expressions at all.


What a price the programming community keeps on paying just because 
their powerful programming language was there first...


Ali



Re: Install D lang on Windows 10 : an installation step by step tutorial made by a beginner who loves D !

2022-04-18 Thread Anonymouse via Digitalmars-d-learn

On Monday, 18 April 2022 at 09:04:24 UTC, Dennis wrote:
What went wrong when you used the DMD installer? Installing 
Visual Studio should not be necessary, since DMD ships with the 
lld linker and MinGW Windows import libraries. If it doesn't 
work out of the box, it should be fixed.


"Download and install Visual Studio 2019" is preselected in the 
installer, so you have to know to pick "Install VC2010 
redistributables to use it with the MinGW Platform libraries" to 
opt out. I guess it's not *necessary* but it certainly encourages 
new users to install it.


(I'd subjectively argue the VC2010/MinGW option should be the 
default, the whole of VS2019 is a very hefty download and not my 
IDE of choice.)




Re: Why do immutable variables need reference counting?

2022-04-18 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Apr 18, 2022 at 12:55:26PM +, wjoe via Digitalmars-d-learn wrote:
> On Sunday, 17 April 2022 at 14:14:37 UTC, H. S. Teoh wrote:
> > Not entirely true. See paragraph 3 in:
> > 
> > https://dlang.org/spec/unittest.html
> > 
> > and 10.24.11.3 in:
> > 
> > https://dlang.org/spec/expression.html#assert_expressions
[...]
> Thanks. Either I missed that the last time I checked or it wasn't
> there ;)
> But the interesting question is: does the compiler go out of its way
> to make that happen or is it just paragraphs written in the spec?

My guess: the spec was amended after the fact. :-D


T

-- 
Those who don't understand D are condemned to reinvent it, poorly. -- Daniel N


Re: Static struct initialization syntax behavior & it being disabled upon adding a constructor

2022-04-18 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Apr 18, 2022 at 08:22:26AM +, cc via Digitalmars-d-learn wrote:
> On Monday, 18 April 2022 at 03:21:30 UTC, H. S. Teoh wrote:
> > Structs in D ought to be treated like "glorified ints", as Andrei
> > puts it. If you need complex ctors and complex methods, that's a
> > sign you should be using a class instead.
> 
> Unless you're having a nice quiet get-together with friends, and you
> don't want to invite the GC, the biggest loudest party animal on the
> block.  Phobos's RefCounted seems to stretch the definition of
> "glorified ints"..

"Glorified int" includes pass-by-value types like pointers. Pointers /
references wrapped in a struct is one of the more powerful D constructs
that lets you do some pretty neat things.  (Just don't expect it to
behave like C++, lol. :-P)


T

-- 
Debian GNU/Linux: Cray on your desktop.


Re: Static struct initialization syntax behavior & it being disabled upon adding a constructor

2022-04-18 Thread zjh via Digitalmars-d-learn

On Monday, 18 April 2022 at 13:21:44 UTC, zjh wrote:


I hope that d can support it like `C++`.



`Struct` and `class` behavior is inconsistent.
`Constructors` sometimes have initialize behavior.
If D doesn't think about `C++` users, `C++` users feel too 
troublesome, can't understand, and the cognitive burden is too 
heavy.






Re: DUB issues

2022-04-18 Thread Mike Parker via Digitalmars-d-learn

On Monday, 18 April 2022 at 05:27:32 UTC, Danny Arends wrote:


Any ideas how to get into contact/fix this issue ?


I've emailed Sönke and pointed him to this thread.


Re: Static struct initialization syntax behavior & it being disabled upon adding a constructor

2022-04-18 Thread zjh via Digitalmars-d-learn

On Sunday, 17 April 2022 at 15:13:29 UTC, HuskyNator wrote:

This is a twofold question, along the example code below:



The `default constructor` of `struct` is very convenient to use.
I hope that d can support it like `C++`.



Re: Static struct initialization syntax behavior & it being disabled upon adding a constructor

2022-04-18 Thread user1234 via Digitalmars-d-learn

On Monday, 18 April 2022 at 10:26:16 UTC, HuskyNator wrote:
On a sidenote, I'm surprised D did not choose 0 as the default 
floating value. Doesn't almost every language do this? I 
understand the thinking behind it, but when the type one uses 
in a template influences the behavior of the code, that seems 
like a pretty big red flag to me. (Any non-floating type 
defaults to 0, but using floats/doubles suddenly introduces 
NaN, surely I'm not the only one that sees a problem with this 
) Especially when it's basically a standard 0 is used for 
this. Sorry for the rant.


Let me explain the why:

D default initialization is not designed to replace user-defined 
initialization, it's rather made to make bugs related to 
non-initialized variables stable, e.g not UB.


The easiest way to get that is to think to references and 
pointers. A random garbage value pointed by an alloca may work to 
some point (e.g access to member), if it's set to `null` right 
after the alloca then you have a stable segfault that always 
happens at the same time and is easy to debug.


Similarly, for floating point numbers the D designers considered 
that `NaN` was the best choice because FP operations will not 
wrongly appear valid when starting operations with NaN.


With integral types, this system does not work as well, as `0` 
doesn't create bugs as easily as `null` and `NaN`. The confusion 
about the real role of default initialization comes from integral 
types I believe.


Re: Why do immutable variables need reference counting?

2022-04-18 Thread wjoe via Digitalmars-d-learn

On Sunday, 17 April 2022 at 14:14:37 UTC, H. S. Teoh wrote:

Not entirely true. See paragraph 3 in:

https://dlang.org/spec/unittest.html

and 10.24.11.3 in:

https://dlang.org/spec/expression.html#assert_expressions


T


Thanks. Either I missed that the last time I checked or it wasn't 
there ;)
But the interesting question is: does the compiler go out of its 
way to make that happen or is it just paragraphs written in the 
spec?




Re: Static struct initialization syntax behavior & it being disabled upon adding a constructor

2022-04-18 Thread cc via Digitalmars-d-learn

On Monday, 18 April 2022 at 10:26:16 UTC, HuskyNator wrote:
On a sidenote, I'm surprised D did not choose 0 as the default 
floating value. Doesn't almost every language do this? I 
understand the thinking behind it, but when the type one uses 
in a template influences the behavior of the code, that seems 
like a pretty big red flag to me. (Any non-floating type 
defaults to 0, but using floats/doubles suddenly introduces 
NaN, surely I'm not the only one that sees a problem with this 
) Especially when it's basically a standard 0 is used for 
this. Sorry for the rant.


I agree, it's a hiccup.  I have at times intentionally 
initialized a float as NaN so that I can identify later whether 
an appropriate value has been assigned, but I've never seen the 
need to have this be the default behavior when integer types 
always init to 0 (more specifically, init to a MODIFYABLE value). 
 In game design I have tons upon tons of floats that all [should] 
start initialized to zero.  I can add 4 to a declared but 
not-assigned-to int and it'll be 4, a float remains NaN.  Having 
to manually declare appropriate init values to each one doesn't 
aid me in detecting "bugs".  If I had an int that was supposed to 
default to 10 instead of 0 it would still be a bug if I forgot to 
specify that, tripping me up for falsely assuming floats would 
start at 0 doesn't aid my workflow in any way.  The whole "you 
should pay more attention to what you're initializing, o buggy 
programmer you" philosophy seems like something that should be 
reserved for pointers and reference types, not basic numeric 
data.  It's probably set in stone by this point though and too 
late to change.


Ten years ago, almost to the day:
https://forum.dlang.org/thread/thsjtreegdwcgbazh...@forum.dlang.org

The reasoning still feels flimsy and stubborn.


Re: Static struct initialization syntax behavior & it being disabled upon adding a constructor

2022-04-18 Thread HuskyNator via Digitalmars-d-learn

On Monday, 18 April 2022 at 03:21:30 UTC, H. S. Teoh wrote:
Structs in D ought to be treated like "glorified ints", as 
Andrei puts it. If you need complex ctors and complex methods, 
that's a sign you should be using a class instead.


I prefer not to use classes, as the code would now move towards 
using references, which is the exact reason I'm using structs.


I ended up creating a constructor for my needs and disabling the 
default constructor. I'm mostly just surprised the static syntax 
is turned off by adding one. I still don't see the reason behind 
it. Why have it but disable it?


I ironically almost always need the exact same constructor with 
the identical arguments though: Initialize the matrix to the 
identity matrix. Why not introduce the empty self-defined 
constructor as a separate thing from the .init value?


On a sidenote, I'm surprised D did not choose 0 as the default 
floating value. Doesn't almost every language do this? I 
understand the thinking behind it, but when the type one uses in 
a template influences the behavior of the code, that seems like a 
pretty big red flag to me. (Any non-floating type defaults to 0, 
but using floats/doubles suddenly introduces NaN, surely I'm not 
the only one that sees a problem with this ) Especially when 
it's basically a standard 0 is used for this. Sorry for the rant.


Re: Install D lang on Windows 10 : an installation step by step tutorial made by a beginner who loves D !

2022-04-18 Thread Dennis via Digitalmars-d-learn

On Monday, 18 April 2022 at 08:22:43 UTC, SMAOLAB wrote:
I tried to install D on a Windows 10 but encountered some 
difficulties (even though I was reading the official D langage 
tutorial available on the official website).


What went wrong when you used the DMD installer? Installing 
Visual Studio should not be necessary, since DMD ships with the 
lld linker and MinGW Windows import libraries. If it doesn't work 
out of the box, it should be fixed.


Nevertheless, thanks for writing the detailed instructions.

Have a nice reading and don't hesitate to send me your 
comments, I will improve the document...


I don't see the guide (explicitly) installing git, but I recall 
dub needing it to install packages. Is that covered?




Install D lang on Windows 10 : an installation step by step tutorial made by a beginner who loves D !

2022-04-18 Thread SMAOLAB via Digitalmars-d-learn

Hello everyone,

I am a newbie in the D langage.

I tried to install D on a Windows 10 but encountered some 
difficulties (even though I was reading the official D langage 
tutorial available on the official website).


I guess that for someone who has a totally new PC, new & fresh 
Windows 10 operating system, well, installing D, it's not so 
easy... :-)


This is why I decided to publish a tutorial on how to install D 
lang on a fresh Windows 10 (step by step tutorial).


Here is the link to the tutorial: 
https://p0nce.github.io/d-idioms/#Installing-Dlang-on-Windows


I hope that this "simple" document will complete the official D 
installation tutorial.


Have a nice reading and don't hesitate to send me your comments, 
I will improve the document...


Regards


Re: Static struct initialization syntax behavior & it being disabled upon adding a constructor

2022-04-18 Thread cc via Digitalmars-d-learn

On Monday, 18 April 2022 at 03:21:30 UTC, H. S. Teoh wrote:
Structs in D ought to be treated like "glorified ints", as 
Andrei puts it. If you need complex ctors and complex methods, 
that's a sign you should be using a class instead.


Unless you're having a nice quiet get-together with friends, and 
you don't want to invite the GC, the biggest loudest party animal 
on the block.  Phobos's RefCounted seems to stretch the 
definition of "glorified ints"..


Re: DUB issues

2022-04-18 Thread BoQsc via Digitalmars-d-learn

On Monday, 18 April 2022 at 05:27:32 UTC, Danny Arends wrote:

Hey All,

For some reason I cannot reset my password to get into dub 
(https://code.dlang.org/), after trying I never receive the 
email to reset my password.


I was unsure at first if I had signed up at all, but trying to 
make a new account tells me my email address is already in use.


Any ideas how to get into contact/fix this issue ?


I tried to look around and it seems that there are no direct 
contacts.
There is old inactive forum. 
https://forum.rejectedsoftware.com/groups/rejectedsoftware.dub/


You can try this general email: i...@rejectedsoftware.com
This one is for both vibe.d and dub.

If no response, there will be a need to try to contact the dub 
authors personally about this issue.


I think it's kind of frustrating. If there is a need, I can try 
to annoy them on the social media, maybe they'll turn up.