Re: cannot call impure function

2020-10-04 Thread Michael via Digitalmars-d-learn

On Sunday, 4 October 2020 at 17:43:13 UTC, Michael wrote:

On Sunday, 4 October 2020 at 17:37:52 UTC, Mathias LANG wrote:

On Sunday, 4 October 2020 at 17:05:33 UTC, Michael wrote:

On Sunday, 4 October 2020 at 17:01:44 UTC, Paul Backus wrote:

On Sunday, 4 October 2020 at 16:48:24 UTC, Michael wrote:

Dear all,

Sorry for the potentially stupid question, but I'm a 
complete newbie to D. Why does compiling the following 
trivial code fail?


import std.stdio;

void main()
{
writeln(3.14);
}


Works fine for me using DMD 2.094.0 on Linux. What OS and 
compiler version are you using, and how did you install DMD?


DMD64 D Compiler v2.094.0
on macOS 10.15.6


I cannot reproduce locally (macOS 10.15.6 too). How did you 
install DMD ?


I used the dmg file: dmd.2.094.0.dmg


I reinstalled using the installation script (install.sh) and now 
it works. Still don't know why the dmg-based intstallation did 
not work.

https://dlang.org/install.html

Anyway, thanks for your responses!


Re: cannot call impure function

2020-10-04 Thread Michael via Digitalmars-d-learn

On Sunday, 4 October 2020 at 17:37:52 UTC, Mathias LANG wrote:

On Sunday, 4 October 2020 at 17:05:33 UTC, Michael wrote:

On Sunday, 4 October 2020 at 17:01:44 UTC, Paul Backus wrote:

On Sunday, 4 October 2020 at 16:48:24 UTC, Michael wrote:

Dear all,

Sorry for the potentially stupid question, but I'm a 
complete newbie to D. Why does compiling the following 
trivial code fail?


import std.stdio;

void main()
{
writeln(3.14);
}


Works fine for me using DMD 2.094.0 on Linux. What OS and 
compiler version are you using, and how did you install DMD?


DMD64 D Compiler v2.094.0
on macOS 10.15.6


I cannot reproduce locally (macOS 10.15.6 too). How did you 
install DMD ?


I used the dmg file: dmd.2.094.0.dmg


Re: cannot call impure function

2020-10-04 Thread Michael via Digitalmars-d-learn

On Sunday, 4 October 2020 at 17:05:33 UTC, Michael wrote:

On Sunday, 4 October 2020 at 17:01:44 UTC, Paul Backus wrote:

On Sunday, 4 October 2020 at 16:48:24 UTC, Michael wrote:

Dear all,

Sorry for the potentially stupid question, but I'm a complete 
newbie to D. Why does compiling the following trivial code 
fail?


import std.stdio;

void main()
{
writeln(3.14);
}


Works fine for me using DMD 2.094.0 on Linux. What OS and 
compiler version are you using, and how did you install DMD?


DMD64 D Compiler v2.094.0
on macOS 10.15.6


I did not use any compiler flags, but just:
dmd test1.d



Re: cannot call impure function

2020-10-04 Thread Michael via Digitalmars-d-learn

On Sunday, 4 October 2020 at 17:01:44 UTC, Paul Backus wrote:

On Sunday, 4 October 2020 at 16:48:24 UTC, Michael wrote:

Dear all,

Sorry for the potentially stupid question, but I'm a complete 
newbie to D. Why does compiling the following trivial code 
fail?


import std.stdio;

void main()
{
writeln(3.14);
}


Works fine for me using DMD 2.094.0 on Linux. What OS and 
compiler version are you using, and how did you install DMD?


DMD64 D Compiler v2.094.0
on macOS 10.15.6



cannot call impure function

2020-10-04 Thread Michael via Digitalmars-d-learn

Dear all,

Sorry for the potentially stupid question, but I'm a complete 
newbie to D. Why does compiling the following trivial code fail?


import std.stdio;

void main()
{
writeln(3.14);
}

Error message:

/Library/D/dmd/src/phobos/std/format.d(1601): Error: pure 
function std.format.FormatSpec!char.FormatSpec.toString cannot 
call impure function 
std.format.FormatSpec!char.FormatSpec.toString!(Appender!string).toString
/Library/D/dmd/src/phobos/std/format.d(478): Error: template 
instance std.format.FormatSpec!char error instantiating
/Library/D/dmd/src/phobos/std/stdio.d(1590):instantiated 
from here: formattedWrite!(LockingTextWriter, char, double)
/Library/D/dmd/src/phobos/std/stdio.d(3927):instantiated 
from here: write!(double, char)

test1.d(5):instantiated from here: writeln!double

Cheers,
Michael


Unused imports

2020-01-30 Thread Michael via Digitalmars-d-learn

Is there a way to detect unused imports?

It happened to me that I used imports which I did not need in the 
end. So, I'd like to remove them easily.





Re: readline / Gnu readline

2020-01-30 Thread Michael via Digitalmars-d-learn

On Thursday, 30 January 2020 at 13:23:17 UTC, Adam D. Ruppe wrote:

On Thursday, 30 January 2020 at 06:12:32 UTC, Michael wrote:

I did exactly just what you proposed.


yeah i often just leave my random filenames in there, in this 
case rl was one of them. (if you don't put `.d` at the end of a 
filename, dmd will add it automatically). Generally a "module X 
is in file X which cannot be read" error means you should:


1) double-check any filenames on the command line. Make sure no 
typos etc and the files all exist. With my samples that 
frequently means changing the filename from whatever nonsense I 
left in my lazy copy/paste :P


2) If all the files are in place, this error can also be caused 
by a mismatch between the `module` name in an imported file and 
the `import` statement that is trying to use it. Those should 
always match.


I'm getting a bit more familiar with D. Really nice. Just wrote a 
program consisting of several files. Importing works fine now and 
also GNU readline.

Thanks for your help


auto keyword

2020-01-30 Thread Michael via Digitalmars-d-learn
auto is surely a nice feature. Nonetheless I'd prefer to use 
explicit types. So when reading a code and I see the auto keyword 
I also have to find out what kind of type is meant.


I have a line of code that looks like this:
auto elements = buf.to!string.strip.split(" ").filter!(a => a != 
"");


That line strips white space from buf, splits it, removes empty 
elements and returns an array of strings. At least I thought so.


Indeed elements can be treated as a string slice, but if i 
replace auto by string[] the compiler complains:
Error: cannot implicitly convert expression 
filter(split(strip(to(buf)), " ")) of type 
FilterResult!(__lambda1, string[]) to string[]


In order to use an explicit type I wonder what kind of type I 
might use instead of auto?


Re: readline / Gnu readline

2020-01-30 Thread Michael via Digitalmars-d-learn

On Thursday, 30 January 2020 at 08:13:16 UTC, Mike Parker wrote:
That means any arguments you pass on the command line after the 
source file name will be passed to your program. Compiler 
options need to go before the source file name.


rdmd -L-lreadline mysource.d


That works, thanks Mike


Re: readline / Gnu readline

2020-01-29 Thread Michael via Digitalmars-d-learn

On Thursday, 30 January 2020 at 06:15:54 UTC, Mike Parker wrote:

Is your source file named rl.d? And are you running dmd in the 
source file's directory?


No, I did not. Changed it now and it works with dmd. Great!
Tried the same with rdmd I'm getting a linker error.




Re: readline / Gnu readline

2020-01-29 Thread Michael via Digitalmars-d-learn
On Wednesday, 29 January 2020 at 21:15:08 UTC, Adam D. Ruppe 
wrote:

On Wednesday, 29 January 2020 at 20:01:32 UTC, Michael wrote:

I am new to D.
I would like to use the Gnu readline function in D. Is there a 
module that i can use?


just define it yourself

---

// this line right here is all you need to call the function
extern(C) char* readline(const char*);

import core.stdc.stdio;

void main() {
char* a = readline("prompt> ");
printf("%s\n", a);
}

---

# and also link it in at the command line with -L-lreadline
 dmd rl -L-lreadline






readline is so simple you don't need to do anything fancier. If 
you need history and such too you just define those functions 
as well.


Dear Adam,

I did exactly just what you proposed.

When 'dmd rl -L-lreadline' in the command line. I do get the 
following error:

Error: module rl is in file 'rl.d' which cannot be read.

So probably I'm missing something unfortunately I don't know what.


readline / Gnu readline

2020-01-29 Thread Michael via Digitalmars-d-learn

I am new to D.
I would like to use the Gnu readline function in D. Is there a 
module that i can use?


Re: Deprecation: foreach: loop index implicitly converted from size_t to int

2019-01-18 Thread Michael via Digitalmars-d-learn

On Friday, 18 January 2019 at 13:29:29 UTC, Adam D. Ruppe wrote:

On Friday, 18 January 2019 at 12:27:17 UTC, Michael wrote:

This, to be, looks like quite the explicit conversion, no?


Yeah, I agree. But the language is silly. I just leave the type 
out of foreach and explicitly cast it inside the body.


Thank you all for the concise explanations and suggestions, I 
think that's fairly straightforward. I thought perhaps I was 
doing the sensible thing of dealing with the conversion inside 
the foreach statement, but I guess not!


Deprecation: foreach: loop index implicitly converted from size_t to int

2019-01-18 Thread Michael via Digitalmars-d-learn

Hello all,

I am getting this deprecation warning when compiling using DMD64 
D Compiler v2.084.0 on Linux. I'm a little unsure what the 
problem is, however, because the code producing these warnings 
tends to be of the form:



foreach (int i, ref prop; props)


This, to be, looks like quite the explicit conversion, no? Does 
it mean I now have to use to!int(i) to convert the type of i in a 
foreach now?


Thanks,
Michael.


Re: Forums intermittently going down?

2018-09-17 Thread Michael via Digitalmars-d
On Monday, 17 September 2018 at 11:51:04 UTC, Vladimir Panteleev 
wrote:

On Monday, 17 September 2018 at 11:02:39 UTC, Michael wrote:
It has been occurring for the past two weeks now, at least. 
When I try to load the forum (on different networks) it will 
often hang for a while, and when it does eventually load a 
page, it is likely that clicking a link will cause it to get 
stuck loading again, or eventually display the following 
message:


forum.dlang.org is temporarily down for maintenance, and 
should be back up shortly. Apologies for the inconvenience.


Is anyone else experiencing this? I thought it might just be 
me but it seems to be happening across browsers and on 
different networks.


Not just you. The server is just overloaded.

The high load is temporary, but will take a week or two to 
resolve.


Okay great, as long as it's just not me and you guys are aware. 
Thanks for letting me (us) know.


Forums intermittently going down?

2018-09-17 Thread Michael via Digitalmars-d
It has been occurring for the past two weeks now, at least. When 
I try to load the forum (on different networks) it will often 
hang for a while, and when it does eventually load a page, it is 
likely that clicking a link will cause it to get stuck loading 
again, or eventually display the following message:


forum.dlang.org is temporarily down for maintenance, and should 
be back up shortly. Apologies for the inconvenience.


Is anyone else experiencing this? I thought it might just be me 
but it seems to be happening across browsers and on different 
networks.


Thanks,
Michael.


Re: John Regehr on "Use of Assertions"

2018-09-05 Thread Michael via Digitalmars-d
On Saturday, 1 September 2018 at 20:15:15 UTC, Walter Bright 
wrote:


