Re: Example for Mir-Random fails

2021-04-03 Thread Brad via Digitalmars-d-learn

On Saturday, 3 April 2021 at 20:55:40 UTC, Preetpal wrote:

On Saturday, 3 April 2021 at 19:02:34 UTC, Brad wrote:
Obviously it is a type mismatch - I have tried using to!uint 
to convert the result from unpredictableSeed to a type that 
will match - but that just causes more errors.


Thank you in advance.


I was able to compile the sample without any issue and it was 
able to run. Can you give more information about your 
environment and possibly create a minimal example that 
re-creates the issue like in a Github repository?


I figured out that I had not purged all the Phobos random imports 
from my code and the issue was related to the two libraries not 
playing well together.


It is working now.

Interestingly though - the example code will not compile in the D 
Playground.  I am not going to worry about that.  It is working 
for me now.


Thanks


Re: Example for Mir-Random fails

2021-04-03 Thread Brad via Digitalmars-d-learn

On Saturday, 3 April 2021 at 22:04:33 UTC, Bastiaan Veelo wrote:

On Saturday, 3 April 2021 at 19:02:34 UTC, Brad wrote:
I just do not know enough about the D libraries to figure out 
what is wrong.  I know it is a case of type mismatch.  The 
example appears on the Mir-Random page as listed under DUB:

https://code.dlang.org/packages/mir-random

[...]


I think you are seeing conflicts between Phobos and Mir: they 
both provide unpredictableSeed and Random. If you want to use 
the ones from Mir, be sure to not import std or std.random, or 
use fully qualified names.


— Bastiaan.


You nailed it.  I just now figured that out.  It never ceases to 
amaze me how much time can my lost to a simple mistake like that.


Thank you.


Example for Mir-Random fails

2021-04-03 Thread Brad via Digitalmars-d-learn
I just do not know enough about the D libraries to figure out 
what is wrong.  I know it is a case of type mismatch.  The 
example appears on the Mir-Random page as listed under DUB:

https://code.dlang.org/packages/mir-random

The code looks like this:

```d
void main()
{
import mir.random;
import mir.random.variable: normalVar;
import mir.random.algorithm: randomSlice;

// Engines are allocated on stack or global
auto rng = Random(unpredictableSeed);
auto sample = rng.randomSlice(normalVar, 10);

import std.stdio;
sample[rng.randIndex($)].writeln;
}
```

This is the error I am seeing (I slapped the sample code into 
another program that flips a coin... It compiles file without the 
sample code):


```d
source\flipcoin.d(39,20): Error: constructor 
`std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 
31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 
4022730752u, 18LU, 1812433253u).MersenneTwisterEngine.this(uint 
value)` is not callable using argument types `(ulong)`
source\flipcoin.d(39,20):cannot pass argument 
`unpredictableSeed()` of type `ulong` to parameter `uint value`

```

Obviously it is a type mismatch - I have tried using to!uint to 
convert the result from unpredictableSeed to a type that will 
match - but that just causes more errors.


Thank you in advance.


Creating a .di file for a custom C library

2021-03-29 Thread Brad via Digitalmars-d-learn
I would like to use an updated version of the Termbox library 
(written in C) with D.  I have the .h file.  This is new 
territory for me (why try something easy - right?).  I think I 
need to create a .di file that corresponds to the .h file.  I 
also suspect that I need to put the library file (C code) into 
the project as a file somehow.  I am probably just not looking in 
the right place for the documentation, but I cannot seem to find 
a lot of guidance in this area.


Thanks in advance.


Re: Windows Console and writing Unicode characters

2021-03-29 Thread Brad via Digitalmars-d-learn

On Monday, 29 March 2021 at 11:53:32 UTC, Adam D. Ruppe wrote:

On Monday, 29 March 2021 at 02:12:57 UTC, Brad wrote:

[...]


You can still import std.stdio and use other functions with 
just the one overridden.


D handles name lookups by just ... well, looking up lol. It 
starts in the current scope, then checks the next one up until 
the module, then starts looking at imported modules for the 
name.


If there's two with the same name, it prefers the most local 
one, but you can override that by using the full name:


import std.stdio;
void writeln() {}

writeln(); // since you have a local name, it uses that first
getc(); // no local name, so it checks the imported modules
std.stdio.writeln(); // specifically uses the one from the 
module


Perfect.  Thank you Adam.


Windows Console and writing Unicode characters

2021-03-28 Thread Brad via Digitalmars-d-learn

I am new here so I will post this in Learn.

I have been doing a bit of reading on printing unicode characters 
in the Windows Console.  Specifically W10 command prompt.  I ran 
across a post by Adam Ruppe in a thread created a couple years 
ago which links a short bit of code and a quick discussion that 
Adam presents on his blog.  Here is a link to the specific reply 
I refer to: 
https://forum.dlang.org/post/sjsqqhwvlonohvwyq...@forum.dlang.org


Which points to his Blog post here: 
http://dpldocs.info/this-week-in-d/Blog.Posted_2019_11_25.html#unicode


The code snippet works great and does exactly what I want it to 
do.  I am just curious - since it works by basically providing a 
custom implementation for writeln rather than use the one in 
stdout module (package?) that would mean any other functions from 
that package I would want to leverage I would need to include by 
name.


Would it be acceptable then to maybe rename the custom writeln 
functions in my own code to something like uniwriteln and then 
include the standard library for other functions I might want to 
use?  I am guessing this is not a problem, although I found the 
code a little intimidating and was not sure I wanted to play fast 
and lose with it...


Thanks


Immutable

2021-03-27 Thread Brad via Digitalmars-d-learn
I was looking through lots of sample code on Rosetta Code.  D has 
a lot of solutions out there.  That is really nice but it has me 
wondering - coming from other languages that do not support the 
concept of immutability - do real world programmers and/or 
hobbyists really use it as much as I see it on Rosetta Code?  I 
know it adds a layer of security to your code, but I am still 
thinking "why?".


Thanks for entertaining a newbie question.