Note the "may or may not be evaluated." We've debated this here 
before. I'm rather pleased that John agrees with me on this. 
I.e. the optimizer can assume the expression is true and use 
that information to generate better code, even if the assert 
code generation is turned off.


Is the part about the optimizer true in D's case? Or is this just 
a theoretical advantage to using asserts that are not evaluated 
in production code but left in?


Re: Enum and CTFE function call

2018-08-14 Thread Michael via Digitalmars-d-learn
On Tuesday, 14 August 2018 at 11:25:06 UTC, Jonathan M Davis 
wrote:
On Tuesday, August 14, 2018 4:03:11 AM MDT Michael via 
Digitalmars-d-learn wrote:

[...]


CTFE is triggered when a value must be known at compile-time. 
So, if you have something like


[...]


That is much clearer now, thanks for clarifying.


Re: Enum and CTFE function call

2018-08-14 Thread Michael via Digitalmars-d-learn

On Tuesday, 14 August 2018 at 09:17:41 UTC, ixid wrote:

On Tuesday, 14 August 2018 at 09:12:30 UTC, ixid wrote:
This will not compile as it says n is not known at compile 
time...


This does work if 'value' is changed to immutable and fun to 
accept it. So it still seems like a missed opportunity as enum 
shouldn't be able to change either.


From the examples on this page:
https://tour.dlang.org/tour/en/gems/compile-time-function-evaluation-ctfe

It looks to me like it might be a slight issue with the function 
being void, in that you need to explicitly ensure that n is 
immutable. For the example on the page above, they assign the 
result of the function to a static variable, and so the function 
is evaluated at compile-time, but without assigning the value to 
a static variable, it is evaluated at runtime. I guess in this 
case the compiler may just be being cautious?


The page does state that enums should trigger CTFE though.


Re: throwing lots of resources at a GC

2018-07-23 Thread Michael via Digitalmars-d

On Friday, 20 July 2018 at 00:46:37 UTC, John Belmonte wrote:
Interesting (and way too detailed for me) tale of GC adventures 
in golang:


https://blog.golang.org/ismmkeynote


Seeing the pretty incredible reductions in additional latency was 
great. I would love to see some in-depth analysis of D's garbage 
collector.


Re: Funding code-d

2018-07-13 Thread Michael via Digitalmars-d-announce

On Friday, 13 July 2018 at 14:20:19 UTC, Mike Parker wrote:
As promised in my tweet of June 30 (and to the handful of 
people who emailed me), the cloud of mystery surrounding the 
use of the money raised for code-d and its supporting tools has 
now been (partially) lifted!


In this post, I lay out the details of how the first $1000 will 
be paid out to project maintainer Jan Jurzitza, a.k.a 
Webfreak001, and explain what we hope to achieve with this 
ecosystem fundraising initiative going forward.


This time around, it all came together in the background of 
prepping for DConf with little forethought beyond activating an 
Open Collective goal and then working with Jan to determine the 
details. Lessons were learned. Later this year, you'll see the 
result when we announce the next of what we hope to be an 
ongoing series of funding targets.


In the meantime:

The blog
https://dlang.org/blog/2018/07/13/funding-code-d/

Reddit
https://www.reddit.com/r/d_language/comments/8yka7b/funding_coded_the_d_blog/


I think this is a worthy cause for the money. I'm glad to see the 
D foundation looking more towards investing in these kinds of 
community projects, as they make up the D ecosystem that many 
opponents of D describe as lacking.


Re: UFCS confusion

2018-07-13 Thread Michael via Digitalmars-d-learn

On Friday, 13 July 2018 at 11:17:32 UTC, Radu wrote:

On Friday, 13 July 2018 at 11:12:47 UTC, Michael wrote:

On Friday, 13 July 2018 at 10:52:54 UTC, Radu wrote:

On Friday, 13 July 2018 at 10:21:54 UTC, Michael wrote:

[...]


Do you try to call member functions? UFCS only works with 
free functions, meaning declared at module level.


https://dlang.org/spec/function.html#pseudo-member


I'm not intentionally trying to call member functions, no. The 
functions are all static functions of a class, but the 
chaining of them using UFCS doesn't seem to work.


OK, static functions of a class are static *member* functions, 
they are not free functions.


Oh, really? Well that will explain it then. I was sure I had used 
this syntax before but perhaps not. Thanks for your help!


Re: UFCS confusion

2018-07-13 Thread Michael via Digitalmars-d-learn

On Friday, 13 July 2018 at 10:52:54 UTC, Radu wrote:

On Friday, 13 July 2018 at 10:21:54 UTC, Michael wrote:

Hello,

I am nesting some function calls, and I'm pretty used to 
making use of D's Uniform Function Call Syntax, but I'm 
getting an error if I try to convert this line:



createSet(createVector(langSize, index)).length;


which works, into this line:


createVector(langSize, index).createSet.length;


receiving the error "Error: no property createSet for type 
int[]", when the signature for createSet is:



static auto createSet(in int[] vector) pure


What am I missing here? I'm sure it's stupidly obvious but it 
expects one argument, so I'm just calling it without 
parentheses.


Do you try to call member functions? UFCS only works with free 
functions, meaning declared at module level.


https://dlang.org/spec/function.html#pseudo-member


I'm not intentionally trying to call member functions, no. The 
functions are all static functions of a class, but the chaining 
of them using UFCS doesn't seem to work.


UFCS confusion

2018-07-13 Thread Michael via Digitalmars-d-learn

Hello,

I am nesting some function calls, and I'm pretty used to making 
use of D's Uniform Function Call Syntax, but I'm getting an error 
if I try to convert this line:



createSet(createVector(langSize, index)).length;


which works, into this line:


createVector(langSize, index).createSet.length;


receiving the error "Error: no property createSet for type 
int[]", when the signature for createSet is:



static auto createSet(in int[] vector) pure


What am I missing here? I'm sure it's stupidly obvious but it 
expects one argument, so I'm just calling it without parentheses.


Re: Passing a reference to a returned reference

2018-07-06 Thread Michael via Digitalmars-d-learn

On Friday, 6 July 2018 at 16:24:03 UTC, Timoses wrote:

On Friday, 6 July 2018 at 15:51:34 UTC, Michael wrote:

[...]
While writing I realized that the following is even the case 
without the 'ref' parameter:
The caller of the setter will still be able to change the 
content of your private data after you checked it for validity. 
Take following example:


[...]


I understand your warning, but as the array is created purely to 
assign to the agent's beliefs, it only appears in the main() 
function as a rhs reference, which is passed to the agent, the 
reference is stored in the member variable, and then the main 
function continues, holding no reference to that array outside of 
agent's agent.beliefs getter function. Appreciate the heads up, 
though.


Re: Passing a reference to a returned reference

2018-07-06 Thread Michael via Digitalmars-d-learn

On Friday, 6 July 2018 at 15:57:27 UTC, Timoses wrote:

On Friday, 6 July 2018 at 15:33:18 UTC, Michael wrote:


This is definitely to do with my use of the setter syntax, 
which maybe I am misunderstanding? Because if I change it to a 
normal function call like so:


a.beliefs(Operator.create());

then it complains if I use ref, and doesn't complain if I 
don't.


You can try removing the "auto" from the Operator class method

// Error: returning dict escapes a reference to local variable 
dict

false
static ref create()
{
double[int] dict;
dict[2] = 1.0;
dict[1] = 0.0;
return dict;
}

That indicates that 'dict' is actually returned by value (at 
least the reference). This sounds a bit confusing.
AFAIK, in above code a reference 'dict' is created pointing 
towards memory that stores that dictionary entries. The 
reference itself is a "pointer"(?) which will "die" when 
running out of the method's scope. This pointer lives on the 
function's stack. So returning this "pointer" (essentially a 
value type, e.g. int) will return it by value.


You could return a reference like so:

class Operator
{
static double[int] hdict;
static this()
{
 hdict[2] = 1.0;
 hdict[1] = 0.0;
}
static ref create()
{
return hdict;
}
}

then


a.beliefs(Operator.create());


should work on the "ref" setter.


Oh of course, as it's a reference type, the "value" being 
returned by 'auto ref' is the value of the reference to the array 
anyway, so I am already passing the reference. Not sure how I 
managed to get really confused about that. Then, forcing the 
function to return a reference to a local reference to a heap 
alloc. array is obviously a problem. This makes way more sense 
now. Thank you again, Timoses, and I hope you enjoyed the result, 
Ali.


I guess I just need to be careful with the setter/getter 
approach, in case I accidentally invoke the getter to return a 
reference, which I then overwrite with another reference. I don't 
know if that's worthy of adding some kind of compiler warning, or 
if I'm just the stupid one to get caught by that, but I'm glad 
it's resolved.


At least it was, technically, working before by leaking access to 
the private member variable and overwriting it.


Re: Passing a reference to a returned reference

2018-07-06 Thread Michael via Digitalmars-d-learn

On Friday, 6 July 2018 at 15:37:25 UTC, Timoses wrote:

On Friday, 6 July 2018 at 15:14:01 UTC, Michael wrote:

class Agent
{
private
{
double[int] mDict;
}

// Setter: copy
void beliefs(ref double[int] dict)
{
import std.stdio : writeln;
writeln("Setter function.");
this.mDict = dict;
}

// Getter
auto ref beliefs()
{
return this.mDict;
}
}

class Operator
{
static auto ref create()
{
double[int] dict;
dict[2] = 1.0;
dict[1] = 0.0;
return dict;
}
}


Throw in a writeln statement in getter and be amazed : D

class Agent
{
private
{
double[int] mDict;
}

// Setter: copy
void beliefs(ref double[int] dict)
{
import std.stdio : writeln;
writeln("Setter function.");
this.mDict = dict;
}

// Getter
auto ref beliefs()
{
writeln("getter");
return this.mDict;
}
}

class Operator
{
static auto ref create()
{
double[int] dict;
dict[2] = 1.0;
dict[1] = 0.0;
return dict;
}
}

unittest
{
import std.stdio : writeln;

Agent a = new Agent();

writeln("Statement 1");
a.beliefs = Operator.create();
writeln("Statement 2");
assert(a.beliefs.keys.length == 2);

writeln("Statement 3");
writeln(a.beliefs);
}

If you remove the ref then "Statement 1" will use the setter 
method. Otherwise it calls the "auto ref" function to get a 
reference of 'mDict' and assign it a value. Essentially


// Getter
auto ref beliefs()
{
return this.mDict;
}

makes your "private" variable not private any more, since you 
are leaking a reference to it. So any program calling 
"a.beliefs" can get a reference to your private data and modify 
it.


My guess is that (if ref is removed from the setter) it serves 
as a @property function:

https://dlang.org/spec/function.html#property-functions
So this allows the function to work in a statement like:
a.beliefs = 

And apparently it is prioritized over the "ref beliefs()" 
function.



I guess it is nicer to actually use the "setter" function, as 
it allows you to inspect what the private data will be assigned 
to and take appropriate measures, whereas with the "ref 
beliefs()" method the private data is open for any manipulation 
out of your control.


How strange! Nice find though, thanks for your help with this, I 
really appreciate it as this had been bugging me for a while.


So essentially, what is happening is, if the setter method 
expects a reference, then because the create() function isn't 
returning a reference but a copy, it actually does the following:


a.beliefs = Operator.create();

receives an object from create(), while a.beliefs retrieves a 
reference to agent.mBeliefs, and then effectively sets this 
reference to point to the object copied by create()?


Also, yes, I am using the setter method to play around with the 
precision of the double values, and do some normalising. I always 
want it to access the setter method, but I had hoped that, given 
it's an associative array, that the creation of the object in 
create() would simply create it on the heap and I could pass back 
a reference. It seems that I was incorrect, as if I set create() 
to explicitly return a reference, it complains about returning a 
reference to a local variable. Any advice on the best way to pass 
it as a reference?


Re: Passing a reference to a returned reference

2018-07-06 Thread Michael via Digitalmars-d-learn

On Friday, 6 July 2018 at 15:14:01 UTC, Michael wrote:

On Friday, 6 July 2018 at 14:50:39 UTC, Ali Çehreli wrote:

[...]


I'm just trying to do that now.

Here is what I have in terms of code:

[...]


This is definitely to do with my use of the setter syntax, which 
maybe I am misunderstanding? Because if I change it to a normal 
function call like so:


a.beliefs(Operator.create());

then it complains if I use ref, and doesn't complain if I don't.


Re: Passing a reference to a returned reference

2018-07-06 Thread Michael via Digitalmars-d-learn

On Friday, 6 July 2018 at 14:50:39 UTC, Ali Çehreli wrote:

On 07/06/2018 07:36 AM, Michael wrote:
> but not in
> my case, if this is a weird edge-case with setter member
functions?

This is all very interesting but I'm dying to see the code. :) 
Can you change Timoses's code to demonstrate your case?


Ali


I'm just trying to do that now.

Here is what I have in terms of code:

class Agent
{
private
{
double[int] mDict;
}

// Setter: copy
void beliefs(ref double[int] dict)
{
import std.stdio : writeln;
writeln("Setter function.");
this.mDict = dict;
}

// Getter
auto ref beliefs()
{
return this.mDict;
}
}

class Operator
{
static auto ref create()
{
double[int] dict;
dict[2] = 1.0;
dict[1] = 0.0;
return dict;
}
}

unittest
{
import std.stdio : writeln;

Agent a = new Agent();

a.beliefs = Operator.create();
assert(a.beliefs.keys.length == 2);

writeln(a.beliefs);
}


and here is the output WITH "ref" in beliefs's signature before 
double[int] dict:


➜  dempshaf git:(master) ✗ rdmd -I../ -unittest -main bug_test.d
[2:1, 1:0]

and without "ref":

➜  dempshaf git:(master) ✗ rdmd -I../ -unittest -main bug_test.d
Setter function.
[2:1, 1:0]


I'm surprised it's showing the correct value of the associative 
array, but hopefully this shows my point that it's not printing 
for some reason, when the parameter is ref.


Re: Passing a reference to a returned reference

2018-07-06 Thread Michael via Digitalmars-d-learn

On Friday, 6 July 2018 at 14:11:42 UTC, Timoses wrote:


This works for me:

auto create()
{
string[int] dict;
dict[2] = "hello";
return dict;
}

void modifyNoRef(string[int] m)
{
 writeln("Address not ref: ", );
 m[0] = "modified";
}

void modifyRef(ref string[int] m)
{
 writeln("Address ref: ", );
 m[1] = "modified";
}

unittest
{
auto r = create();
writeln("Address r: ", );
assert(r.keys.length == 1);
modifyNoRef(r);
assert(r.keys.length == 2); 
modifyRef(r);
assert(r.keys.length == 3); 
}

So either with ref or not as parameter storage class the assoc. 
array is modified. Note the address in the "ref" one is the 
same as "r" in the unittest.


[1]: https://dlang.org/spec/function.html#auto-ref-functions



I'm wondering, seeing as it works in the example given above, but 
not in my case, if this is a weird edge-case with setter member 
functions?


What I wanted to do was have the "Agent" object set its internal 
variable to point to the newly created associative array but 
instead it just seems to go right past the setter function.


Re: Passing a reference to a returned reference

2018-07-06 Thread Michael via Digitalmars-d-learn

On Friday, 6 July 2018 at 14:11:42 UTC, Timoses wrote:

On Friday, 6 July 2018 at 13:13:43 UTC, Michael wrote:

static auto ref consensus( ... )


`auto ref` infers the return type from the return statement 
[1]. So it's not necessarily returning a ref type.


However, I don't think this matters if the only concern you 
have is that the setter function actually modifies the passed 
object.




and the agent's setter method looks like the following:

void beliefs(ref double[int] beliefs)

Now obviously if I remove ref in the above signature, 
everything works fine, but I am surprised I wasn't getting any 
kind of warning about the reference because the setter 
function just doesn't run at all. I tried checking if (beliefs 
is null) but perhaps this isn't the correct way to check if an 
associative array's reference is no longer reachable?


Some explanation would be great, thanks!


This works for me:

auto create()
{
string[int] dict;
dict[2] = "hello";
return dict;
}

void modifyNoRef(string[int] m)
{
 writeln("Address not ref: ", );
 m[0] = "modified";
}

void modifyRef(ref string[int] m)
{
 writeln("Address ref: ", );
 m[1] = "modified";
}

unittest
{
auto r = create();
writeln("Address r: ", );
assert(r.keys.length == 1);
modifyNoRef(r);
assert(r.keys.length == 2); 
modifyRef(r);
assert(r.keys.length == 3); 
}

So either with ref or not as parameter storage class the assoc. 
array is modified. Note the address in the "ref" one is the 
same as "r" in the unittest.


[1]: https://dlang.org/spec/function.html#auto-ref-functions


Aah yes I had forgotten that I had set it as auto ref. However, 
even when I set that function to always return a copy of the 
associative array, it didn't change anything -- the issue always 
seems to be with the setter method expecting a reference.


So then, supposing it's returning a copy of the object. Given 
that my setter method was still expecting a reference, is there a 
reason why it doesn't even invoke the setter unless I change the 
parameter from expecting a reference to expecting a copy of the 
object? It's not like the function failed in any way, it just 
wouldn't run the function at all. Not even while I was printing 
something right at the top.


Passing a reference to a returned reference

2018-07-06 Thread Michael via Digitalmars-d-learn

Hello,

I'm a little confused about what is actually happening when I try 
to pass a reference, returned by a method that produces the 
object (associative array), to a setter method which expects a 
reference. What seems to be happening is that it simply does 
nothing, as if the setter method is never called.


I'll try to provide some code to highlight the signatures.

The setter method being called on the reference returned by the 
method that produces the array:


agent.beliefs = combination( ... ); // should receive a 
reference, and pass this to the setter method.


Combination is a function point to one of two functions, whose 
signatures look like:


static auto ref consensus( ... )

and the agent's setter method looks like the following:

void beliefs(ref double[int] beliefs)

Now obviously if I remove ref in the above signature, everything 
works fine, but I am surprised I wasn't getting any kind of 
warning about the reference because the setter function just 
doesn't run at all. I tried checking if (beliefs is null) but 
perhaps this isn't the correct way to check if an associative 
array's reference is no longer reachable?


Some explanation would be great, thanks!


Re: Is it possible to set up DConf Asia?

2018-06-29 Thread Michael via Digitalmars-d

On Friday, 29 June 2018 at 10:12:28 UTC, Mike Parker wrote:


I can tell you that DConf Asia is something the Foundation is 
interested in. It's also something I plan to work toward making 
happen eventually. We discussed this at our Seoul meetup 
recently. What I need to know before anything can happen is how 
large the Chinese and Japanese D communities are.


I guess the best place to start is to organise meetups in the 
countries first to gauge interest and the size of the D community 
in those countries, and then there can be some communication 
between the local meetups aiming at organising a more regional 
DConf?


Re: ldc flags for beginner

2018-04-22 Thread Michael via Digitalmars-d-learn

On Sunday, 22 April 2018 at 02:08:40 UTC, fevasu wrote:
what flags to use so that the intermediate .o files are 
discared by ldc and only a.out is written to disk


You can also use rdmd with ldc, if that makes things easier.


Re: How to delete element from array container or dlist?

2018-03-18 Thread Michael via Digitalmars-d-learn

On Sunday, 18 March 2018 at 15:42:18 UTC, Andrey Kabylin wrote:

On Sunday, 18 March 2018 at 15:32:47 UTC, Michael wrote:

On Sunday, 18 March 2018 at 14:58:52 UTC, Andrey Kabylin wrote:
In DList we have method remove, but I can't understand how 
this method works, I want write somethink like this:

void unsubscribe(EventsSubscriber subscriber) {
subscribers.remove(subscriber);
}


So I guess you would want something like

subscribers.remove!(a => a == subscriber));

which is the different definition of remove available here:
https://dlang.org/phobos/std_algorithm_mutation.html#.remove.2


Yes this works, thanks!


No problem, glad to help!


Re: How to delete element from array container or dlist?

2018-03-18 Thread Michael via Digitalmars-d-learn

On Sunday, 18 March 2018 at 14:58:52 UTC, Andrey Kabylin wrote:
In DList we have method remove, but I can't understand how this 
method works, I want write somethink like this:

void unsubscribe(EventsSubscriber subscriber) {
subscribers.remove(subscriber);
}


The remove function seems to expect an index, not an element.


Re: How to delete element from array container or dlist?

2018-03-18 Thread Michael via Digitalmars-d-learn

On Sunday, 18 March 2018 at 14:58:52 UTC, Andrey Kabylin wrote:
In DList we have method remove, but I can't understand how this 
method works, I want write somethink like this:

void unsubscribe(EventsSubscriber subscriber) {
subscribers.remove(subscriber);
}


So I guess you would want something like

subscribers.remove!(a => a == subscriber));

which is the different definition of remove available here:
https://dlang.org/phobos/std_algorithm_mutation.html#.remove.2


Re: A betterC base

2018-02-08 Thread Michael via Digitalmars-d

On Thursday, 8 February 2018 at 14:54:19 UTC, Adam D. Ruppe wrote:

On Thursday, 8 February 2018 at 11:06:15 UTC, ixid wrote:
It feels like D has not overcome at least two major issues in 
the public mind, the built-in GC


D is a pragmatic language aimed toward writing fast code, fast. 
Garbage collection has proved to be a smashing success in the 
industry, providing productivity and memory-safety to 
programmers of all skill levels. D's GC implementation follows 
in the footsteps of industry giants without compromising 
expert's ability to tweak even further.




That's what we should be saying every single time someone 
mentions GC. Including it was the RIGHT DECISION and we should 
own that.


Yes, absolutely! It's the reason I chose to start writing 
programs in D, because I had a background in C and Java, and 
wanted a fast, compiled language that would take care of the 
details for me. You can write programs quickly, and it's quick 
enough when running them, and can of course be tuned further 
through managing allocations/collections of the GC etc.


Re: #dbugfix Issue 16189

2018-02-07 Thread Michael via Digitalmars-d

On Wednesday, 7 February 2018 at 08:51:01 UTC, Kirr wrote:

https://issues.dlang.org/show_bug.cgi?id=16189

This is a P1 critical DMD bug, silently generating wrong code. 
Reported one and a half year ago, but exists in DMD compilers 
going back to DMD 2.050 (possibly more, but this is as far back 
as I tried).


The repro is essentially C, it involves nothing but array, 
struct and loop. No templates, CTFE, no phobos, no any fancy 
features.


I can fully understand that may be this bug is hard to fix, 
that there's not enough manpower, that there are other more 
pressing issues, that no one can be expected to work on 
something they are not interested in, etc. And may I'm the only 
one affected? (it's a mystery to me). But this bug is a 
phychological obstacle to my use of D (or rather DMD, because 
LDC seems OK). May be it's just my expectation that is too high.


I'm not ready to give up arrays, structs or loops. I 
experimentally worked around this once I found it, by 
re-wording the loop. But I've no idea how to make sure this bug 
won't hit me somewhere else. I guess I can live without 
optimizer (or without DMD). In any case, I think that 
miscompiling a simplest C-like loop does not send the right 
message to a newcomer.


I'll appreciate any help with this bug.


Yeah that's... really bad. I suppose the saving grace is that 
it's only a serious issue with the use of the optimiser, which I 
don't tend to use on DMD, but this should really be prioritised. 
I guess the fact that it's not a regression might make fixing it 
harder, but it doesn't really matter.


Does it work with slightly varied examples like where a = -1, and 
is incremented etc.?


Re: My choice to pick Go over D ( and Rust ), mostly non-technical

2018-02-05 Thread Michael via Digitalmars-d
On Saturday, 3 February 2018 at 01:52:04 UTC, psychoticRabbit 
wrote:

On Friday, 2 February 2018 at 15:06:35 UTC, Benny wrote:

[...]


I think that point hits the cause of your problem with D (along 
with your need to 'choose' something over 'something' else).


[...]


I think it is worth mentioning that D does in fact have corporate 
interests driving some of the development behind D. They have 
"sponsors" just like many other languages, we just don't see the 
direct connection between a sponsor's donations and the focus of 
development of the language.


Re: Quora: Why hasn't D started to replace C++?

2018-01-31 Thread Michael via Digitalmars-d
On Wednesday, 31 January 2018 at 07:56:37 UTC, Andrew Benton 
wrote:
On Tuesday, 30 January 2018 at 20:45:44 UTC, Andrei 
Alexandrescu wrote:

https://www.quora.com/Why-hasnt-D-started-to-replace-C++

Andrei


I think that the largest issue there is probably the marketing 
and advocacy.  When Rust was about the same share as D, it had 
much better marketing.  Someone was running their twitter 
channel and working to make the language much more visible.  D 
flat out doesn't have that.


If I had to pick a second issue, it's that the ecosystem story 
is hard compared to other languages.  New programmers aren't 
certain what to choose or how to get their environment up and 
running.  Compared against Rust, Go, and Java we have horrible 
ecosystem fragmentation.  E.g. three compilers, two separate 
languages for dub


I agree that marketing is a pretty serious problem for D. Many 
people just aren't aware of it. Even for people who do not 
program in the newer languages, Rust and Go are already well 
known to anybody who uses C# or C/C++ or Java, and even many 
Python or JavaScript programmers. D is often looked over and not 
visible enough on people's radars for them to even notice it, 
which is hugely disappointing as I've no doubt many would come to 
realise that it offers much of what they're looking for. 
Marketing is definitely failing the language here, but 
considering we don't have some huge company backing D, it's doing 
fairly well on its own. I just worry it's not enough to rely on 
word-of-mouth because it doesn't seem to be enough.


Personally I don't find the ecosystem to be a huge problem any 
more than C++'s is a problem. I can install DMD and LDC and, 
if/when I want/need to, I can tell rdmd to build using LDC. I am 
glad to have options, as I don't feel that they hinder my use of 
D.


Re: Should negating an unsigned integral be an error?

2018-01-30 Thread Michael via Digitalmars-d

On Tuesday, 30 January 2018 at 14:08:41 UTC, bauss wrote:

On Tuesday, 30 January 2018 at 11:09:08 UTC, Michael wrote:
On Monday, 29 January 2018 at 10:06:41 UTC, Jonathan M Davis 
wrote:
On Monday, January 29, 2018 09:58:00 Dave Jones via 
Digitalmars-d wrote:

Given

uint i = 12345;

should

writeln(-i)

be an error? or maybe i should be automatically cast to a 
larger signed type?


It arguably should be, but it's pretty common in C/C++ to get 
uint.max with -1, and I suspect that it's fairly common in D 
as well even though you could just use uint.max. So, it could 
be argued either way.


- Jonathan M Davis


I'd like to see these kinds of potential mistakes to be forced 
to use something like uint.max. Of course, at this point it 
might be too late to introduce something as breaking as this, 
but these kinds of things should definitely be forced by the 
language, or made a warning at least, pointing to the use of 
.max instead.


A normal deprecation process should be enough, since it'll give 
time to update code that uses it.


I don't think there is a lot of idiomatic D code that uses this 
feature.


But it's one of those bad habits lots of people have probably 
gotten into because it was the way to do things in C/C++ or 
whatever. Good point, though. I think it would be worth catching 
all of these small potential errors that can be replaced with 
code that is much more clear as to its intent.


Re: Should negating an unsigned integral be an error?

2018-01-30 Thread Michael via Digitalmars-d
On Monday, 29 January 2018 at 10:06:41 UTC, Jonathan M Davis 
wrote:
On Monday, January 29, 2018 09:58:00 Dave Jones via 
Digitalmars-d wrote:

Given

uint i = 12345;

should

writeln(-i)

be an error? or maybe i should be automatically cast to a 
larger signed type?


It arguably should be, but it's pretty common in C/C++ to get 
uint.max with -1, and I suspect that it's fairly common in D as 
well even though you could just use uint.max. So, it could be 
argued either way.


- Jonathan M Davis


I'd like to see these kinds of potential mistakes to be forced to 
use something like uint.max. Of course, at this point it might be 
too late to introduce something as breaking as this, but these 
kinds of things should definitely be forced by the language, or 
made a warning at least, pointing to the use of .max instead.


Re: How programmers transition between languages

2018-01-29 Thread Michael via Digitalmars-d
On Monday, 29 January 2018 at 03:22:54 UTC, Ola Fosheim Grøstad 
wrote:

On Sunday, 28 January 2018 at 23:09:00 UTC, Michael wrote:
by the whole target audience. Rust, on the other hand, seems 
to be picking up those who have left Go.


I guess some go to Rust after working with Go, but the 
transition matrix linked above suggests that the trend has been 
that people give up on Rust and try out Go then Python... Of 
course, with so little data things are uncertain and can change.


I would hazard a guess that Go is likely the language they settle 
on for whatever task required something more low-level like 
Rust/Go(/D? =[ ) and that they move to Python for the kinds of 
scripting tasks that follow development of something in the 
previous languages.


Re: How programmers transition between languages

2018-01-28 Thread Michael via Digitalmars-d

On Sunday, 28 January 2018 at 15:36:17 UTC, bachmeier wrote:

On Sunday, 28 January 2018 at 13:50:03 UTC, Michael wrote:
Most people at my university, outside of the computer science 
department, that are using languages like Python and R and 
MATLAB the most, are very aware of Rust and Go, but not D.


I'd say Julia is getting a lot more attention than Rust or Go 
for those users. And rightfully so.


I wasn't trying to relate these two sections. My point above was 
that people who don't really work with systems languages were 
still widely aware of the existence of new languages, while D 
remains relatively obscure.




I wonder if we do need to pay more attention to attracting new 
users just to get people talking about it.


I'm not sure why those users would be interested in D at the 
moment. D presents itself as a C++ replacement, discussions are 
all about low-level stuff, garbage collection, and efficiency, 
and new users are told to use Dub and learn about Git 
submodules. That's not ever going to appeal to the R and Matlab 
crowd. I have gotten others to start using D, and it was quite 
easy. Just make an R package containing D code, they install 
it, and then they call D functions from R. Few in this 
community understand that style of programming though.


But D is fighting against Rust and Go, and struggling to pull any 
attention away from either. Go has found its niche, and has 
settled pretty well, but it has not been overwhelmingly adopted 
by the whole target audience. Rust, on the other hand, seems to 
be picking up those who have left Go.


Re: How programmers transition between languages

2018-01-28 Thread Michael via Digitalmars-d

On Sunday, 28 January 2018 at 13:50:03 UTC, Michael wrote:
On Friday, 26 January 2018 at 09:02:03 UTC, Ola Fosheim Grøstad 
wrote:

[...]


I find it fascinating that C# is in the "languages to avoid" 
section, because from my perspective it's receiving more and 
more adoption as the modern alternative to Java, in a way that 
Go and Rust are not. Different markets and all of that. So I 
can't see why C# would be seen as a language that is dropping 
in popularity (though I don't use it myself).


[...]


Oh, I had confused Objective-C with C# in that graph. Forget the 
first part of my previous post.


Re: How programmers transition between languages

2018-01-28 Thread Michael via Digitalmars-d
On Friday, 26 January 2018 at 09:02:03 UTC, Ola Fosheim Grøstad 
wrote:
While this analysis of language popularity on Github is 
enlightening:


http://www.benfrederickson.com/ranking-programming-languages-by-github-users/

I found the older analysis of how programmers transition (or 
adopt new languages) more interesting:


https://blog.sourced.tech/post/language_migrations/

Like how people move from Rust to Go. And from Go to Python:

https://blog.sourced.tech/post/language_migrations/sum_matrix_22lang_eig.svg


Also the growth of Java is larger than I would anticipate:

https://blog.sourced.tech/post/language_migrations/eigenvect_stack_22lang.png

Granted, Java has gotten quite a few convenience features over 
the years.


I find it fascinating that C# is in the "languages to avoid" 
section, because from my perspective it's receiving more and more 
adoption as the modern alternative to Java, in a way that Go and 
Rust are not. Different markets and all of that. So I can't see 
why C# would be seen as a language that is dropping in popularity 
(though I don't use it myself).


I do worry that, having been using D for about 3 1/2 years now, 
that the perceptions of D outside of this community don't seem to 
be changing much. It does seem to make a huge difference to have 
a big company behind a language, purely for the "free 
advertisement". Most people at my university, outside of the 
computer science department, that are using languages like Python 
and R and MATLAB the most, are very aware of Rust and Go, but not 
D. I wonder if we do need to pay more attention to attracting new 
users just to get people talking about it.


Re: The name "Phobos" in user-facing docs

2018-01-12 Thread Michael via Digitalmars-d

On Friday, 12 January 2018 at 22:26:38 UTC, Michael wrote:

On Friday, 12 January 2018 at 21:24:40 UTC, John Gabriele wrote:

[...]


I mean, you're correct to say it's an artifact of D being an 
old language. Tango was the original, and Phobos was introduced 
for D2 as a competing library. I don't see this as being 
confusing for new users. When I learnt D, I simply understood 
that the standard library was called "Phobos" instead of "STL" 
some other associated term. It didn't ever become confusing, 
and when I learnt about Tango I was immediately made aware (by 
the context) that Tango was simply the old standard library, 
where Phobos had replaced it. This isn't any more confusing 
than C99, C11 etc. as versioning numbers for updates to the 
language and their libraries. D1 and Tango, D2 and Phobos. I 
don't think it's common to get the impression that Tango is 
still a competing library, though that may differ for some 
users.


I also just really like the name and hope that kind of convention 
continues. You have a core language (Digital Mars (the planet), 
or D) and its accompanying moon (Tango, then Phobos). I think it 
suits the language.


Re: The name "Phobos" in user-facing docs

2018-01-12 Thread Michael via Digitalmars-d

On Friday, 12 January 2018 at 21:24:40 UTC, John Gabriele wrote:
After having started learning some D lately, two things about 
the standard library have struck me:


 1. It has its own name. Phobos. This is unusual. I don't know 
of any other language who's std lib has any name other than 
"the {lang} standard library". Why does it have its own 
distinct name, and why do I (as a user) need to know it?


 2. There is evidently *still* some lingering FUD out there 
about some long-since-settled dual-standard-library issue. I 
haven't been around here long enough, but I still see 
references to Tango here and there.


I think it would help D's image to simply remove the name 
"phobos" from any user-facing docs. That is, change "phobos" to 
"the standard library" everywhere users would be looking. (Of 
course, *internally* the name "phobos" may still be useful for 
repo names, mailing list names, and what have you.)


Just the fact that the std lib *has* it's own user-facing name 
suggests that there may be more than one standard library (or 
else, why would it need its own special name to begin with?). 
It may also imply that the door is open for some other young 
upstart library to swoop in usurp the title of official 
standard library. The standard library having its own distinct 
user-facing name appears to sow confusion.


Maybe, historically, it was useful to have distinct names for 
competing potential D standard libraries, in order to 
distinguish them. Is that still the case?


I mean, you're correct to say it's an artifact of D being an old 
language. Tango was the original, and Phobos was introduced for 
D2 as a competing library. I don't see this as being confusing 
for new users. When I learnt D, I simply understood that the 
standard library was called "Phobos" instead of "STL" some other 
associated term. It didn't ever become confusing, and when I 
learnt about Tango I was immediately made aware (by the context) 
that Tango was simply the old standard library, where Phobos had 
replaced it. This isn't any more confusing than C99, C11 etc. as 
versioning numbers for updates to the language and their 
libraries. D1 and Tango, D2 and Phobos. I don't think it's common 
to get the impression that Tango is still a competing library, 
though that may differ for some users.


Re: I want to transmit the class name and the member name in the method

2018-01-05 Thread Michael via Digitalmars-d-learn

On Friday, 5 January 2018 at 12:19:11 UTC, thedeemon wrote:

On Friday, 5 January 2018 at 07:40:14 UTC, Brian wrote:

I think code style like:
db.select(User).where(email.like("*@hotmail.com")).limit(10);


You need to read about templates in D, here's a good guide:
https://github.com/PhilippeSigaud/D-templates-tutorial

Basically you can write a function like
auto select(Class, string fieldName)(Class value) {
 ...

and call it later as
select!(User, "name")(u);

Here User and "name" are compile-time arguments, you can pass 
there types, values and more exotic stuff like other templates.


And inside the function you can use
__traits(getMember, u, fieldName)
to get field by its name from the passed value.
See: https://dlang.org/spec/traits.html


This was a really nice, short example btw. I'm not OP, but thanks 
for that.


Re: Alias example should supposedly be illegal, but runs fine

2017-12-19 Thread Michael via Digitalmars-d-learn

On Tuesday, 19 December 2017 at 02:12:29 UTC, Mike Franklin wrote:

On Tuesday, 19 December 2017 at 02:04:34 UTC, codephantom wrote:


 writeln(S.j);
 // Error: Instance symbols cannot be used through types.


I don't understand why you would say that is a bug.



I meant that the example is wrong, and a bug report should be 
filed to fix the example.


Mike


Hmm.. but the example is explicitly dealing with when it is valid 
to create an alias for a non-static struct member. Should it 
still not be int? Even if you cannot change it via that alias?


Re: Alias example should supposedly be illegal, but runs fine

2017-12-19 Thread Michael via Digitalmars-d-learn

On Tuesday, 19 December 2017 at 01:29:04 UTC, Meta wrote:

On Monday, 18 December 2017 at 23:44:46 UTC, Michael wrote:

[...]


I think the reason that this works is because i is static, 
meaning that you don't need the `this` reference of S to access 
it and thus it can be aliased. Declaring a static class or 
struct variable is pretty much the same as declaring a global 
variable, just with a tighter scope. If you look at it that 
way, then this makes a lot more sense. If you declare a global 
variable i at module scope, of course you can create an alias 
for it.


Yes I think you're right. I wasn't sure what was going on, just 
noticed that the example definitely isn't right. I'll file a bug 
support and try and fix it.


Alias example should supposedly be illegal, but runs fine

2017-12-18 Thread Michael via Digitalmars-d-learn

Hello,

I have been looking at the following example found right at the 
end of the section here: 
https://dlang.org/spec/declaration.html#alias


struct S { static int i; }
S s;

alias a = s.i; // illegal, s.i is an expression
alias b = S.i; // ok
b = 4; // sets S.i to 4

and it runs fine to me, including if I add:

a = 3;

So, to me I don't see why either can't be valid, but either way 
something needs to be fixed to reflect that this is no longer 
illegal in DMD v2.077.1.


Re: Is there a pragma or command line option to ask DMD to show a warning when it implicitly casts from long to ulong ?

2017-12-15 Thread Michael via Digitalmars-d-learn
On Friday, 15 December 2017 at 21:29:10 UTC, Jonathan M Davis 
wrote:
On Friday, December 15, 2017 20:40:10 Ecstatic Coder via 
Digitalmars-d-learn wrote:
It's taken me some time to find an implicit cast bug ("if 
(my_sometimes_negative_index >= this_array.length)"), while a 
simple C++-like implicit-cast warning would have allowed me to 
find this nasty bug WAY sooner...


No.

https://issues.dlang.org/show_bug.cgi?id=259

- Jonathan M Davis


How does something like this get left for so long...


Re: d-apt update

2017-12-08 Thread Michael via Digitalmars-d-announce

On Friday, 8 December 2017 at 15:53:24 UTC, Jordi Sayol wrote:

d-apt  release dmd v2.077.1

In this release, d-apt splits "dmd-bin" deb package into 
"dmd-compiler" (the command line compiler) and "dmd-tools" 
(includes: dumpobj, obj2asm, rdmd, ddemangle and dustmite).


Best regards,
Jordi.


Yeah this update seemed to break a couple of packages, but was 
fixed just fine.


Re: Release D v2.077.1

2017-11-30 Thread Michael via Digitalmars-d-announce

On Thursday, 30 November 2017 at 13:52:00 UTC, Martin Nowak wrote:

Glad to announce D v2.077.1.

http://dlang.org/download.html

This point release fixes a few issues over v2.077.1, see the 
changelog for more details.


http://dlang.org/changelog/v2.077.1.html

- -Martin


Thanks for all your work, it doesn't go unnoticed!


Re: Shared and race conditions

2017-11-29 Thread Michael via Digitalmars-d-learn
On Wednesday, 29 November 2017 at 17:03:42 UTC, Steven 
Schveighoffer wrote:

On 11/29/17 11:13 AM, Wanderer wrote:
I'm trying to simulate a race condition in D with the 
following code:


(https://run.dlang.io/is/RfOX0I)


One word of caution, I think the running of your code on 
run.dlang.io is cached. Refreshing doesn't make it re-run.


https://run.dlang.io/is/k0LhQA

-Steve


Ah good catch.


Re: Shared and race conditions

2017-11-29 Thread Michael via Digitalmars-d-learn
On Wednesday, 29 November 2017 at 16:33:50 UTC, Steven 
Schveighoffer wrote:

On 11/29/17 11:13 AM, Wanderer wrote:

[...]


[snip]


[...]


Using the compiler switch -vcg-ast, I see no synchronization of 
these methods.


[...]


Any idea what has changed in DMD-nightly to retain the correct 
ordering of IDs?


Re: Shared and race conditions

2017-11-29 Thread Michael via Digitalmars-d-learn

On Wednesday, 29 November 2017 at 16:19:05 UTC, Michael wrote:

On Wednesday, 29 November 2017 at 16:13:13 UTC, Wanderer wrote:

[...]


I unfortunately cannot answer your question but I am noticing 
that running the code with DMD gives you an unordered sequence 
of IDs, but running with DMD-nightly gives you a sequence in 
the correct order. I wonder what has changed to do with threads 
that causes this difference between compiler versions.


Just to add to this, the page here:
https://tour.dlang.org/tour/en/multithreading/synchronization-sharing
does suggest that the compiler will automatically create critical 
sections when it can i.e. wrapping a section in


synchronized {
importStuff();
}


Re: Shared and race conditions

2017-11-29 Thread Michael via Digitalmars-d-learn

On Wednesday, 29 November 2017 at 16:13:13 UTC, Wanderer wrote:
I'm trying to simulate a race condition in D with the following 
code:


(https://run.dlang.io/is/RfOX0I)

```
import std.stdio;
import core.thread;
import std.concurrency;

shared struct IdGen(T)
{
T id;

this(T start)
{
id = start;
}

T next()
{
id = id.next();
return id;
}
}

struct MyId
{
uint num;

shared MyId next()
{
return MyId(num + 1);
}
}

static void getId(shared IdGen!(MyId)* g)
{
writeln("next: ", g.next());
writeln("next: ", g.next());
}

void main()
{
MyId start = {0};
auto g = IdGen!(MyId)(start);

auto num = 12;
for (auto i = 0; i < num; i++)
{
spawn(, );
}

thread_joinAll();
writeln("Done");
}
```

But all I get is correct IDs without any sign of a race (i.e. 
duplicate ids).

Does compiler add synchronization for `shared` data?


I unfortunately cannot answer your question but I am noticing 
that running the code with DMD gives you an unordered sequence of 
IDs, but running with DMD-nightly gives you a sequence in the 
correct order. I wonder what has changed to do with threads that 
causes this difference between compiler versions.


Re: reduce condition nesting

2017-11-23 Thread Michael via Digitalmars-d-learn
On Thursday, 23 November 2017 at 14:16:25 UTC, Andrea Fontana 
wrote:
On Thursday, 23 November 2017 at 13:47:37 UTC, Adam D. Ruppe 
wrote:

On Thursday, 23 November 2017 at 05:19:27 UTC, Andrey wrote:

for instance in kotlin it can be replace with this:

when {
c1 -> foo(),
c2 -> bar(),
c3 -> ...
else -> someDefault()
}


The `switch` statement covers some of these cases too.


Anyway you can create something like this:
https://run.dlang.io/is/7pbVXT


That's pretty cool!


Re: Project Elvis

2017-11-10 Thread Michael via Digitalmars-d

On Friday, 10 November 2017 at 05:23:53 UTC, Adam Wilson wrote:

On 11/6/17 12:20, Michael wrote:

[...]


You're right, I didn't, that was intentional, because sometimes 
people write things like that. And it took a while for anyone 
to say anything about it. That is my point.


But that's the thing. The ?? is significantly more obvious in 
the condensed version.


This is something that a UX designer would recognize instantly, 
but human factors are very definitely not our strong skill as 
engineers. FWIW, my human factors experience comes from the 
deep study of airline crashes that I do as a pilot.



[...]


Two things. ?: is ALSO a change a to language (lexer+parser). 
As to the whole "it's no more likely to typo the colon than the 
question" argument, sure, but that depends on the keyboard 
layout more than anything else, what works for you may not work 
elsewhere. And in either case, it's an easy compiler error. So 
you don't win anything with the ?:, but you win readability 
with the ??. MSFT spends a LOT of time studying these things. 
It would be wise to learn for free from the money they spent.


This is fair, though do we know Microsoft actually put research 
into their choice on this matter? Either way, it would be a nice 
addition, and my preference is for ?: but I'm sure the best case 
will win the others over.


Re: Project Elvis

2017-11-06 Thread Michael via Digitalmars-d
I can't quite see why this proposal is such a big deal to people 
- as has been restated, it's just a quick change in the parser 
for a slight contraction in the code, and nothing 
language-breaking, it's not a big change to the language at all.


On Monday, 6 November 2017 at 19:13:59 UTC, Adam Wilson wrote:
I am all for the Elvis operator, however I have two 
reservations about it. The first is that I don't see much use 
for it without a null-conditional. The second is that the 
current proposed syntax ?: is MUCH to easily confused with ?.


This is not easy to read: obj1?.obj2?.prop3?:constant.

When designing syntax sugar, ergonomics are very important, 
otherwise people won't use it. Microsoft spent a LOT of time 
and treasure to learn these lessons for us. I see no reason to 
ignore them just because "we don't like Microsoft"


My proposal would be to copy what MSFT did, expect that I would 
I would introduce both operators at the same time.


Syntax as follows: obj1?.obj2?.prop3 ?? constant

In practice I don't see much use of the idiom outside of 
null's. The ONLY other thing that would work there is a boolean 
field and you might as well just return the boolean itself 
because the return values have to match types.


I feel this is kind of embellished somewhat. When you write


This is not easy to read: obj1?.obj2?.prop3?:constant.


you're not separating it out as you do when you write your 
preferred version:



Syntax as follows: obj1?.obj2?.prop3 ?? constant


How is


obj1?.obj2?.prop3 ?: constant


not as easy to read as



obj1?.obj2?.prop3 ?? constant


to me they are the same in terms of readability, only with ?? you 
have greater chances of mistyping and adding a second ? in there 
somewhere, whereas the ?: is just a contraction of the current 
syntax, I really don't think it's that difficult, so I'm not sure 
what people's hang-ups are, but I don't think the argument that 
?? is easier to read than ?: holds any weight here, because one 
*is* a change to the language, and the other is a change to the 
parser and a contraction of a standard convention.





Re: html fetcher/parser

2017-08-12 Thread Michael via Digitalmars-d-learn

On Saturday, 12 August 2017 at 20:22:44 UTC, Adam D. Ruppe wrote:

On Saturday, 12 August 2017 at 19:53:22 UTC, Faux Amis wrote:

[...]


My dom.d and http2.d combine to make this easy:

https://github.com/adamdruppe/arsd/blob/master/dom.d
https://github.com/adamdruppe/arsd/blob/master/http2.d

[...]


Sometimes it feels like there's the standard D library, Phobos, 
and then for everything else you have already developed a 
suitable library to supplement it haha!


Re: Vectorflow noob

2017-08-11 Thread Michael via Digitalmars-d-learn

On Thursday, 10 August 2017 at 19:10:05 UTC, Jiyan wrote:

Hey,
wanted to the following simple thing with vectorflow:

[...]


I'm worried there might not be many on the forums who can help 
too much with vectorflow given how new it is. Maybe some in the 
community are more familiar with neural nets and have played wit 
vectorflow already, but I'm not sure. I hope somebody can drop in 
to give you a hand.


Re: I'm the new package maintainer for D on ArchLinux

2017-08-09 Thread Michael via Digitalmars-d-announce

On Wednesday, 9 August 2017 at 20:42:48 UTC, Wild wrote:

Hi everyone,

The D packages for ArchLinux has been orphaned since Dicebot 
stepped down as the maintainer and no one else stepped up. So I 
decided to step up and apply to become a Trusted User, and I 
got accepted yesterday[1]. So from now on I will be the one who 
maintains all the D packages (in the [community] repo), and it 
will be my job to fix them if they break.


[...]


You are very much appreciated! Thanks for all your work!


Re: Calling D from Ruby for GPU computing

2017-08-04 Thread Michael via Digitalmars-d-announce

On Saturday, 29 July 2017 at 06:54:47 UTC, Prasun Anand wrote:

Hi,

I wrote a Linear Mixed Model tool for Genome Wide Association 
Studies(GWAS) called
[faster_lmm_d](https://github.com/prasunanand/faster_lmm_d). It 
is built on LDC
and is faster than its Python alternative. Also, its the only 
GWAS tool with a GPU

backend.

I am interested in porting ` faster_lmm_d` to Ruby. Though, it 
is still a work in progress, I have written a blog about my 
findings.


Blog: 
http://www.prasunanand.com/gpu-computing/2017/07/25/gsoc17-calling-d-from-ruby-for-gpu-computing.html


I would love to hear your feedback.

Regards,
Prasun

[Previously posted on LDC thread: 
http://forum.dlang.org/thread/rzrawenyssbiidsgt...@forum.dlang.org]


I don't know much about your work but it sounds like an 
interesting application for D. How easy was it interfacing with 
cuda? Was it just cuda you targeted or would it also work with 
OpenCL? What made you choose D over going straight to C to work 
directly with cuda?


Re: D books for $5

2017-08-03 Thread Michael via Digitalmars-d-announce

On Friday, 16 December 2016 at 05:43:02 UTC, Kai Nacke wrote:

Hi all,

Packt Publishing offers eBooks for $5 for a limited time. If 
your collection of D eBooks is still incomplete then this is a 
great chance for you. :-)


D Cookbook by Adam D. Ruppe 
(https://www.packtpub.com/application-development/d-cookbook)
Learning D by Michael Parker 
(https://www.packtpub.com/application-development/learning-d)
D Web Development by myself 
(https://www.packtpub.com/web-development/d-web-development)


Regards,
Kai


Any chance the print books are going on sale? I buy too many 
books as a student but would love to learn web dev in D.


Re: Why free and realloc seem to include .

2017-08-03 Thread Michael via Digitalmars-d-learn

On Thursday, 3 August 2017 at 15:29:29 UTC, Adam D. Ruppe wrote:

On Thursday, 3 August 2017 at 15:18:17 UTC, Michael wrote:
I've not seen that either, though I'm not a C++ programmer. 
Does using free() on its own not assume access of a global 
namespace?


Consider the following:

class Foo {
   void free(void*);

   void other_method() {
  free(ptr); // calls the member function
   }
}


The leading dot in D just ensures it calls the global one 
instead of a member (if present).


So it could be used without, but you risk conflicts with other 
functions. I got it, thanks to both of you.


Re: Why free and realloc seem to include .

2017-08-03 Thread Michael via Digitalmars-d-learn

On Thursday, 3 August 2017 at 14:15:40 UTC, Temtaime wrote:

On Thursday, 3 August 2017 at 14:03:56 UTC, Michael wrote:
So this might be a bit of a stupid question, but looking at 
the DMD source code (dmodule.d in particular) I see the 
following code:



[...]


and I was just wondering why certain functions seem to be 
called using the dot operator on its own, unattached to some 
object. This is probably a naive question but I haven't seen 
this in my limited experience using D and I was just wondering 
why this is. I have only really seen this relating to D's 
manual memory management. But in the same file, I see examples 
like this:



[...]


so what is the case when you should use .free() and why not 
just free()? Thanks.


Dot is equal to C++'s :: operator to access a global namespace.
Aka ::free(ptr);


I've not seen that either, though I'm not a C++ programmer. Does 
using free() on its own not assume access of a global namespace?


Why free and realloc seem to include .

2017-08-03 Thread Michael via Digitalmars-d-learn
So this might be a bit of a stupid question, but looking at the 
DMD source code (dmodule.d in particular) I see the following 
code:



if (srcfile._ref == 0)
   .free(srcfile.buffer);
srcfile.buffer = null;
srcfile.len = 0;


and I was just wondering why certain functions seem to be called 
using the dot operator on its own, unattached to some object. 
This is probably a naive question but I haven't seen this in my 
limited experience using D and I was just wondering why this is. 
I have only really seen this relating to D's manual memory 
management. But in the same file, I see examples like this:



FileName.free(n);


so what is the case when you should use .free() and why not just 
free()? Thanks.


Re: Visual D 0.45 released - better VS2017 integration

2017-08-03 Thread Michael via Digitalmars-d-announce

On Thursday, 3 August 2017 at 07:04:55 UTC, Rainer Schuetze wrote:

Hi,

there is a new version 0.45 of Visual D available at 
http://rainers.github.io/visuald/visuald/StartPage.html


Most changes are bug fixes and incremental improvements, maybe 
standing out:


* improved VS 2017 integration
* task list support
* dparser update to recent language additions

See 
http://rainers.github.io/visuald/visuald/VersionHistory.html 
for the full version history.


Visual D is a Visual Studio extension that adds D language 
support to VS2008-2017. It is written in D, its source code can 
be found on github: 
https://github.com/D-Programming-Language/visuald, pull 
requests welcome.


Rainer


Good work! You guys integrating D support into editors are 
awesome and we appreciate the work you do.


Re: is the ubuntu sourceforge repository safe?

2017-08-01 Thread Michael via Digitalmars-d

On Monday, 24 July 2017 at 11:02:55 UTC, Russel Winder wrote:
On Sun, 2017-07-23 at 18:23 +, Michael via Digitalmars-d 
wrote:


I stopped using it. It kept causing error messages in my 
package manager and I couldn't update it properly so I've just 
stuck to downloading the updates on release.


If we are talking about D-Apt here  
http://d-apt.sourceforge.net/  it seems to be working fine for 
me on Debian Sid.  2.075 just installed this morning.


I stopped using it a while ago as it was constantly causing me 
problems with being unable to check for new package updates. It 
was right when sourceforge was issuing security warnings and I 
couldn't be bothered to try and deal with it.


Re: How do you use D?

2017-07-31 Thread Michael via Digitalmars-d

On Friday, 28 July 2017 at 14:58:01 UTC, Ali wrote:

How do you use D?
In work, (key projects or smaller side projects)


I did my undergraduate in CS where I picked up Python, Java and a 
little bit of C/C++, but Java was my most familiar language. When 
I started my PhD in an Engineering Maths department, I picked up 
Andrei's book on D as I had come across the language several 
times earlier but never had a good excuse to pick it up properly. 
My supervisor is more of a mathematician so I did not have any 
dependencies or limitations in the tools I chose to use for 
research. For the first year of my PhD I built models in Java 
with Python for scripting on the side. I was incredibly 
disappointed with the performance in Java, and having been 
learning D on the side during that year, I decided to rewrite it 
using D. I essentially chose D for the one reason many people do 
NOT choose D; I wanted a GC-language that offered a decent level 
of control like C/C++ and was much nicer to write than Java, but 
with the convenience of not having to concern myself too much 
with memory management. I was happy to tune for efficiency, but 
did not want memory management to interrupt my workflow when 
writing a new model. D was perfect for this.



in your side project, (github, links please)


I've been lazy with side projects since I am always trying to 
work on my maths and writing skills which are pretty lacking 
given my choice of degree.


Did you introduce D to your work place? How? What challenges 
did you face?


I've tried to inform people of the merits of D but in this 
department, we're heavily tied to Matlab for teaching. When I 
started, they switched up the undergrad courses and started 
teaching Python as an alternative to Matlab alongside C/Java, but 
there's still a lot of reliance on Matlab. I'd like to see them 
chuck Java and teach C/D but we'll see. At university, there's a 
lot of difficulty in balancing the necessities (C for embedded 
systems/robotics and Matlab for modelling).



What is you D setup at work, which compiler, which IDE?


I've been a long-time Sublime Text user, using DMD (rdmd is a 
life saver) and that's about it. I'm interested in VS Code with 
the dlang extension though.



And any other fun facts you may want to share :)


It makes me sad to see so many people disgruntled by the mere 
presence of a garbage collector. I like it a lot and while I am 
completely on board with moving toward making it more optional, I 
am glad it's there and would welcome speed improvements. I think 
there's a balance to be struck between allowing programmers to 
forget about the low-level memory management when writing 
programs and tuning memory management when optimising for 
performance.


Re: is the ubuntu sourceforge repository safe?

2017-07-23 Thread Michael via Digitalmars-d

On Saturday, 22 July 2017 at 00:21:45 UTC, Ali wrote:
I know that sourceforge doesnt have the best security track 
record

Is it safe thought to use the dmd ubuntu repository hosted there

[code]
sudo wget 
http://master.dl.sourceforge.net/project/d-apt/files/d-apt.list 
-O /etc/apt/sources.list.d/d-apt.list

wget -qO - https://dlang.org/d-keyring.gpg | sudo apt-key add -
sudo apt-get update && sudo apt-get install dmd-bin
[/code]


I stopped using it. It kept causing error messages in my package 
manager and I couldn't update it properly so I've just stuck to 
downloading the updates on release.


Re: Go 1.9

2017-06-25 Thread Michael via Digitalmars-d

On Monday, 19 June 2017 at 15:07:12 UTC, Jack Stouffer wrote:

On Monday, 19 June 2017 at 13:24:00 UTC, Russel Winder wrote:

The former is not a problem for D, but the latter…


Disagree. One of D's biggest competitive advantages is fast 
compilation of fast code. If other languages become as fast or 
faster than DMD in compilation speed then that's a big problem.


I think the problem with this is that compilation speed being the 
no. 1 selling point requires people to invest in large projects 
in order to reap the benefits. However, if you fail to draw them 
in to begin with, then they're not going to commit to a large 
enough project to benefit enough from improved compilation speed.


Re: bug in foreach continue

2017-03-17 Thread Michael via Digitalmars-d-learn

On Friday, 17 March 2017 at 11:30:48 UTC, Jonathan M Davis wrote:
On Friday, March 17, 2017 01:55:19 Hussien via 
Digitalmars-d-learn wrote:


I tend to agree with this. If the foreach is static, and 
continue and break are just going to be ignored, then they 
should just be illegal. Allowing them is just going to confuse 
people. Now, making it so that they actually work statically 
has some interesting possibilities, but that would fall apart 
as soon as you have any constructs that would use continue or 
break (e.g. a loop or switch statement) inside the static 
foreach, and it might break code in rare cases. So, we're 
probably better off just making them illegal. But having them 
be legal just seems disingenious, since they don't do anything.


- Jonathan M Davis


What exactly IS happening in the case of a continue in a 
static-if? I could sort of imagine that maybe if you were 
expecting the loop to be unrolled, that you then have a continue 
statement in the correct part of the unrolled loop. But I take it 
this isn't what's happening?


Re: Any news on DIP88?

2017-03-14 Thread Michael via Digitalmars-d
On Saturday, 11 March 2017 at 19:07:10 UTC, Jonathan M Davis 
wrote:
On Saturday, March 11, 2017 15:25:14 bauss via Digitalmars-d 
wrote:
Are there any news on DIP88? Will it be implemented?, when?, 
is there an implementation currently in development or?


https://wiki.dlang.org/DIP88



So, if someone cares enough, they can propose a new DIP for 
named arguments, but I doubt that it would be accepted, and no 
one has made the attempt regardless, so it definitely hasn't 
been accepted as of now.


- Jonathan M Davis


I just wanted to chime in by saying that I like the syntax of the 
proposal a lot. It's up to those making the decision about 
whether this is approved or rejected but if this is decided to be 
a language feature then the syntax presented is quite appealing.


Re: D to C++

2016-08-31 Thread Michael via Digitalmars-d-learn

On Wednesday, 31 August 2016 at 11:43:12 UTC, Nick wrote:

On Tuesday, 30 August 2016 at 14:24:22 UTC, eugene wrote:

On Tuesday, 30 August 2016 at 13:33:44 UTC, Nick wrote:

Is it possible to compile from D to C++?

Explanation:
I do some competition programming and would like to write it 
in D instead of C++ :)


maybe will help https://wiki.dlang.org/Calypso


That's quite nice, but not what I'm looking for.
What Calypso does, as far as I can see, is to make it possible 
to compile C++ and D together. I'm looking for a compiler that 
takes in D code and spits out either C or C++ code.


I can't imagine that's been done, and I'm not sure it will be 
high on anybody's list of priorities I'm afraid. A lot of work 
was done on automating C++ -> D, but converting D, a language 
intended to replace C++, to C++ itself seems a little backwards. 
I get why you'd like to use it, but I don't think it's been done, 
sorry.


Re: D APT repository fails

2016-07-25 Thread Michael via Digitalmars-d

On Monday, 25 July 2016 at 15:51:50 UTC, Zardoz wrote:
I keep seeing along this last month many problems with the D 
APT repository.

There is any one cheeking the health of these repository ?

Now I get an error with 
"http://master.dl.sourceforge.net/project/d-apt/dists/d-apt/main/binary-amd64/Packages; Wrong header line.


Using a phrase where I live, fails more that a fair shotgun.


I've been noticing this for a while now. There seems to be a 
pattern of downtime. To be honest, given that Google has begun 
warning its users before allowing them to access sourceforge, it 
would be nice to move the repository to another, more stable site.


Re: Card on fire

2016-07-12 Thread Michael via Digitalmars-d

On Monday, 11 July 2016 at 21:29:49 UTC, Walter Bright wrote:

On 7/11/2016 7:49 AM, Meta wrote:

It wouldn't happen to be an nVidia card, would it?


MSI GeForce GT 720 DirectX 12 N720-1GD3HLP 1GB 64-Bit DDR3 PCI 
Express 2.0 x16 HDCP Ready Video Card


The fire happened at the junction between the graphics card and 
the motherboard. I'm not totally sure which failed. Could have 
been a bad capacitor on the motherboard. Maybe it was a defect 
in the connector.


It had been in near continuous use for over a year.


Maybe it's time to invest in some "workstation" / server-grade 
stuff if it's going to be running continuously with little moving 
air.


Re: daffodil, a D image processing library

2016-07-01 Thread Michael via Digitalmars-d-announce

On Friday, 1 July 2016 at 11:09:49 UTC, Relja Ljubobratovic wrote:
On Thursday, 30 June 2016 at 21:35:37 UTC, Benjamin Schaaf 
wrote:

[...]


Hi there. Took a quick look at the source and it seems really 
nice! I like your idea of extensibility for color conversion. 
Also, image I/O seems to be set up quite nicely for a starting 
point. Although I have to comment that bit depth shouldn't be a 
template argument, in my opinion. When loading images, bit 
depth should be determined in the runtime, depending on the 
image you'd be loading at the moment. Or am I wrong? - do you 
have some other way of handing this case?


Also wanted to let you know I've been working on a similar 
library for some time now [1].
Hope we could merge some modules and learn from each other, and 
not have multiple different implementations of the same stuff. 
Please let me know if your interested.


[1] https://github.com/ljubobratovicrelja/dcv


This is how responses should be, so thanks for adding to the 
conversation, unlike the initial commenter.


I do think, as there has been multiple proposed libraries for 
audio/CV/UI models, that some collaboration and merging of the 
more similar modules would benefit greatly from the combined 
effort and increased output, as getting these kinds of libraries 
off the ground seems to be quite slow at first. I'd love to start 
using some CV libraries in D for video processing.


Re: Release D 2.071.1

2016-06-28 Thread Michael via Digitalmars-d-announce

On Monday, 27 June 2016 at 23:26:25 UTC, Jack Stouffer wrote:
On Monday, 27 June 2016 at 23:15:06 UTC, Robert burner Schadek 
wrote:

Awesome, releases are becoming more and more boring. I like it!


I wouldn't call 1.0 * -1.0 == 1.0 boring!


Yeah I was thinking this haha.


Re: I'd love to see DScript one day ...

2016-06-11 Thread Michael via Digitalmars-d
Having DScript running in the browser and D on the server would 
be an absolute dream to develop with. It might also turn a few 
heads our way.


Re: Free the DMD backend

2016-05-31 Thread Michael via Digitalmars-d

On Monday, 30 May 2016 at 15:06:42 UTC, Saurabh Das wrote:

On Monday, 30 May 2016 at 14:51:48 UTC, Matthias Klumpp wrote:

The case for DMD though is compile speed. It really changes the 
way one writes programs and makes it possible to write bash 
script-like functionality in D because of a rapid compile-run 
cycle.


LDC and GDC are quite a bit slower than DMD. Is this gap 
inherent in the structure of these compilers or can there be an 
LDC mode which compiles as rapidly as DMD?


Can this be alleviated with something like rdmd for LDC? Does the 
old ldmd2 project still exist?


Re: Using -O with DMD seems to produce non-random values.

2016-05-19 Thread Michael via Digitalmars-d-learn

On Thursday, 19 May 2016 at 15:49:17 UTC, ag0aep6g wrote:

On 05/19/2016 05:09 PM, Michael wrote:
Any idea what causes this to occur when optimising? I wanted 
to try and

speed up a simulation I'm running but it just produces too many
unexpected consequences.


I suspect that you're seeing issue 16027 [1], a bad bug in 
2.071.0. The upcoming 2.071.1 point release should have it 
fixed.



[1] https://issues.dlang.org/show_bug.cgi?id=16027


Yeah that's what I was thinking but I don't know much about the 
optimisation process so I wanted to mention it anyway.


Re: Using -O with DMD seems to produce non-random values.

2016-05-19 Thread Michael via Digitalmars-d-learn
Could it be that the code is optimised to the same as that in the 
original issue and so the current compiler still produces the 
incorrect result? Obviously the original issue has since been 
fixed but I won't be able to test this until the next version of 
DMD is released.




Using -O with DMD seems to produce non-random values.

2016-05-19 Thread Michael via Digitalmars-d-learn
I'm not entirely sure what optimisations are made when supplying 
the -O flag to rdmd, but this may be related to an earlier issue 
I found for similar code here:

https://issues.dlang.org/show_bug.cgi?id=16027

The code is:
void main()
{
auto seed = 128;
auto rand = Random(seed);
double[] values;

values = generateValues(rand, 10);

writeln(values);
}

double[] generateValues(ref Random rand, int l)
{
auto values = new double[](l);
foreach (ref val; values)
{
auto value = 1.0;
if (uniform(0, 2, rand))
{
value = value * -1;
}
val = value;
}

return values;
}

Which returns different values depending on whether -O is passed:

$rdmd testing_optimiser.d
[1, -1, -1, 1, -1, 1, 1, 1, -1, -1]
$rdmd -O testing_optimiser.d
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]


Any idea what causes this to occur when optimising? I wanted to 
try and speed up a simulation I'm running but it just produces 
too many unexpected consequences.


Re: Beta D 2.071.1-b1

2016-05-18 Thread Michael via Digitalmars-d-announce

On Monday, 16 May 2016 at 20:59:41 UTC, Jack Stouffer wrote:

On Sunday, 15 May 2016 at 04:40:21 UTC, Martin Nowak wrote:

First beta for the 2.071.1 point release.
A few issues remain to be fixed before the next beta.

http://dlang.org/download.html#dmd_beta 
http://dlang.org/changelog/2.071.1.html


Please report any bugs at https://issues.dlang.org

-Martin


This should probably be stalled until 
https://github.com/dlang/dmd/pull/5781 is pulled.


Agreed. A silent regression of this kind is pretty serious, and I 
think it needs to make it into the stable release as soon as 
possible.


Re: Using shorthand *= leads to unexpected result?

2016-05-15 Thread Michael via Digitalmars-d-learn

On Sunday, 15 May 2016 at 14:12:47 UTC, Marc Schütz wrote:

On Sunday, 15 May 2016 at 13:01:45 UTC, Michael wrote:
It may be that I'm doing something wrong here, but after 
updating DMD to the latest version, my simulations started 
producing some very odd results and I think I've pinpointed it 
to a sign inversion that I was making. Here is some code from 
dpaste to demonstrate the behaviour I get vs. the behaviour I 
expected:

https://dpaste.dzfl.pl/9bd7aea75fb2

Any ideas? Am I getting something wrong or is this some sort 
of regression with the latest DMD?


It's a regression introduced here:
https://github.com/dlang/dmd/pull/5534

I've filed a bug report:
https://issues.dlang.org/show_bug.cgi?id=16027


Thanks for filing the bug report, and good find with the 
regression.


Re: Using shorthand *= leads to unexpected result?

2016-05-15 Thread Michael via Digitalmars-d-learn

On Sunday, 15 May 2016 at 13:12:44 UTC, Saurabh Das wrote:

On Sunday, 15 May 2016 at 13:01:45 UTC, Michael wrote:
It may be that I'm doing something wrong here, but after 
updating DMD to the latest version, my simulations started 
producing some very odd results and I think I've pinpointed it 
to a sign inversion that I was making. Here is some code from 
dpaste to demonstrate the behaviour I get vs. the behaviour I 
expected:

https://dpaste.dzfl.pl/9bd7aea75fb2

Any ideas? Am I getting something wrong or is this some sort 
of regression with the latest DMD?


Strangely, if I substitute the variable type 'auto' for 'float' 
or 'real', it gives the expected output of -1. Variable type 
'double' gives the incorrect value of 1.


This is strange behaviour. Perhaps someone more knowledgeable 
can shed light. If it is a regression, it is a very serious 
regression :(


~ sd


Well I'm pretty sure the code was working just fine earlier in 
the week at the office, but running the code at home with the 
newest version of DMD started producing these odd results.


Using shorthand *= leads to unexpected result?

2016-05-15 Thread Michael via Digitalmars-d-learn
It may be that I'm doing something wrong here, but after updating 
DMD to the latest version, my simulations started producing some 
very odd results and I think I've pinpointed it to a sign 
inversion that I was making. Here is some code from dpaste to 
demonstrate the behaviour I get vs. the behaviour I expected:

https://dpaste.dzfl.pl/9bd7aea75fb2

Any ideas? Am I getting something wrong or is this some sort of 
regression with the latest DMD?


Re: Computer Vision Library in D

2016-04-28 Thread Michael via Digitalmars-d-announce
On Thursday, 28 April 2016 at 11:50:55 UTC, Edwin van Leeuwen 
wrote:

On Thursday, 28 April 2016 at 11:32:25 UTC, Michael wrote:
And I would also like to see some more scientific libraries 
make it into D. Though I understand that including it in the 
standard library can cause issues, it would be nice to at 
least get some Linear Algebra libraries in experimental or 
over with the rest of the science libraries.


As I understand it that is part of the goal of mir:
https://code.dlang.org/packages/mir

Not sure if you were aware, but there is also a group with the 
aim to promote scientific dlang work:

https://gitter.im/DlangScience/public


I've seen the mir project and it looks promising. I'm also aware 
of Dlang science and I hope that it gains some support.


Re: Using D in Android App

2016-04-18 Thread Michael via Digitalmars-d-learn

On Monday, 18 April 2016 at 09:38:48 UTC, Justice wrote:

On Saturday, 16 April 2016 at 04:04:24 UTC, Justice wrote:
Is it difficult to create a D business like app and connect it 
to android through java for the interface?


I'd rather create all the complex stuff in D and either use it 
natively through java(I need a UI).


If it is workable, can the same be said for IOS(just recompile 
the D source to the IOS architecture then use it in an IOS app 
for the ui)?


Anyone?


If you're treating the Android/iOS applications as purely 
"client-side", then there's no reason why you can't create a 
"server-side" application in D using something like vibe.d and 
then passing data between clients and servers using JSON or 
similar data interchange formats. That way,you only develop the 
main server-side application in D, and can communicate with it 
using any other language (Java/C#/Swift) on other operating 
systems and devices.


Re: Pitching D to academia

2016-03-09 Thread Michael via Digitalmars-d
On Sunday, 6 March 2016 at 08:40:17 UTC, Ola Fosheim Grøstad 
wrote:

On Sunday, 6 March 2016 at 07:38:01 UTC, Ali Çehreli wrote:
Motivated by Dmitry's "Pitching D to a gang of Gophers" 
thread, how about pitching it to a gang of professors and 
graduate students?


The geeky graduate students are the better target.

In teaching you usually want a focused clean language related 
to the course or a language that is already adopted by industry.


This hold a lot of weight speaking as a current postgraduate. I 
find that when teaching undergraduate courses, you're very much 
restricted to a few things. First, the choice of language to 
teach at the beginning of a student's degree needs to be based on 
what they will continue to use throughout their degree and beyond 
graduating. This means that other modules with specific 
software/library requirements will need to be taken into account 
(no point in teaching D/Go/Rust when you require MATLAB for 
several modules or coursework is required to be submitted in 
C/Java in later years). So it needs to fit with other taught 
units and that means that other members of staff who do not know 
D (and honestly, often don't have the time to learn a new 
language and rewrite all of the course material) will be stuck 
teaching the students another language on top of achieving their 
unit's aims.


Second, a university needs to be able to provide sufficient 
argument for teaching a language in relation to graduate 
employment; If the job market demands C++/Java/Python and only 
know D then problems arise pretty quickly and heads of department 
are not going to approve languages in place of those with high 
industrial demand. For most graduates, experience and skills for 
graduate employment is key.


Postgraduates, on the other hand, often have more time to 
experiment, and due to the nature of postgraduate work 
(particularly Ph.D and beyond) their research tends to require 
novelty. D has proved very valuable for me during my research and 
the lack of library requirements for experiments to be written 
and tested means that I am not tied to using a particular 
language. I am of course not saying that we shouldn't try to 
encourage undergraduates to explore D, but it's very difficult to 
try and introduce a new language into the curriculum at most 
universities without a rather large volume of support and 
justifications for doing so. Just some thoughts.


Re: scope block do not handle failure, but try-catch does

2014-12-11 Thread Michael via Digitalmars-d-learn

On Thursday, 11 December 2014 at 20:40:40 UTC, Suliman wrote:

string dbname = config.getKey(dbname1);
scope(failure) writeln(look like dbname is missing);

I am using dini and trying to throw exception if value can't be 
extract from config. If I am wrap it's in try-сефср block it's 
work or. But in this situation scope block do not execute and I 
see only stack tracing error on console.


Why? What's wrong. By idea if block failure scope should execute


I'm not 100% sure on this, but I suspect you have to declare the 
scope(failure) before you call the code that might execute it.


e.g.

scope(failure) writeln(Looks like the dbname is missing);
string dbname = config.getKey(dbname1);


how to access a ftp sever with socket

2014-12-08 Thread michael via Digitalmars-d-learn
Hello Anyone:
 i am trying make a ftp client with socket,i have tried std.net.curl,but i 
cont stand with so many try-catch structure in my code,i am not familiar with
socket,i write a pecie of code but it cont give me the welcome message which i 
want,and then i use wireshark to trace the comunication,i found that
ftp server:21 send the message to my client:1024,but why there is nothing in 
str buf?thanks for your help.
import std.socket,std.stdio;
void main(){
 string ip = **;//i hide the address
 int msecs = 1000;
 auto ftp = getAddressInfo(ip,ftp);
 Socket listener = new TcpSocket;
 listener.bind(new InternetAddress(1024));
 listener.connect(ftp[0].address);
 auto pair = socketPair();
 auto sock = pair[0];
 sock.setOption(SocketOptionLevel.SOCKET,SocketOption.RCVTIMEO, 
dur!msecs(msecs));
 char[1024] buf;
 sock.receive(buf);
 writeln(buf);
}

 ‍

Re: threading issues with D - C - Python

2014-12-08 Thread Michael via Digitalmars-d-learn

On Monday, 8 December 2014 at 01:17:16 UTC, Ellery Newcomer wrote:

On 12/07/2014 03:12 PM, Michael wrote:
On Saturday, 6 December 2014 at 00:40:49 UTC, Ellery Newcomer 
wrote:

On 12/04/2014 10:55 PM, Ellery Newcomer wrote:

I guess tomorrow I can try messing around with 
thread_attachThis, as the
fullcollect happening in #2 might be screwing with python 
data. But you
aren't really passing anything from python to d or vice 
versa, so I'm
not sure why the gc would need to know about the python 
threads.


by gum, thread_attachThis and thread_detachThis fix the issue!

now to figure out how to use them in the general case.


This is great.. Thank you. I'm looking forward to being able 
to try the

finished result.


It would be great if there were some convenient hook in python 
to stick these calls. Near as I can tell, there isn't. That 
leaves you with either explicitly calling attach and detach 
with an exposed api, or pyd obsessively checking whether the 
current thread is registered.


Actually, I suppose with a thread local flag the latter 
wouldn't be too bad.


Mind if I incorporate your example into pyd's test suite?


Not at all. Go for it.


Re: threading issues with D - C - Python

2014-12-07 Thread Michael via Digitalmars-d-learn
On Saturday, 6 December 2014 at 00:40:49 UTC, Ellery Newcomer 
wrote:

On 12/04/2014 10:55 PM, Ellery Newcomer wrote:

I guess tomorrow I can try messing around with 
thread_attachThis, as the
fullcollect happening in #2 might be screwing with python 
data. But you
aren't really passing anything from python to d or vice versa, 
so I'm
not sure why the gc would need to know about the python 
threads.


by gum, thread_attachThis and thread_detachThis fix the issue!

now to figure out how to use them in the general case.


This is great.. Thank you. I'm looking forward to being able to 
try the finished result.


Re: threading issues with D - C - Python

2014-12-04 Thread Michael via Digitalmars-d-learn
On Thursday, 4 December 2014 at 03:22:05 UTC, Ellery Newcomer 
wrote:


dustmite?


Not sure what went wrong with dustmite, but every time I tried it 
it just started deleting all the files in the directory and 
setup.py would give errors. I manually deleted a reasonable chunk 
of the code and I'm left with these files which still seem to 
cause segfaults:


Main code: http://pastebin.com/zqgNTk9w
PyD definitions: http://pastebin.com/6mRH3KZZ
setup.py: http://pastebin.com/i9Ph78UC
test code that causes segfaults: http://pastebin.com/1ukzShVh

Cheers,
Michael.


  1   2   >