Re: Benchmarking sigmoid function between C and D

2018-04-07 Thread Arun Chandrasekaran via Digitalmars-d-learn

On Saturday, 7 April 2018 at 23:48:36 UTC, kinke wrote:
On Saturday, 7 April 2018 at 20:33:13 UTC, Arun Chandrasekaran 
wrote:

[...]


As this appears to be benchmarking mostly the 
std.math.exp(float) performance - some/many basic algos in 
std.math, incl. exp(), are currently using the x87 FPU for all 
3 floating-point types, although there are treacherous 
float/double overloads, sacrificing performance in many cases.
See 
https://github.com/dlang/phobos/pull/6272#issuecomment-373967109 (and the later numbers for current Intel and GCC compilers) for a performance comparison of some std.math algos incl. exp(). For LDC, the double/float versions of the few worked-on algos in that PR were sped-up by an overall factor of 3 [but only by 1.46 for exp(float)].


Interesting to see this, thanks! Did you also generate the bar 
graph plot using D?


Re: Dockerfile with cross-compiler targeting Windows x64

2018-04-07 Thread kinke via Digitalmars-d-announce

On Saturday, 7 April 2018 at 14:05:15 UTC, Seb wrote:
Hmm how hard would it be to use the MinGW libraries like DMD is 
doing as a fallback since 2.079?


The MinGW ones for the Windows API may do, but the VS 2010 
libraries are not an option for LDC, we require at least 2015 
(which introduced the 'Universal CRT', probably making things 
more complicated). I'd also prefer to keep on defaulting to the 
static C runtime in order not to produce binaries depending on 
Visual C++ DLLs (hindering portability of Windows binaries).


Re: HTTP-methods and encoding

2018-04-07 Thread Vindex via Digitalmars-d-learn

On Saturday, 7 April 2018 at 15:58:14 UTC, Seb wrote:

On Saturday, 7 April 2018 at 13:02:39 UTC, Vindex wrote:
There is an error on some sites when using HTTP-methods 
(std.net.curl.get, std.net.curl.post):
std.encoding.EncodingException@std/encoding.d(2505): 
Unrecognized Encoding: utf8


Is there a beautiful way around it?
For the GET-method I use the download() and readText(). But 
for the POST-method I can not come up with an alternative 
solution.


That's weird. std.net.curl should be able to handle UTF-8.
What content are you trying to download/post?
Maybe you can open a bug report for it?

In any case, you might want to checkout requests:

https://github.com/ikod/dlang-requests

It's by far more convenient to use than std.net.curl


The problem is that "utf-8" (or "UTF-8") is required instead of 
"utf8".


I tried to get HTML and JSON. For example, this GET-query returns 
error:

"https://yobit.net/api/3/ticker/btc_usd;

Thank you for the advice


Re: Benchmarking sigmoid function between C and D

2018-04-07 Thread kinke via Digitalmars-d-learn
On Saturday, 7 April 2018 at 20:33:13 UTC, Arun Chandrasekaran 
wrote:
Much better with mir.math.common, still a bit slower than C 
(even with larger loops):


As this appears to be benchmarking mostly the std.math.exp(float) 
performance - some/many basic algos in std.math, incl. exp(), are 
currently using the x87 FPU for all 3 floating-point types, 
although there are treacherous float/double overloads, 
sacrificing performance in many cases.
See 
https://github.com/dlang/phobos/pull/6272#issuecomment-373967109 
(and the later numbers for current Intel and GCC compilers) for a 
performance comparison of some std.math algos incl. exp(). For 
LDC, the double/float versions of the few worked-on algos in that 
PR were sped-up by an overall factor of 3 [but only by 1.46 for 
exp(float)].


Re: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/, [your code here]

2018-04-07 Thread bauss via Digitalmars-d

On Friday, 6 April 2018 at 14:03:18 UTC, Abdulhaq wrote:

On Friday, 6 April 2018 at 13:10:07 UTC, jason wrote:

what is this?


It's a perl program that converts D code into APL


Here is a more readable version:

(?:(?:\r\n)?[ \t])*(?:(?:(?:[^()<>@,;:\\".\[\] 
\000-\031]+(?:(?:(?:\r\n)?[ \t]
)+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ 
\t]))*"(?:(?:
\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] 
\000-\031]+(?:(?:(
?:\r\n)?[ 
\t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[
\t]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ 
\t])*(?:[^()<>@,;:\\".\[\] \000-\0
31]+(?:(?:(?:\r\n)?[ 
\t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\
](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ 
\t])*(?:[^()<>@,;:\\".\[\] \000-\031]+
(?:(?:(?:\r\n)?[ 
\t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:
(?:\r\n)?[ \t])*))*|(?:[^()<>@,;:\\".\[\] 
\000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z
|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ 
\t]))*"(?:(?:\r\n)
?[ \t])*)*\<(?:(?:\r\n)?[ \t])*(?:@(?:[^()<>@,;:\\".\[\] 
\000-\031]+(?:(?:(?:\
r\n)?[ 
\t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[
 \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] 
\000-\031]+(?:(?:(?:\r\n)
?[ 
\t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t]
)*))*(?:,@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] 
\000-\031]+(?:(?:(?:\r\n)?[
 
\t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*
)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] 
\000-\031]+(?:(?:(?:\r\n)?[ \t]

)+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*)
*:(?:(?:\r\n)?[ \t])*)?(?:[^()<>@,;:\\".\[\] 
\000-\031]+(?:(?:(?:\r\n)?[ \t])+
|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ 
\t]))*"(?:(?:\r
\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] 
\000-\031]+(?:(?:(?:
\r\n)?[ 
\t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t
]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ 
\t])*(?:[^()<>@,;:\\".\[\] \000-\031
]+(?:(?:(?:\r\n)?[ 
\t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](
?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] 
\000-\031]+(?
:(?:(?:\r\n)?[ 
\t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?
:\r\n)?[ \t])*))*\>(?:(?:\r\n)?[ \t])*)|(?:[^()<>@,;:\\".\[\] 
\000-\031]+(?:(?
:(?:\r\n)?[ 
\t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?
[ \t]))*"(?:(?:\r\n)?[ \t])*)*:(?:(?:\r\n)?[ 
\t])*(?:(?:(?:[^()<>@,;:\\".\[\]
\000-\031]+(?:(?:(?:\r\n)?[ 
\t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|
\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ 
\t])*(?:[^()<>
@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ 
\t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"
(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ 
\t])*))*@(?:(?:\r\n)?[ \t]
)*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ 
\t])+|\Z|(?=[\["()<>@,;:\\
".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ 
\t])*)(?:\.(?:(?:\r\n)?[ \t])*(?
:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ 
\t])+|\Z|(?=[\["()<>@,;:\\".\[
\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ 
\t])*))*|(?:[^()<>@,;:\\".\[\] \000-
\031]+(?:(?:(?:\r\n)?[ 
\t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(
?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)*\<(?:(?:\r\n)?[ 
\t])*(?:@(?:[^()<>@,;
:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ 
\t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([
^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ 
\t])*(?:[^()<>@,;:\\"
.\[\] \000-\031]+(?:(?:(?:\r\n)?[ 
\t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\
]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*(?:,@(?:(?:\r\n)?[ 
\t])*(?:[^()<>@,;:\\".\
[\] \000-\031]+(?:(?:(?:\r\n)?[ 
\t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\
r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ 
\t])*(?:[^()<>@,;:\\".\[\]
\000-\031]+(?:(?:(?:\r\n)?[ 
\t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]
|\\.)*\](?:(?:\r\n)?[ \t])*))*)*:(?:(?:\r\n)?[ 
\t])*)?(?:[^()<>@,;:\\".\[\] \0
00-\031]+(?:(?:(?:\r\n)?[ 
\t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\
.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ 
\t])*(?:[^()<>@,
;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ 
\t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?
:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ 
\t])*))*@(?:(?:\r\n)?[ \t])*
(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ 
\t])+|\Z|(?=[\["()<>@,;:\\".
\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ 
\t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[
^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ 
\t])+|\Z|(?=[\["()<>@,;:\\".\[\]
]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*\>(?:(?:\r\n)?[ 
\t])*)(?:,\s*(
?:(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ 
\t])+|\Z|(?=[\["()<>@,;:\\
".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ 
\t])*)(?:\.(?:(
?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ 
\t])+|\Z|(?=[
\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ 
\t]))*"(?:(?:\r\n)?[ \t
])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] 

Re: DIP 1009 (Add Expression-Based Contract Syntax) Accepted

2018-04-07 Thread Zach Tollen via Digitalmars-d-announce

On Saturday, 7 April 2018 at 20:06:19 UTC, Jordan Wilson wrote:
Although https://dlang.org/spec/contracts.html will surely be 
updated with this new syntax, I think a blog post would also 
help in this regard, I think.


Jordan


That's a good idea. I'll start on one.


Re: Registering packages crashed DUB registry

2018-04-07 Thread Sönke Ludwig via Digitalmars-d

Am 07.04.2018 um 23:57 schrieb Sönke Ludwig:

Am 07.04.2018 um 21:49 schrieb 0xEAB:

Hello :)

Tried to add a new package, but after clicking on [Register package] I 
only get the following error:



502 Bad Gateway
nginx/1.6.2



Regards,
Elias



Bug report: https://github.com/dlang/dub/issues/1441
PR: https://github.com/dlang/dub-registry/pull/318


The fix is deployed on the server now, so registering packages should 
work correctly again now.


[Issue 18744] Class l-values can be implicitly converted to `Object` l-values, even in safe code

2018-04-07 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18744

Stefan  changed:

   What|Removed |Added

 CC||kde...@vogtner.de

--


Re: Hamburg meets D

2018-04-07 Thread Stephan via Digitalmars-d-announce

On Wednesday, 4 April 2018 at 20:57:13 UTC, Stefan wrote:

On Monday, 5 March 2018 at 19:40:12 UTC, Stephan wrote:

Hello fellow Dlers,

thanks to last years DConf some German D developers agreed to 
meet for drinks in Hamburg.


congratz!

how was it?
hope a next meetup is already planned.


It was great! I wanna thank everyone coming, we had great 
discussions, pizza and a little vibe.d feature actually arose out 
of it! And we were 5 people actually :)


I guess after dconf we will start planning the next date.

~Stephan


Re: that is bug?

2018-04-07 Thread David Nadlinger via Digitalmars-d

On Saturday, 7 April 2018 at 09:07:48 UTC, sdvcn wrote:

true?stt="AA":stt="BB";-///Out:BB
writeln(stt);


As I just pointed out in Ali's bug report [1], this is correct, as

true ? stt = "AA" : stt = "BB"

means

(true ? (stt = "AA") : stt) = "BB",

in accordance to D's grammar [2]:

AssignExpression:
ConditionalExpression
ConditionalExpression = AssignExpression
[…]

We should probably require explicit parentheses here. Relying on 
this behaviour is just asking for trouble anyway, as evidenced by 
the amount of confusion in this thread.


 — David



[1] https://issues.dlang.org/show_bug.cgi?id=18743
[2] https://dlang.org/spec/expression.html#assign_expressions


Re: that is bug?

2018-04-07 Thread David Nadlinger via Digitalmars-d

On Saturday, 7 April 2018 at 21:22:07 UTC, kdevel wrote:
Can the ternary conditional even be used to assign objects of 
the wrong type?

[…]


Congratulations, I'm pretty sure you found an actual bug, even 
though it doesn't have anything to do with the conditional 
operator per se: https://issues.dlang.org/show_bug.cgi?id=18744


 — David


[Issue 18744] New: Class l-values can be implicitly converted to `Object` l-values, even in safe code

2018-04-07 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18744

  Issue ID: 18744
   Summary: Class l-values can be implicitly converted to `Object`
l-values, even in safe code
   Product: D
   Version: D2
  Hardware: All
OS: All
Status: NEW
  Keywords: accepts-invalid, safe
  Severity: major
  Priority: P1
 Component: dmd
  Assignee: nob...@puremagic.com
  Reporter: c...@klickverbot.at

---
@safe:

class A { int* a; }
class B { long b; }

// Either of these shouldn't be allowed:
void boom1(ref A a, B b) { (cast(Object)a) = b; }
void boom2(ref A a, B b) { (true ? a : b) = b; }

int main() {
  A a = new A;
  B b = new B;
  boom1(a, b);
  boom2(a, b);
  return *a.a;
}
---

compiles fine on DMD 2.079, but covariance in l-values can't be allowed. This
is the same problem often illustrated using containers.

--


Re: Registering packages crashed DUB registry

2018-04-07 Thread Sönke Ludwig via Digitalmars-d

Am 07.04.2018 um 21:49 schrieb 0xEAB:

Hello :)

Tried to add a new package, but after clicking on [Register package] I 
only get the following error:



502 Bad Gateway
nginx/1.6.2



Regards,
Elias



Bug report: https://github.com/dlang/dub/issues/1441
PR: https://github.com/dlang/dub-registry/pull/318


Re: Benchmarking sigmoid function between C and D

2018-04-07 Thread Guillaume Piolat via Digitalmars-d-learn
On Saturday, 7 April 2018 at 20:33:13 UTC, Arun Chandrasekaran 
wrote:

On Saturday, 7 April 2018 at 19:14:27 UTC, Daniel Kozak wrote:
or for ldc 
http://docs.algorithm.dlang.io/latest/mir_math_common.html


On Sat, Apr 7, 2018 at 9:10 PM, Daniel Kozak 
 wrote:



can you try it with c math functions?

instead of std.math, try to use core.stdc.math

On Sat, Apr 7, 2018 at 8:53 PM, Arun Chandrasekaran via 
Digitalmars-d-learn  wrote:



[...]


Much better with mir.math.common, still a bit slower than C 
(even with larger loops):


10^7 iterations using sigmoid1: 168 ms
10^7 iterations using sigmoid2: 39 ms

Also LDC optimized away the computation. So I had to modify the 
code a bit.





Have you tried LLVM intrinsics? say llvm_exp


[Issue 18743] ConditionalExpression and AssignExpression should require parentheses

2018-04-07 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18743

--- Comment #2 from David Nadlinger  ---
(Note that this _is_ part of the specification in form of the grammar.
Assignment is defined as 

AssignExpression:
ConditionalExpression
ConditionalExpression = AssignExpression
ConditionalExpression += AssignExpression
ConditionalExpression -= AssignExpression
ConditionalExpression *= AssignExpression
ConditionalExpression /= AssignExpression
ConditionalExpression %= AssignExpression
ConditionalExpression &= AssignExpression
ConditionalExpression |= AssignExpression
ConditionalExpression ^= AssignExpression
ConditionalExpression ~= AssignExpression
ConditionalExpression <<= AssignExpression
ConditionalExpression >>= AssignExpression
ConditionalExpression >>>= AssignExpression
ConditionalExpression ^^= AssignExpression

which unambiguously specifies the precedence.)

--


[Issue 18743] ConditionalExpression and AssignExpression should require parentheses

2018-04-07 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18743

David Nadlinger  changed:

   What|Removed |Added

 CC||c...@klickverbot.at
   Hardware|x86_64  |All
Summary|Conditional expression  |ConditionalExpression and
   |(ternary operator) can  |AssignExpression should
   |evaluate the third  |require parentheses
   |expression even "If it is   |
   |true"   |
 OS|Linux   |All
   Severity|normal  |enhancement

--- Comment #1 from David Nadlinger  ---
This isn't a bug.

In D, ?: has higher precedence than =, so

true ? stt = "AA" : stt = "BB"

means

(true ? (stt = "AA") : stt) = "BB",

in line with C and other languages, but notably not C++.

The operator precedence should be documented somewhere, though; while there is
a table in TDPL (p. 61 ff.) and on the Wiki
(https://wiki.dlang.org/Operator_precedence), I can't seem to find it on
dlang.org/spec.

---

Changing this to an enhancement request, as we should really consider requiring
explicit parenthesization for this sort of error-prone code, similar to how we
disallow assignment expressions in if statements.

--


Re: that is bug?

2018-04-07 Thread kdevel via Digitalmars-d

On Saturday, 7 April 2018 at 19:44:35 UTC, Ali wrote:

so it seems
that since
b = (true ? stt="AA": stt )="BB";
and
b = true ? stt="AA": stt ="BB";

are equivalent
that

that the ternary operator return stt (after assigning it "AA") 
then assign "BB" to it


Can the ternary conditional even be used to assign objects of the 
wrong type?


dcondo.d
---
import std.stdio;

class A {
   int a;
   this (int i)
   {
  a = i;
   }
}

class C {
   int c;
   this (int i)
   {
  c = i;
   }
}

void dump (A a, A b, C c, C d)
{
   a.writeln;
   b.writeln;
   c.writeln;
   d.writeln;
   a.a.writeln;
   b.a.writeln;
   c.c.writeln;
   d.c.writeln;
}

void main ()
{
   A a = new A (1), b = new A (2);
   C c = new C (3), d = new C (4);
   dump (a, b, c, d);
   true ? a = b : c = d;
//   a = c; // Error: cannot implicitly convert expression
//   c = a; // Error: cannot implicitly convert expression
   dump (a, b, c, d);
}
---

Output:

dcondo.A
dcondo.A
dcondo.C
dcondo.C
1
2
3
4
dcondo.C
dcondo.A
dcondo.C
dcondo.C
4
2
3
4



Re: Store struct tuple of alias and access members through it?

2018-04-07 Thread Alex via Digitalmars-d-learn

On Saturday, 7 April 2018 at 13:31:01 UTC, Timoses wrote:

Simen was faster :)

In my solution I simply ignore such things as functions... But 
there is the cool delegate creation approach in Simen's solution 
for this. I can handle arrays instead. :)

And I got rid of tupelof acting on an instance.

Be aware, that bitfields create more fields then the delegates 
for the bitfield's members...


import std.stdio;
import std.bitmanip;
import std.traits;

void main()
{
S s;
Param!S example = new Param!S(s);

writeln(example[0]);
writeln(example[1]);
writeln(example[2]);
writeln(example[3]);
writeln(example[4]);
writeln(example[5]);
writeln(example[6]);

writeln([__traits(allMembers, S)]);

writeln(example[15]);
writeln(example[16]);
writeln(example[17]);
writeln(example[18]);
}

struct S
{
uint s1;
ushort s2;

string s3;
float s4;

mixin(bitfields!(
uint, "x",2,
int,  "y",3,
uint, "z",2,
bool, "flag", 1));

size_t fun(){ return 42; }

size_t delegate() dg;

size_t[] arr;

static void fun(){}
}

interface IParam{}

class Param(T) : IParam
{
T m;
this(T m)
{
this.m = m;
}

IParam opIndex(size_t i)
{
//static if(!isBasicType!T)
static if(__traits(compiles, __traits(allMembers, T)))
{
static foreach (j, t; __traits(allMembers, T))
{
if (i == j)
{
		static if(__traits(compiles, new 
Param!(typeof(__traits(getMember, this.m, 
t)))(__traits(getMember, this.m, t

{
			return new Param!(typeof(__traits(getMember, 
this.m, t)))(__traits(getMember, this.m, t));

}
}
}
}
return null;
}
}


Re: that is bug?

2018-04-07 Thread kdevel via Digitalmars-d

On Saturday, 7 April 2018 at 16:52:00 UTC, Patrick Schluter wrote:
[...]
The odd man out is C++ [1], assignment has higher precedence 
because of right to left evaluation.


Your reference [1] is not even a witness to your claim. The 
precedence table says that the "Ternary conditional" has the 
*same* precedence as the "Direct Assigment", namely "16".


You may find an in-depth discussion of the C++ case in

https://stackoverflow.com/questions/7499400/ternary-conditional-and-assignment-operator-precedence


[Issue 18743] Conditional expression (ternary operator) can evaluate the third expression even "If it is true"

2018-04-07 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18743

Ketmar Dark  changed:

   What|Removed |Added

 CC||ket...@ketmar.no-ip.org

--


Re: Is it a bug that a parent class that access its own private members from derived classes gets deprecation warning?

2018-04-07 Thread bauss via Digitalmars-d

On Saturday, 7 April 2018 at 20:34:57 UTC, user1234 wrote:

On Saturday, 7 April 2018 at 20:14:49 UTC, bauss wrote:

jesus that became a long title.

Anyway as the title says, is it a bug that a parent class that 
access its own private members from derived classes gets 
deprecation warning?


If the import is selective no. (`import foo : Foo;`)
If the import is for the whole module i'd say yes. (`import 
foo;`)


What do you mean?

The problem is that "Foo" cannot access "_baz" without 
deperecation warning, but "_baz" is a part of "Foo".


Re: Registering packages crashed DUB registry

2018-04-07 Thread bauss via Digitalmars-d

On Saturday, 7 April 2018 at 20:44:12 UTC, 0xEAB wrote:

On Saturday, 7 April 2018 at 20:17:41 UTC, bauss wrote:

On Saturday, 7 April 2018 at 19:49:31 UTC, 0xEAB wrote:

Hello :)

Tried to add a new package, but after clicking on [Register 
package] I only get the following error:



502 Bad Gateway
nginx/1.6.2



Regards,
Elias


I don't think that was the case.

code.dlang.org has been having a lot of issues lately it seems.

It's down a lot.


But it happens again everytime I re-submit the package.


Maybe yours does do it, I don't know.

But it has been down multiple times for me today alone.


Re: Is it a bug that a parent class that access its own private members from derived classes gets deprecation warning?

2018-04-07 Thread bauss via Digitalmars-d

On Saturday, 7 April 2018 at 20:46:39 UTC, bauss wrote:
The problem is that "Foo" cannot access "_baz" without 
deperecation warning, but "_baz" is a part of "Foo".


I'm not trying to access "_baz" directly from "Bar" except for 
that I call the templated function that access "_baz", but that 
function is a part of "Foo"


Re: Registering packages crashed DUB registry

2018-04-07 Thread 0xEAB via Digitalmars-d

On Saturday, 7 April 2018 at 20:17:41 UTC, bauss wrote:

On Saturday, 7 April 2018 at 19:49:31 UTC, 0xEAB wrote:

Hello :)

Tried to add a new package, but after clicking on [Register 
package] I only get the following error:



502 Bad Gateway
nginx/1.6.2



Regards,
Elias


I don't think that was the case.

code.dlang.org has been having a lot of issues lately it seems.

It's down a lot.


But it happens again everytime I re-submit the package.


Re: Benchmarking sigmoid function between C and D

2018-04-07 Thread Arun Chandrasekaran via Digitalmars-d-learn

On Saturday, 7 April 2018 at 19:14:27 UTC, Daniel Kozak wrote:
or for ldc 
http://docs.algorithm.dlang.io/latest/mir_math_common.html


On Sat, Apr 7, 2018 at 9:10 PM, Daniel Kozak 
 wrote:



can you try it with c math functions?

instead of std.math, try to use core.stdc.math

On Sat, Apr 7, 2018 at 8:53 PM, Arun Chandrasekaran via 
Digitalmars-d-learn  wrote:



[...]


Much better with mir.math.common, still a bit slower than C (even 
with larger loops):


10^7 iterations using sigmoid1: 168 ms
10^7 iterations using sigmoid2: 39 ms

Also LDC optimized away the computation. So I had to modify the 
code a bit.


```
private auto sigmoid1_perf() {
auto sw = StopWatch(AutoStart.yes);
int i;
float x, y = 0.0f;

for (i = 0; i < 10; i++) {
for (x = -5.0f; x <= 5.0f; x+=0.1f) {
y += sigmoid1(x);
}
}
auto t = sw.peek.total!"msecs";
return tuple(y, t);
}

private auto sigmoid2_perf() {
auto sw = StopWatch(AutoStart.yes);
int i;
float x, y = 0.0f;
for (i = 0; i < 10; i++) {
for (x = -5.0f; x <= 5.0f; x+=0.1f) {
y += sigmoid2(x);
}
}
auto t = sw.peek.total!"msecs";
return tuple(y, t);
}
```


Re: Is it a bug that a parent class that access its own private members from derived classes gets deprecation warning?

2018-04-07 Thread user1234 via Digitalmars-d

On Saturday, 7 April 2018 at 20:14:49 UTC, bauss wrote:

jesus that became a long title.

Anyway as the title says, is it a bug that a parent class that 
access its own private members from derived classes gets 
deprecation warning?


If the import is selective no. (`import foo : Foo;`)
If the import is for the whole module i'd say yes. (`import foo;`)




Re: Registering packages crashed DUB registry

2018-04-07 Thread bauss via Digitalmars-d

On Saturday, 7 April 2018 at 19:49:31 UTC, 0xEAB wrote:

Hello :)

Tried to add a new package, but after clicking on [Register 
package] I only get the following error:



502 Bad Gateway
nginx/1.6.2



Regards,
Elias


I don't think that was the case.

code.dlang.org has been having a lot of issues lately it seems.

It's down a lot.


Re: Is it a bug that a parent class that access its own private members from derived classes gets deprecation warning?

2018-04-07 Thread bauss via Digitalmars-d

On Saturday, 7 April 2018 at 20:14:49 UTC, bauss wrote:

foreach (child; values)
{
  child._isChild = true;
}


I forgot: _isChild should be _baz in the narrowed down version.


Is it a bug that a parent class that access its own private members from derived classes gets deprecation warning?

2018-04-07 Thread bauss via Digitalmars-d

jesus that became a long title.

Anyway as the title says, is it a bug that a parent class that 
access its own private members from derived classes gets 
deprecation warning?


Scenario narrowed down:

// module foo;
class Foo
{
private:
bool _baz;

public:
final void foos(T : Foo)(string key, T[] values)
{
  if (values && values.length)
  {
foreach (child; values)
{
  child._isChild = true;
}
  }
}
}

// module bar;
class Bar : Foo
{
}

The above in my case will give a deprecation warning that "_baz" 
isn't visible from "Bar".


Seems like a bug to me since I'm accessing "_baz" from "Foo" 
itself and not from "Bar" or is it by design that you can't do 
such thing.


I'm thinking it's because of my templated function perhaps?

I haven't decoupled it out of my project to make a separate 
compilation, I just want to clarify it's not a design thing 
first, because if it's by design then I don't want to spend more 
time on it than necessary.


If it's not by design then I'll narrow it down even more, to see 
if it's reproducable as above.


(I did not test the narrowed down version.)


Create bitcoin genesis block in d language

2018-04-07 Thread aerto via Digitalmars-d-announce
was playing around with d, i write a pure implementation of 
bitcoin genesis block creation in dlang 
https://github.com/cvsae/genesisd


Registering packages crashed DUB registry

2018-04-07 Thread 0xEAB via Digitalmars-d

Hello :)

Tried to add a new package, but after clicking on [Register 
package] I only get the following error:



502 Bad Gateway
nginx/1.6.2



Regards,
Elias



Re: that is bug?

2018-04-07 Thread Ali via Digitalmars-d

On Saturday, 7 April 2018 at 18:52:56 UTC, Ali Çehreli wrote:

On 04/07/2018 10:53 AM, Ali wrote:
> On Saturday, 7 April 2018 at 15:26:56 UTC, Ali Çehreli wrote:
>> On 04/07/2018 02:07 AM, sdvcn wrote:
>>>  string stt = "none";
>>>  true?writeln("AA"):writeln("BB");   ///Out:AA
>>>  true?stt="AA":stt="BB";-///Out:BB
>>>  writeln(stt);
>>
>> It is a bug because the behavior does not match the spec:
>>
>>   https://issues.dlang.org/show_bug.cgi?id=18743
>>
>> Ali
>
> Hi Ali C
>
> I think it also a bug because the ternary seem to be
returning the
> second part

Maybe... but the following is not a good test for that because 
the return value of the assignment operator would always be stt 
regardless of which expression is evaluated.


>
> try
>
>  string stt = "none";
>  string b = "";
>  true?writeln("AA"):writeln("BB");   ///Out:AA
>  b = (true ? stt="AA":stt="BB");///Out:BB
>  writeln(stt);
>  writeln(b); ///Out:BB

I tried something else and noticed that it doesn't actually 
evaluate the third expression because b is never changed:


import std.stdio;

void main() {
int a;
int b;
int * c = &(true ? a = 1 : b = 2);
writefln("a:%s %s", a, );
writefln("b:%s %s", b, );
writefln("c:  %s", c);
}

Output:

a:2 7FFDBBF57DB0  <-- Got the value of the third expression 
(BAD)

b:0 7FFDBBF57DB4  <-- Not changed (good)
c:  7FFDBBF57DB0  <-- Address of a (good)

So, the expression correctly decides to affect and returns 'a' 
but uses the wrong value to assign.


Ali


this kinda explains what happens to me
try
string stt = "none";
string b = "";
true?writeln("AA"):writeln("BB");
b = (true ? stt="AA": stt )="BB";
writeln(stt);
writeln(b);

output
AA
BB
BB

now try

string stt = "none";
string b = "";
true?writeln("AA"):writeln("BB");   ///Out:AA
(b = (true ? stt="AA": stt ))="BB";///Out:BB
writeln(stt);
writeln(b);

output
AA
AA
BB

so it seems
that since
b = (true ? stt="AA": stt )="BB";
and
b = true ? stt="AA": stt ="BB";

are equivalent
that

that the ternary operator return stt (after assigning it "AA") 
then assign "BB" to it





Re: Store struct tuple of alias and access members through it?

2018-04-07 Thread Simen Kjærås via Digitalmars-d-learn

On Saturday, 7 April 2018 at 13:31:01 UTC, Timoses wrote:

In the end I would like to accomplish the following:
Provide access to contained bitfields and members of a struct 
in the order they

appear in the struct via an index.


The behavior of Type.tupleof in D seems a bit unfinished - they 
can't be passed to other functions, they can't be directly used 
to get the member they refer to, and the indirect way is clunky.


Anyways. Your desired code `return this.m.members[i];` is, as you 
have noticed, impossible. There's multiple reasons for that - 
first, `members` can't be used like that. Second, since you need 
to wrap it in a Param instance, you need more information than 
that. Third, there's a clear distinction in D between 
compile-time and run-time values, so you need the static foreach 
there to get the right compile-time value.


Now, what *can* we do?

First, there's no need for __traits(getMember, this.m, 
members[j].stringof), since the index into T.tupleof is the exact 
same as for m.tupleof. In other words, you could use


return new Param!(typeof(m.tupleof[j]))(m.tupleof[j]);

I think that is clearer. I'd suggest also creating this function:

IParam param(T)(T value) {
return new Param!T(value);
}

That way, the above line would be

return param(m.tupleof[j]);

Handling methods is a tad more complicated, and you will not get 
the correct interleaving of methods and fields, which may or may 
not be a problem to you.


Here's my attempt at solving all your problems. There may be 
things I've misunderstood, forgotten or ignored, and there are 
certainly places where I'm unsure.



import std.meta;
import std.traits;

// List all member functions, and wrap them such that 
myFoo.fun(3) can be called as 
AllMemberFunctions!(typeof(myFoo))[idx](myFoo, 3).

template AllMemberFunctions(T)
{
template createDg(alias fn)
{
static if (__traits(isStaticFunction, fn))
alias createDg = fn;
else
ReturnType!fn createDg(ref T ctx, Parameters!fn args)
{
ReturnType!fn delegate(Parameters!fn) fun;
fun.funcptr = 
fun.ptr = cast(void*)
return fun(args);
}
}

alias GetOverloads(string name) = 
AliasSeq!(__traits(getOverloads, T, name));


alias AllMemberFunctions = staticMap!(createDg, 
staticMap!(GetOverloads, __traits(allMembers, T)));

}

interface IParam
{
// Moved this here, since otherwise you'd need to know the
// exact template parameters to Param to get to anything.
IParam opIndex(size_t i);
}


// Simplified template definition.
class Param(T) : IParam
{
T m;
this(T m)
{
this.m = m;
}

static if (!isBasicType!T && !isArray!T && 
!isFunctionPointer!T)

{
IParam opIndex(size_t i)
{
switch (i)
{
// Go through all members:
static foreach (j; 0..m.tupleof.length)
case j:
return param(m.tupleof[j]);
// Then all functions after:
static foreach (j, fn; AllMemberFunctions!T)
case j+m.tupleof.length:
return param();
// And blow up if the index is invalid.
default:
assert(false, "Invalid index!");
}
}
}
else
{
IParam opIndex(size_t i)
{
assert(false, T.stringof ~ " is not an aggregate 
type, and can't be indexed.");

}
}
}

IParam param(T)(T value) {
return new Param!T(value);
}

struct S {
int n;
float f;
string s;
int fn() { return n+2; }
string fun() { return ""; }
string fun(int n) { return ""; }
static void func() {}
}


unittest {
S s;
IParam a = param(s);
}

--
  Simen


Re: Benchmarking sigmoid function between C and D

2018-04-07 Thread Daniel N via Digitalmars-d-learn
On Saturday, 7 April 2018 at 18:53:57 UTC, Arun Chandrasekaran 
wrote:
What am I doing wrong here that makes the D equivalent 2.5 
times slower than it's C equivalent?


Compilers used:

LDC2: LDC - the LLVM D compiler (1.8.0)
GCC: gcc (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609

11:36:39 ~/code/c/test2$ ldc2 sigmoid.d -O5 && ./sigmoid


When benchmarking against C you need to add more switches to 
ldc2, like:

-release -boundscheck=off



Re: Benchmarking sigmoid function between C and D

2018-04-07 Thread Daniel Kozak via Digitalmars-d-learn
or for ldc http://docs.algorithm.dlang.io/latest/mir_math_common.html

On Sat, Apr 7, 2018 at 9:10 PM, Daniel Kozak  wrote:

> can you try it with c math functions?
>
> instead of std.math, try to use core.stdc.math
>
> On Sat, Apr 7, 2018 at 8:53 PM, Arun Chandrasekaran via
> Digitalmars-d-learn  wrote:
>
>> What am I doing wrong here that makes the D equivalent 2.5 times slower
>> than it's C equivalent?
>>
>> Compilers used:
>>
>> LDC2: LDC - the LLVM D compiler (1.8.0)
>> GCC: gcc (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609
>>
>> 11:36:39 ~/code/c/test2$ ldc2 sigmoid.d -O5 && ./sigmoid
>> Max deviation is 0.001664
>> 10^7 iterations using sigmoid1: 308 ms
>> 10^7 iterations using sigmoid2: 30 ms
>> 11:36:55 ~/code/c/test2
>> $ gcc sigmoid.c -o sigmoid-c -O3 -lm 2>/dev/null && ./sigmoid-c
>> Max deviation is 0.001664
>> 10^7 iterations using sigmoid1: 134 ms
>> 10^7 iterations using sigmoid2: 29 ms
>> 11:37:10 ~/code/c/test2
>> $
>>
>> C code, taken from https://stackoverflow.com/ques
>> tions/412019/math-optimization-in-c-sharp#412176:
>>
>> ```
>> #include 
>> #include 
>> #include 
>>
>> #define SCALE 320.0f
>> #define RESOLUTION 2047
>> #define MIN -RESOLUTION / SCALE
>> #define MAX RESOLUTION / SCALE
>>
>> static float sigmoid_lut[RESOLUTION + 1];
>>
>> void init_sigmoid_lut(void) {
>> int i;
>> for (i = 0; i < RESOLUTION + 1; i++) {
>> sigmoid_lut[i] =  (1.0 / (1.0 + exp(-i / SCALE)));
>> }
>> }
>>
>> static float sigmoid1(const float value) {
>> return (1.0f / (1.0f + expf(-value)));
>> }
>>
>> static float sigmoid2(const float value) {
>> if (value <= MIN) return 0.0f;
>> if (value >= MAX) return 1.0f;
>> if (value >= 0) return sigmoid_lut[(int)(value * SCALE + 0.5f)];
>> return 1.0f-sigmoid_lut[(int)(-value * SCALE + 0.5f)];
>> }
>>
>> float test_error() {
>> float x;
>> float emax = 0.0;
>>
>> for (x = -10.0f; x < 10.0f; x+=0.1f) {
>> float v0 = sigmoid1(x);
>> float v1 = sigmoid2(x);
>> float error = fabsf(v1 - v0);
>> if (error > emax) { emax = error; }
>> }
>> return emax;
>> }
>>
>> int sigmoid1_perf() {
>> clock_t t0, t1;
>> int i;
>> float x, y = 0.0f;
>>
>> t0 = clock();
>> for (i = 0; i < 10; i++) {
>> for (x = -5.0f; x <= 5.0f; x+=0.1f) {
>> y = sigmoid1(x);
>> }
>> }
>> t1 = clock();
>> printf("", y); /* To avoid sigmoidX() calls being optimized away */
>> return (t1 - t0) / (CLOCKS_PER_SEC / 1000);
>> }
>>
>> int sigmoid2_perf() {
>> clock_t t0, t1;
>> int i;
>> float x, y = 0.0f;
>> t0 = clock();
>> for (i = 0; i < 10; i++) {
>> for (x = -5.0f; x <= 5.0f; x+=0.1f) {
>> y = sigmoid2(x);
>> }
>> }
>> t1 = clock();
>> printf("", y); /* To avoid sigmoidX() calls being optimized away */
>> return (t1 - t0) / (CLOCKS_PER_SEC / 1000);
>> }
>>
>> int main(void) {
>> init_sigmoid_lut();
>> printf("Max deviation is %0.6f\n", test_error());
>> printf("10^7 iterations using sigmoid1: %d ms\n", sigmoid1_perf());
>> printf("10^7 iterations using sigmoid2: %d ms\n", sigmoid2_perf());
>>
>> return 0;
>> }
>> ```
>>
>> D equivalent:
>>
>> ```
>> module sigmoid;
>>
>> import std.stdio;
>> import std.math;
>> import std.datetime.stopwatch;
>>
>> enum SCALE = 320.0f;
>> enum RESOLUTION = 2047;
>> enum MIN = -RESOLUTION / SCALE;
>> enum MAX = RESOLUTION / SCALE;
>>
>> float[RESOLUTION + 1] sigmoid_lut;
>>
>> void init_sigmoid_lut() {
>> int i;
>> for (i = 0; i < RESOLUTION + 1; i++) {
>> sigmoid_lut[i] =  (1.0 / (1.0 + exp(-i / SCALE)));
>> }
>> }
>>
>> private float sigmoid1(const float value) {
>> return (1.0f / (1.0f + exp(-value)));
>> }
>>
>> private float sigmoid2(const float value) {
>> if (value <= MIN) return 0.0f;
>> if (value >= MAX) return 1.0f;
>> if (value >= 0) return sigmoid_lut[cast(int)(value * SCALE + 0.5f)];
>> return 1.0f-sigmoid_lut[cast(int)(-value * SCALE + 0.5f)];
>> }
>>
>> private float test_error() {
>> float x;
>> float emax = 0.0;
>>
>> for (x = -10.0f; x < 10.0f; x+=0.1f) {
>> float v0 = sigmoid1(x);
>> float v1 = sigmoid2(x);
>> float error = fabs(v1 - v0);
>> if (error > emax) { emax = error; }
>> }
>> return emax;
>> }
>>
>> private auto sigmoid1_perf() {
>> auto sw = StopWatch(AutoStart.yes);
>> int i;
>> float x, y = 0.0f;
>>
>> for (i = 0; i < 10; i++) {
>> for (x = -5.0f; x <= 5.0f; x+=0.1f) {
>> y = sigmoid1(x);
>> }
>> }
>> return sw.peek.total!"msecs";
>> }
>>
>> private auto sigmoid2_perf() {
>> auto sw = StopWatch(AutoStart.yes);
>> int i;
>> float x, y = 0.0f;
>> for (i = 0; i < 10; i++) {
>> for (x = -5.0f; x <= 5.0f; x+=0.1f) {
>> y = sigmoid2(x);
>> }
>>   

Re: Benchmarking sigmoid function between C and D

2018-04-07 Thread Daniel Kozak via Digitalmars-d-learn
can you try it with c math functions?

instead of std.math, try to use core.stdc.math

On Sat, Apr 7, 2018 at 8:53 PM, Arun Chandrasekaran via Digitalmars-d-learn
 wrote:

> What am I doing wrong here that makes the D equivalent 2.5 times slower
> than it's C equivalent?
>
> Compilers used:
>
> LDC2: LDC - the LLVM D compiler (1.8.0)
> GCC: gcc (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609
>
> 11:36:39 ~/code/c/test2$ ldc2 sigmoid.d -O5 && ./sigmoid
> Max deviation is 0.001664
> 10^7 iterations using sigmoid1: 308 ms
> 10^7 iterations using sigmoid2: 30 ms
> 11:36:55 ~/code/c/test2
> $ gcc sigmoid.c -o sigmoid-c -O3 -lm 2>/dev/null && ./sigmoid-c
> Max deviation is 0.001664
> 10^7 iterations using sigmoid1: 134 ms
> 10^7 iterations using sigmoid2: 29 ms
> 11:37:10 ~/code/c/test2
> $
>
> C code, taken from https://stackoverflow.com/ques
> tions/412019/math-optimization-in-c-sharp#412176:
>
> ```
> #include 
> #include 
> #include 
>
> #define SCALE 320.0f
> #define RESOLUTION 2047
> #define MIN -RESOLUTION / SCALE
> #define MAX RESOLUTION / SCALE
>
> static float sigmoid_lut[RESOLUTION + 1];
>
> void init_sigmoid_lut(void) {
> int i;
> for (i = 0; i < RESOLUTION + 1; i++) {
> sigmoid_lut[i] =  (1.0 / (1.0 + exp(-i / SCALE)));
> }
> }
>
> static float sigmoid1(const float value) {
> return (1.0f / (1.0f + expf(-value)));
> }
>
> static float sigmoid2(const float value) {
> if (value <= MIN) return 0.0f;
> if (value >= MAX) return 1.0f;
> if (value >= 0) return sigmoid_lut[(int)(value * SCALE + 0.5f)];
> return 1.0f-sigmoid_lut[(int)(-value * SCALE + 0.5f)];
> }
>
> float test_error() {
> float x;
> float emax = 0.0;
>
> for (x = -10.0f; x < 10.0f; x+=0.1f) {
> float v0 = sigmoid1(x);
> float v1 = sigmoid2(x);
> float error = fabsf(v1 - v0);
> if (error > emax) { emax = error; }
> }
> return emax;
> }
>
> int sigmoid1_perf() {
> clock_t t0, t1;
> int i;
> float x, y = 0.0f;
>
> t0 = clock();
> for (i = 0; i < 10; i++) {
> for (x = -5.0f; x <= 5.0f; x+=0.1f) {
> y = sigmoid1(x);
> }
> }
> t1 = clock();
> printf("", y); /* To avoid sigmoidX() calls being optimized away */
> return (t1 - t0) / (CLOCKS_PER_SEC / 1000);
> }
>
> int sigmoid2_perf() {
> clock_t t0, t1;
> int i;
> float x, y = 0.0f;
> t0 = clock();
> for (i = 0; i < 10; i++) {
> for (x = -5.0f; x <= 5.0f; x+=0.1f) {
> y = sigmoid2(x);
> }
> }
> t1 = clock();
> printf("", y); /* To avoid sigmoidX() calls being optimized away */
> return (t1 - t0) / (CLOCKS_PER_SEC / 1000);
> }
>
> int main(void) {
> init_sigmoid_lut();
> printf("Max deviation is %0.6f\n", test_error());
> printf("10^7 iterations using sigmoid1: %d ms\n", sigmoid1_perf());
> printf("10^7 iterations using sigmoid2: %d ms\n", sigmoid2_perf());
>
> return 0;
> }
> ```
>
> D equivalent:
>
> ```
> module sigmoid;
>
> import std.stdio;
> import std.math;
> import std.datetime.stopwatch;
>
> enum SCALE = 320.0f;
> enum RESOLUTION = 2047;
> enum MIN = -RESOLUTION / SCALE;
> enum MAX = RESOLUTION / SCALE;
>
> float[RESOLUTION + 1] sigmoid_lut;
>
> void init_sigmoid_lut() {
> int i;
> for (i = 0; i < RESOLUTION + 1; i++) {
> sigmoid_lut[i] =  (1.0 / (1.0 + exp(-i / SCALE)));
> }
> }
>
> private float sigmoid1(const float value) {
> return (1.0f / (1.0f + exp(-value)));
> }
>
> private float sigmoid2(const float value) {
> if (value <= MIN) return 0.0f;
> if (value >= MAX) return 1.0f;
> if (value >= 0) return sigmoid_lut[cast(int)(value * SCALE + 0.5f)];
> return 1.0f-sigmoid_lut[cast(int)(-value * SCALE + 0.5f)];
> }
>
> private float test_error() {
> float x;
> float emax = 0.0;
>
> for (x = -10.0f; x < 10.0f; x+=0.1f) {
> float v0 = sigmoid1(x);
> float v1 = sigmoid2(x);
> float error = fabs(v1 - v0);
> if (error > emax) { emax = error; }
> }
> return emax;
> }
>
> private auto sigmoid1_perf() {
> auto sw = StopWatch(AutoStart.yes);
> int i;
> float x, y = 0.0f;
>
> for (i = 0; i < 10; i++) {
> for (x = -5.0f; x <= 5.0f; x+=0.1f) {
> y = sigmoid1(x);
> }
> }
> return sw.peek.total!"msecs";
> }
>
> private auto sigmoid2_perf() {
> auto sw = StopWatch(AutoStart.yes);
> int i;
> float x, y = 0.0f;
> for (i = 0; i < 10; i++) {
> for (x = -5.0f; x <= 5.0f; x+=0.1f) {
> y = sigmoid2(x);
> }
> }
> return sw.peek.total!"msecs";
> }
>
> int main() {
> init_sigmoid_lut();
> writefln("Max deviation is %0.6f", test_error());
> writefln("10^7 iterations using sigmoid1: %s ms", sigmoid1_perf());
> writefln("10^7 iterations using sigmoid2: %s ms", sigmoid2_perf());
>
> return 0;
> }
> ```
>


Benchmarking sigmoid function between C and D

2018-04-07 Thread Arun Chandrasekaran via Digitalmars-d-learn
What am I doing wrong here that makes the D equivalent 2.5 times 
slower than it's C equivalent?


Compilers used:

LDC2: LDC - the LLVM D compiler (1.8.0)
GCC: gcc (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609

11:36:39 ~/code/c/test2$ ldc2 sigmoid.d -O5 && ./sigmoid
Max deviation is 0.001664
10^7 iterations using sigmoid1: 308 ms
10^7 iterations using sigmoid2: 30 ms
11:36:55 ~/code/c/test2
$ gcc sigmoid.c -o sigmoid-c -O3 -lm 2>/dev/null && ./sigmoid-c
Max deviation is 0.001664
10^7 iterations using sigmoid1: 134 ms
10^7 iterations using sigmoid2: 29 ms
11:37:10 ~/code/c/test2
$

C code, taken from 
https://stackoverflow.com/questions/412019/math-optimization-in-c-sharp#412176:


```
#include 
#include 
#include 

#define SCALE 320.0f
#define RESOLUTION 2047
#define MIN -RESOLUTION / SCALE
#define MAX RESOLUTION / SCALE

static float sigmoid_lut[RESOLUTION + 1];

void init_sigmoid_lut(void) {
int i;
for (i = 0; i < RESOLUTION + 1; i++) {
sigmoid_lut[i] =  (1.0 / (1.0 + exp(-i / SCALE)));
}
}

static float sigmoid1(const float value) {
return (1.0f / (1.0f + expf(-value)));
}

static float sigmoid2(const float value) {
if (value <= MIN) return 0.0f;
if (value >= MAX) return 1.0f;
if (value >= 0) return sigmoid_lut[(int)(value * SCALE + 
0.5f)];

return 1.0f-sigmoid_lut[(int)(-value * SCALE + 0.5f)];
}

float test_error() {
float x;
float emax = 0.0;

for (x = -10.0f; x < 10.0f; x+=0.1f) {
float v0 = sigmoid1(x);
float v1 = sigmoid2(x);
float error = fabsf(v1 - v0);
if (error > emax) { emax = error; }
}
return emax;
}

int sigmoid1_perf() {
clock_t t0, t1;
int i;
float x, y = 0.0f;

t0 = clock();
for (i = 0; i < 10; i++) {
for (x = -5.0f; x <= 5.0f; x+=0.1f) {
y = sigmoid1(x);
}
}
t1 = clock();
printf("", y); /* To avoid sigmoidX() calls being optimized 
away */

return (t1 - t0) / (CLOCKS_PER_SEC / 1000);
}

int sigmoid2_perf() {
clock_t t0, t1;
int i;
float x, y = 0.0f;
t0 = clock();
for (i = 0; i < 10; i++) {
for (x = -5.0f; x <= 5.0f; x+=0.1f) {
y = sigmoid2(x);
}
}
t1 = clock();
printf("", y); /* To avoid sigmoidX() calls being optimized 
away */

return (t1 - t0) / (CLOCKS_PER_SEC / 1000);
}

int main(void) {
init_sigmoid_lut();
printf("Max deviation is %0.6f\n", test_error());
printf("10^7 iterations using sigmoid1: %d ms\n", 
sigmoid1_perf());
printf("10^7 iterations using sigmoid2: %d ms\n", 
sigmoid2_perf());


return 0;
}
```

D equivalent:

```
module sigmoid;

import std.stdio;
import std.math;
import std.datetime.stopwatch;

enum SCALE = 320.0f;
enum RESOLUTION = 2047;
enum MIN = -RESOLUTION / SCALE;
enum MAX = RESOLUTION / SCALE;

float[RESOLUTION + 1] sigmoid_lut;

void init_sigmoid_lut() {
int i;
for (i = 0; i < RESOLUTION + 1; i++) {
sigmoid_lut[i] =  (1.0 / (1.0 + exp(-i / SCALE)));
}
}

private float sigmoid1(const float value) {
return (1.0f / (1.0f + exp(-value)));
}

private float sigmoid2(const float value) {
if (value <= MIN) return 0.0f;
if (value >= MAX) return 1.0f;
if (value >= 0) return sigmoid_lut[cast(int)(value * SCALE + 
0.5f)];

return 1.0f-sigmoid_lut[cast(int)(-value * SCALE + 0.5f)];
}

private float test_error() {
float x;
float emax = 0.0;

for (x = -10.0f; x < 10.0f; x+=0.1f) {
float v0 = sigmoid1(x);
float v1 = sigmoid2(x);
float error = fabs(v1 - v0);
if (error > emax) { emax = error; }
}
return emax;
}

private auto sigmoid1_perf() {
auto sw = StopWatch(AutoStart.yes);
int i;
float x, y = 0.0f;

for (i = 0; i < 10; i++) {
for (x = -5.0f; x <= 5.0f; x+=0.1f) {
y = sigmoid1(x);
}
}
return sw.peek.total!"msecs";
}

private auto sigmoid2_perf() {
auto sw = StopWatch(AutoStart.yes);
int i;
float x, y = 0.0f;
for (i = 0; i < 10; i++) {
for (x = -5.0f; x <= 5.0f; x+=0.1f) {
y = sigmoid2(x);
}
}
return sw.peek.total!"msecs";
}

int main() {
init_sigmoid_lut();
writefln("Max deviation is %0.6f", test_error());
writefln("10^7 iterations using sigmoid1: %s ms", 
sigmoid1_perf());
writefln("10^7 iterations using sigmoid2: %s ms", 
sigmoid2_perf());


return 0;
}
```


Re: that is bug?

2018-04-07 Thread Ali Çehreli via Digitalmars-d

On 04/07/2018 10:53 AM, Ali wrote:
> On Saturday, 7 April 2018 at 15:26:56 UTC, Ali Çehreli wrote:
>> On 04/07/2018 02:07 AM, sdvcn wrote:
>>>  string stt = "none";
>>>  true?writeln("AA"):writeln("BB");   ///Out:AA
>>>  true?stt="AA":stt="BB";-///Out:BB
>>>  writeln(stt);
>>
>> It is a bug because the behavior does not match the spec:
>>
>>   https://issues.dlang.org/show_bug.cgi?id=18743
>>
>> Ali
>
> Hi Ali C
>
> I think it also a bug because the ternary seem to be returning the
> second part

Maybe... but the following is not a good test for that because the 
return value of the assignment operator would always be stt regardless 
of which expression is evaluated.


>
> try
>
>  string stt = "none";
>  string b = "";
>  true?writeln("AA"):writeln("BB");   ///Out:AA
>  b = (true ? stt="AA":stt="BB");///Out:BB
>  writeln(stt);
>  writeln(b); ///Out:BB

I tried something else and noticed that it doesn't actually evaluate the 
third expression because b is never changed:


import std.stdio;

void main() {
int a;
int b;
int * c = &(true ? a = 1 : b = 2);
writefln("a:%s %s", a, );
writefln("b:%s %s", b, );
writefln("c:  %s", c);
}

Output:

a:2 7FFDBBF57DB0  <-- Got the value of the third expression (BAD)
b:0 7FFDBBF57DB4  <-- Not changed (good)
c:  7FFDBBF57DB0  <-- Address of a (good)

So, the expression correctly decides to affect and returns 'a' but uses 
the wrong value to assign.


Ali



Beta 2.079.1

2018-04-07 Thread Martin Nowak via Digitalmars-d-announce
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA512

First beta for the 2.079.1 patch release.

Comes with a handful of fixes.

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

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

- -Martin


-BEGIN PGP SIGNATURE-

iQIzBAEBCgAdFiEEpzRNrTw0HqEtE8TmsnOBFhK7GTkFAlrJEEoACgkQsnOBFhK7
GTk4xQ/+Ma++WcDt2dCJlmoPYE7gwBVBe2gvrJStx9/7Ef0xtmHyVeo3sbKSXIAG
lhdW7cq+ZR6qvpxmMRu3FIRDFLXBtoFHJLAGOC8dwLv8r1naHheZMcEgRS1ryGnp
ae3T+6Qg7TiALTAC4iy2BcBsUw1DR7JFdj+SNx+5mB9OtKS92hWOf1WtudOayQoV
3NEbGp/Wj0NCVhbkgAn9gDonpMRzV/hYXIJFFm9mHrLIDUL2f3ekdX3mhR4dcKQq
cg75FAL2lEe9wsMlkJVYv+wDMAZXe331wLx68xSr/O2PbrohHLPiHA0t79Ith3kP
2eFXjmQ6VoUSXQgiwDrBjadm6KgXUYYjBKKxWWZIdyua+O+hd9kx6BEC/PypZBCq
DHeZ1loNrI1f+d9Dnif0DFB5mXFBtaJ5XlWEdRf7ss+Xo2VYT/ak8LpKnqkob2Tv
FHctFy4KWIR0Z+Plql990t/RtaTKXDKYW+fW0fw4oKGbG+PBvEzvMxj2wREAtqX5
laCd8hE/g8M5qlv6oWOux7dTzDrkOmPYnepeSkK2aelWO0MV2FAH0hEPRf37QXwq
ir9AA0cxiS5Vv3tM0KBi8XA9u6BlvoOzRXIZpAHAINRUYRjiCvB76bAQhH4O4lh4
UQ9oqa0XWDJ7xs7FuaRldTT7TFAEWn/UtTF5kOOc18G+zKnlQOo=
=7ay/
-END PGP SIGNATURE-


Re: std.datetime.systime: days Deprecation message

2018-04-07 Thread Alex via Digitalmars-d-learn

On Saturday, 7 April 2018 at 17:25:07 UTC, Vino wrote:

Hi All,

  Request your help on the below Deprecation message.

import std.datetime.systime: Clock, days, SysTime;

void main (int AgeSize) {
int AgeSize = 1
auto ct2 = Clock.currTime(), st2 = ct2 + days(-AgeSize);
}
test.d(30): Deprecation: Symbol core.time.days is not visible 
from module test.d because it is privately imported in module 
systime



From,
Vino.B


As far as I understand it, days are located in core.time.

import core.time : days;



Re: that is bug?

2018-04-07 Thread Ali via Digitalmars-d

On Saturday, 7 April 2018 at 15:26:56 UTC, Ali Çehreli wrote:

On 04/07/2018 02:07 AM, sdvcn wrote:

 string stt = "none";
 true?writeln("AA"):writeln("BB");   ///Out:AA
     true?stt="AA":stt="BB";    -///Out:BB
 writeln(stt);


It is a bug because the behavior does not match the spec:

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

Ali


Hi Ali C

I think it also a bug because the ternary seem to be returning 
the second part


try

string stt = "none";
string b = "";
true?writeln("AA"):writeln("BB");   ///Out:AA
b = (true ? stt="AA":stt="BB");///Out:BB
writeln(stt);
writeln(b); ///Out:BB


std.datetime.systime: days Deprecation message

2018-04-07 Thread Vino via Digitalmars-d-learn

Hi All,

  Request your help on the below Deprecation message.

import std.datetime.systime: Clock, days, SysTime;

void main (int AgeSize) {
int AgeSize = 1
auto ct2 = Clock.currTime(), st2 = ct2 + days(-AgeSize);
}
test.d(30): Deprecation: Symbol core.time.days is not visible 
from module test.d because it is privately imported in module 
systime



From,
Vino.B


Re: that is bug?

2018-04-07 Thread Patrick Schluter via Digitalmars-d

On Saturday, 7 April 2018 at 14:28:05 UTC, kdevel wrote:
On Saturday, 7 April 2018 at 09:56:43 UTC, Jonathan M Davis 
wrote:

 true?stt="AA":stt="BB";-///Out:BB


[...]


Assignment takes precendence over the ternary operator.


That's not true. Not in D and not in C/C++


The odd man out is C++ [1], assignment has higher precedence 
because of right to left evaluation. Do not mix it with C please. 
All other C derived languages have indeed higher precedence for 
ternary than assignment: C [2], java [3], C# [4] and D [5].


[1]: http://en.cppreference.com/w/cpp/language/operator_precedence
[2]: http://en.cppreference.com/w/c/language/operator_precedence
[3]: https://introcs.cs.princeton.edu/java/11precedence/
[4]: 
https://www.tutorialspoint.com/csharp/csharp_operators_precedence.htm

[5]: https://wiki.dlang.org/Operator_precedence


https://wiki.dlang.org/Operator_precedence
http://en.cppreference.com/w/c/language/operator_precedence#cite_note-2

So, no, I don't think that it is. Putting parens around the 
assignment expressions makes it print AA.


It should not matter if there are parens around the assignment.

As it stands, it evaluates both assignment expressions before 
evaluating the ternary operator.


That is not true in C/C++, let me quote from a C standard 
(draft), § 6.1.5 conditional operator:


Stop mixing C with C++ they are really 2 very different beasts 
(one is a programming language, the other is Cthulu :-)





Re: HTTP-methods and encoding

2018-04-07 Thread Seb via Digitalmars-d-learn

On Saturday, 7 April 2018 at 13:02:39 UTC, Vindex wrote:
There is an error on some sites when using HTTP-methods 
(std.net.curl.get, std.net.curl.post):
std.encoding.EncodingException@std/encoding.d(2505): 
Unrecognized Encoding: utf8


Is there a beautiful way around it?
For the GET-method I use the download() and readText(). But for 
the POST-method I can not come up with an alternative solution.


That's weird. std.net.curl should be able to handle UTF-8.
What content are you trying to download/post?
Maybe you can open a bug report for it?

In any case, you might want to checkout requests:

https://github.com/ikod/dlang-requests

It's by far more convenient to use than std.net.curl



Re: that is bug?

2018-04-07 Thread Ali Çehreli via Digitalmars-d

On 04/07/2018 02:07 AM, sdvcn wrote:

 string stt = "none";
 true?writeln("AA"):writeln("BB");   ///Out:AA
     true?stt="AA":stt="BB";    -///Out:BB
 writeln(stt);


It is a bug because the behavior does not match the spec:

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

Ali


[Issue 18743] New: Conditional expression (ternary operator) can evaluate the third expression even "If it is true"

2018-04-07 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18743

  Issue ID: 18743
   Summary: Conditional expression (ternary operator) can evaluate
the third expression even "If it is true"
   Product: D
   Version: D2
  Hardware: x86_64
OS: Linux
Status: NEW
  Severity: normal
  Priority: P1
 Component: dmd
  Assignee: nob...@puremagic.com
  Reporter: acehr...@yahoo.com

string stt = "none";
true?writeln("AA"):writeln("BB");   ///Out:AA
true?stt="AA":stt="BB";-///Out:BB
writeln(stt); 

Copied from the forum discussion:

  https://forum.dlang.org/post/rjcjecmgrpeqbdrht...@forum.dlang.org

The behavior does not match the spec:

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

Ali

--


[Issue 18742] New: std.regex: Using CodePointSet in AAs breaks if reference count changes

2018-04-07 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18742

  Issue ID: 18742
   Summary: std.regex: Using CodePointSet in AAs breaks if
reference count changes
   Product: D
   Version: D2
  Hardware: All
OS: All
Status: NEW
  Keywords: bootcamp
  Severity: minor
  Priority: P1
 Component: phobos
  Assignee: nob...@puremagic.com
  Reporter: johannesp...@gmail.com

When storing a CodePointSet in an AA, the reference count member is included
when hashing, so two identical CodePointSets only differing in the reference
count are not considered as the same AA key. std.regex does actually put
CodePointSets into AAs, so this seems very fragile. As a solution, CodePointSet
should properly implement the toHash function.

Test case:
--
import std.uni, std.stdio;

void main()
{
int[CodepointSet] aa;
auto set = unicode.Nd;
aa[set] = 42;
writeln(aa[set]);
}
--
This is expected to print 42, but currently throws a RangeError instead.

--


Re: that is bug?

2018-04-07 Thread kdevel via Digitalmars-d

On Saturday, 7 April 2018 at 14:43:53 UTC, Jonathan M Davis wrote:
On Saturday, April 07, 2018 14:29:15 kdevel via Digitalmars-d 
wrote:

On Saturday, 7 April 2018 at 10:25:19 UTC, bauss wrote:
> On Saturday, 7 April 2018 at 09:07:48 UTC, sdvcn wrote:
>> true?stt="AA":stt="BB";-///Out:BB
>
> It's an UB.
>
> Not a bug.

Why UB? stt is only modified once.


It's modified twice.


So we have diffrent behavior of D wrt to C.

[...] which would imply (though not guarantee) that the D 
behavior is a bug.


After rereading

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

carefully I found that Unlike § 6.1.5 of the C standard the 
"only" is missing in the D docs.




[Issue 18026] Stack overflow in ddmd/dtemplate.d:6241, TemplateInstance::needsCodegen()

2018-04-07 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18026

--- Comment #5 from JR  ---
(In reply to Seb from comment #4)
> JR: Cool! I can reproduce it on my machine too :)

[...]

> I will look at reducing this even further tomorrow.

Awesome, thanks!

--


Re: How to destruct class instances allocated by a Region-allocator over a single GC block

2018-04-07 Thread Per Nordlöw via Digitalmars-d-learn

On Saturday, 7 April 2018 at 07:50:37 UTC, Eduard Staniloiu wrote:

On Friday, 6 April 2018 at 21:49:37 UTC, Per Nordlöw wrote:
On Tuesday, 3 April 2018 at 09:14:28 UTC, Eduard Staniloiu 
wrote:

So, say `reg` is your allocator, your workflow would be

auto obj = reg.make!Type(args);
/* do stuff */
reg.dispose(obj); // If Type has a __dtor, it will call 
obj.__dtor

  // and then reg.deallocate(obj)


If I do sucessive calls to reg.make!X where X are different 
kinds of classes of different sizes how does reg.dispose(obj) 
figure out at which address(es) (where emplace filled in the 
data) the objects reside?


It can't figure out. With custom allocators you have to 
manually do
the memory management, so the responsibility of when and which 
object needs

to be destroyed falls on the user of the custom allocator.


IMHO, such a complexity should be wrapped in a typed allocation 
layer. Have Andrei spoken anything about `TypedAllocator`(s) to 
wrap this complexity?


Re: that is bug?

2018-04-07 Thread Jonathan M Davis via Digitalmars-d
On Saturday, April 07, 2018 14:28:05 kdevel via Digitalmars-d wrote:
> On Saturday, 7 April 2018 at 09:56:43 UTC, Jonathan M Davis wrote:
> >>  true?stt="AA":stt="BB";-///Out:BB
>
> [...]
>
> > Assignment takes precendence over the ternary operator.
>
> That's not true. Not in D and not in C/C++
> https://wiki.dlang.org/Operator_precedence
> http://en.cppreference.com/w/c/language/operator_precedence#cite_note-2
>
> > So, no, I don't think that it is. Putting parens around the
> > assignment expressions makes it print AA.
>
> It should not matter if there are parens around the assignment.
>
> > As it stands, it evaluates both assignment expressions before
> > evaluating the ternary operator.
>
> That is not true in C/C++, let me quote from a C standard
> (draft), § 6.1.5 conditional operator:
>
> [this is about  ?  : ]
>
> "Semantics
>
> The first operand is evaluated; there is a sequence point between
> its evaluation and the evaluation of the second or third operand
> (whichever is evaluated). The second operand is evaluated only if
> the first compares unequal to 0; the third operand is evaluated
> only if the first compares equal to 0; the result is the value of
> the second or third operand (whichever is evaluated), converted
> to the type described below.110)"
>
> According to
>
> https://dlang.org/spec/expression.html#conditional_expressions
>
> the same shall be valid for D. Hence when
>
> true ? s = A : s = B;
>
> or
>
> true ? (s = A) : (s = B);
>
> does not yield A for s it's a bug.

You're right. It's what I get for responding too early in the morning.

- Jonathan M Davis




Re: that is bug?

2018-04-07 Thread Jonathan M Davis via Digitalmars-d
On Saturday, April 07, 2018 14:29:15 kdevel via Digitalmars-d wrote:
> On Saturday, 7 April 2018 at 10:25:19 UTC, bauss wrote:
> > On Saturday, 7 April 2018 at 09:07:48 UTC, sdvcn wrote:
> >> true?stt="AA":stt="BB";-///Out:BB
> >
> > It's an UB.
> >
> > Not a bug.
>
> Why UB? stt is only modified once.

It's modified twice. This

import std.stdio;

struct S
{
S opAssign(string str)
{
writeln(str);
return S.init;
}
}

void main()
{
S stt;
true ? stt = "AA" : stt = "BB";
}

prints

AA
BB

whereas this

import std.stdio;

struct S
{
S opAssign(string str)
{
writeln(str);
return S.init;
}
}

void main()
{
S stt;
true ? (stt = "AA") : (stt = "BB");
}

prints

AA

However, similar code in C++

#include 

class C
{
public:
C& operator=(int i)
{
printf("%d\n", i);
return *this;
}
};

int main()
{
C c;
true ? c = 42 : c = 29;
return 0;
}

prints the first value only, which would imply (though not guarantee) that
the D behavior is a bug.

- Jonathan M Davis



Re: Function template argument deduction

2018-04-07 Thread Paul Backus via Digitalmars-d-learn

On Saturday, 7 April 2018 at 14:02:55 UTC, Paul Backus wrote:
Interesting. Looks like this is an issue with aliases, because 
I get the error with this code too:


--- test.d
import std.typecons: Tuple, tuple;

alias Pair(T) = Tuple!(T, T);

void foo(T)(Pair!T p)
{
return;
}

unittest {
Pair!int x = tuple(1, 2);
foo(x);
}
---


Looks like this is the same problem described in issue 1807:

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

I'm not sure what D was like when Martin Nowak made the most 
recent comment on that issue, in 2012, but alias templates do 
have their own dedicated language construct now, so maybe this is 
worth revisiting.


Re: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/, [your code here]

2018-04-07 Thread kdevel via Digitalmars-d

On Friday, 6 April 2018 at 14:03:18 UTC, Abdulhaq wrote:

On Friday, 6 April 2018 at 13:10:07 UTC, jason wrote:

what is this?


It's a perl program that converts D code into APL


+1


Re: that is bug?

2018-04-07 Thread kdevel via Digitalmars-d

On Saturday, 7 April 2018 at 10:25:19 UTC, bauss wrote:

On Saturday, 7 April 2018 at 09:07:48 UTC, sdvcn wrote:


true?stt="AA":stt="BB";-///Out:BB


It's an UB.

Not a bug.


Why UB? stt is only modified once.


Re: that is bug?

2018-04-07 Thread kdevel via Digitalmars-d

On Saturday, 7 April 2018 at 09:56:43 UTC, Jonathan M Davis wrote:

 true?stt="AA":stt="BB";-///Out:BB


[...]


Assignment takes precendence over the ternary operator.


That's not true. Not in D and not in C/C++
https://wiki.dlang.org/Operator_precedence
http://en.cppreference.com/w/c/language/operator_precedence#cite_note-2

So, no, I don't think that it is. Putting parens around the 
assignment expressions makes it print AA.


It should not matter if there are parens around the assignment.

As it stands, it evaluates both assignment expressions before 
evaluating the ternary operator.


That is not true in C/C++, let me quote from a C standard 
(draft), § 6.1.5 conditional operator:


[this is about  ?  : ]

"Semantics

The first operand is evaluated; there is a sequence point between 
its evaluation and the evaluation of the second or third operand 
(whichever is evaluated). The second operand is evaluated only if 
the first compares unequal to 0; the third operand is evaluated 
only if the first compares equal to 0; the result is the value of 
the second or third operand (whichever is evaluated), converted 
to the type described below.110)"


According to

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

the same shall be valid for D. Hence when

   true ? s = A : s = B;

or

   true ? (s = A) : (s = B);

does not yield A for s it's a bug.


[Issue 18026] Stack overflow in ddmd/dtemplate.d:6241, TemplateInstance::needsCodegen()

2018-04-07 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18026

--- Comment #4 from Seb  ---
JR: Cool! I can reproduce it on my machine too :)

For reference, here's what's necessary for reproducing this without dub:

/home/seb/dlang/dmd/generated/linux/release/64/dmd -c -offoo.o -w -Isource/
source/kameloso/common.d source/kameloso/irc.d source/kameloso/ircdefs.d
source/kameloso/main.d source/kameloso/plugins/notes.d -vcolumns | head -n20

Program received signal SIGSEGV, Segmentation fault.
0x557f4187 in TemplateInstance::needsCodegen() ()
#0  0x557f4187 in TemplateInstance::needsCodegen() ()
#1  0x557f42c6 in TemplateInstance::needsCodegen() ()
#2  0x557f42c6 in TemplateInstance::needsCodegen() ()
#3  0x557f42c6 in TemplateInstance::needsCodegen() ()
#4  0x557f42c6 in TemplateInstance::needsCodegen() ()
#5  0x557f42c6 in TemplateInstance::needsCodegen() ()
#6  0x557f42c6 in TemplateInstance::needsCodegen() ()
#7  0x557f42c6 in TemplateInstance::needsCodegen() ()
#8  0x557f42c6 in TemplateInstance::needsCodegen() ()


I will look at reducing this even further tomorrow.

--


Re: Dockerfile with cross-compiler targeting Windows x64

2018-04-07 Thread Seb via Digitalmars-d-announce

On Saturday, 7 April 2018 at 12:24:54 UTC, kinke wrote:

Any MS libs that can be bundled "legally"?


That's the problem. If there were, they'd be bundled with the 
LDC Windows packages, so that LDC on Windows wouldn't require a 
Visual C++ installation anymore and just work out of the box.
To avoid confusion: we're talking about the static and import 
.lib files of the Visual C++ runtime & Windows SDK, not about 
the redistributable DLLs.


The libs on DropBox are from Visual Studio 2015 Update 3, while 
the LDC 1.8 druntime/Phobos libs have been compiled with latest 
VS 2017, so this divergence could become problematic at some 
point.


Hmm how hard would it be to use the MinGW libraries like DMD is 
doing as a fallback since 2.079?


https://dlang.org/changelog/2.079.0.html#lld_mingw

Rainer's excellent work on this is mostly found in 
dlang/installer:


https://github.com/dlang/installer/blob/build-mingw-libs/windows/build_mingw.bat
https://github.com/dlang/installer/blob/build-lld/windows/build_lld.bat
https://github.com/dlang/installer/pull/281
https://github.com/dlang/dmd/pull/7500

(mingw and lld are separate branches, s.t. they aren't built on 
every AppVeyor run)


Re: dustmite watch shell script (.test vs .lookahead.*)

2018-04-07 Thread Anonymouse via Digitalmars-d-learn

On Friday, 6 April 2018 at 15:42:04 UTC, Vladimir Panteleev wrote:

On Friday, 6 April 2018 at 15:35:59 UTC, Anonymouse wrote:
The dustmite wiki[0] lists the following example script for 
use to monitor the reduction progress:


Here's a more complete version that also works with -j:

https://gist.github.com/CyberShadow/2e8f01895c248111c171e982313bb008


Thanks!


Re: Function template argument deduction

2018-04-07 Thread Paul Backus via Digitalmars-d-learn

On Saturday, 7 April 2018 at 06:26:24 UTC, Uknown wrote:

What I did notice though is that when
`string list2string(T)(List!T list)` was changed to
`string list2string(T)(VariantN!(16LU, Nil, Tuple!(T, "head", 
This*, "tail")) list)`

The compiler correctly deduce `T` to be `int`


Interesting. Looks like this is an issue with aliases, because I 
get the error with this code too:


--- test.d
import std.typecons: Tuple, tuple;

alias Pair(T) = Tuple!(T, T);

void foo(T)(Pair!T p)
{
return;
}

unittest {
Pair!int x = tuple(1, 2);
foo(x);
}
---


[Issue 18026] Stack overflow in ddmd/dtemplate.d:6241, TemplateInstance::needsCodegen()

2018-04-07 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18026

--- Comment #3 from JR  ---
I reduced it to 58 lines using dustmite, which is incidentally amazing.

Under 2.079.0, it compiles in -debug mode but doesn't outside of it. 2.078.3
can however compile it in both. The code is nonsense, but it appears to trigger
the behaviour.

> $ git clone https://github.com/zorael/kameloso -b 2.079-overflow
> $ cd kameloso
> $ dub build -b debug  # works
> 
> $ dub build -b plain
> /usr/bin/dmd failed with exit code -11.
> 
> $ gdb --batch -ex "run" --args dmd source/kameloso/*.d 
> source/kameloso/plugins/*.d
> Program received signal SIGSEGV, Segmentation fault.
> 0x55825982 in TemplateInstance::needsCodegen() ()

I tested it on Travis and CircleCI. Both run 2.079.0, and Travis could not
reproduce the segfault. CircleCI however could! Please see
https://circleci.com/gh/zorael/kameloso/151.

Again, this seems to only affect 2.079.0, and only on *some* distributions.
Unless your linux installation sees the behaviour, I imagine the only way to
observe it is to download a Manjaro .iso and run it in a virtual machine.
Apologies.

I wish I could produce something more tangible but this is how ephemeral the
issue is.

--


Communal Benevolence Required

2018-04-07 Thread Mike Parker via Digitalmars-d-announce
If you've been considering helping out the D Language Foundation 
with a donation, right now is a beneficial time to do it. With 
DConf just around the corner, every dime counts!


Blog
https://dlang.org/blog/2018/04/07/communal-benevolence-required/

Reddit
https://www.reddit.com/r/d_language/comments/8ai5lw/communal_benevolence_required/


Store struct tuple of alias and access members through it?

2018-04-07 Thread Timoses via Digitalmars-d-learn

(Please read at the very bottom what I'd like to achieve)

Is it possible to return the member of a struct by its .tupleof 
index?


I know that it would work on a struct value, but I'd like it to 
work on the type's tupleof:


```
struct S { int i;}
S s;
// below leads to: Error: need this for s1 of type uint
// writeln(/*somehow access s via the S tupleof? */ S.tupleof[0]);
// vs
writeln(s.tupleof[0]);
```

See below example to make the intention a bit clearer:

https://run.dlang.io/gist/6fdb01ddd78b14f8b9a94ac951580cb8
```
struct S
{
uint s1;
ushort s2;
}

interface IParam
{}

template Param(T)
{
static if (isBasicType!T)
alias members = AliasSeq!();
else
alias members = AliasSeq!(T.tupleof);

class Param : IParam
{
T m;
this(T m)
{
this.m = m;
}

IParam opIndex(size_t i)
{
// Something like this possible?
// return this.m.members[i];   // < 
how???


// This works but feels needless.
static foreach (j, t; members)
if (i == j)
{
	return new 
Param!(typeof(members[j]))(__traits(getMember, this.m, 
members[j].stringof));  // <- 
members[j].stringof feels ugly just to get the member that should 
be stored in 'members' already...

}
return null;
}
}
}
```

The reason why I don't want `m.tupleof[i]` is because later I'd 
like to consider bitfields within the struct. This means I'd have 
to also consider the member functions of the struct and 
potentially return them.


E.g.

```
struct S
{
int s1;
int s2() { return 3; }
}
```

and then I'd like to have
alias members = (s1, s2) // pseudo code..

so I could return
S s;
s.members[1]; // would evaluate the function s2 and return the 
value


--

In the end I would like to accomplish the following:
Provide access to contained bitfields and members of a struct in 
the order they

appear in the struct via an index.

I hope I made a somewhat decent job in explaining what I'm trying 
to accomplish.


Please let me know if anything is unclear.


HTTP-methods and encoding

2018-04-07 Thread Vindex via Digitalmars-d-learn
There is an error on some sites when using HTTP-methods 
(std.net.curl.get, std.net.curl.post):
std.encoding.EncodingException@std/encoding.d(2505): Unrecognized 
Encoding: utf8


Is there a beautiful way around it?
For the GET-method I use the download() and readText(). But for 
the POST-method I can not come up with an alternative solution.


Re: code-d 0.17.0 + serve-d 0.1.2

2018-04-07 Thread WebFreak001 via Digitalmars-d-announce

On Friday, 6 April 2018 at 19:12:32 UTC, Wulfklaue wrote:
Nice job WebFreak001 on the new changes. For the first time in 
years the code-d plugin works out of the box on Windows without 
any issues.


A small tip: associate the .d file extension in the Visual 
Studio Code marketplace with Code-d. Currently Code-D does not 
show up when VSC suggests plugins for the .d file extension.


uh I did do that though? Check the provides tab in the extension, 
it shows D


Re: Dockerfile with cross-compiler targeting Windows x64

2018-04-07 Thread kinke via Digitalmars-d-announce

On Friday, 6 April 2018 at 04:08:41 UTC, Seb wrote:
On Thursday, 5 April 2018 at 11:46:42 UTC, Jacob Carlborg 
wrote:
I've created a Dockerfile [1] containing LDC, configured for 
cross-compiling targeting Windows x64.


Thanks for doing this.

BTW I just tested this and it works really nicely (I even 
managed to compile the whole DScanner for Windows (!) and it 
runs as expected in a quick test in a virtual machine). Thanks!


Thanks for the confirmation.


Any MS libs that can be bundled "legally"?


That's the problem. If there were, they'd be bundled with the LDC 
Windows packages, so that LDC on Windows wouldn't require a 
Visual C++ installation anymore and just work out of the box.
To avoid confusion: we're talking about the static and import 
.lib files of the Visual C++ runtime & Windows SDK, not about the 
redistributable DLLs.


The libs on DropBox are from Visual Studio 2015 Update 3, while 
the LDC 1.8 druntime/Phobos libs have been compiled with latest 
VS 2017, so this divergence could become problematic at some 
point.


Re: that is bug?

2018-04-07 Thread Seb via Digitalmars-d

On Saturday, 7 April 2018 at 11:19:44 UTC, meppl wrote:

On Saturday, 7 April 2018 at 10:25:19 UTC, bauss wrote:

On Saturday, 7 April 2018 at 09:07:48 UTC, sdvcn wrote:


true?stt="AA":stt="BB";-///Out:BB


It's an UB.

Not a bug.



I want `condition ? expr1 : expr2` to behave like:

-
auto qc( alias condition, string expr1, string expr2)() {
if( condition) {
return mixin( expr1);
} else {
return mixin( expr2);
}
}
-


You can do so today with lazy:

---
import std.stdio;

auto qc(E1, E2)(bool condition, lazy E1 expr1, lazy E2 expr2)
{
if (condition)
{
return expr1;
}
else
{
return expr2;
}
}

void main()
{
qc(true, "A".writeln, "B".writeln);
string s;
qc(true, s = "A", s = "B");
s.writeln;
}
---

https://run.dlang.io/is/ymZBht
https://dlang.org/articles/lazy-evaluation.html


Re: that is bug?

2018-04-07 Thread meppl via Digitalmars-d

On Saturday, 7 April 2018 at 10:25:19 UTC, bauss wrote:

On Saturday, 7 April 2018 at 09:07:48 UTC, sdvcn wrote:


true?stt="AA":stt="BB";-///Out:BB


It's an UB.

Not a bug.



I want `condition ? expr1 : expr2` to behave like:

-
auto qc( alias condition, string expr1, string expr2)() {
if( condition) {
return mixin( expr1);
} else {
return mixin( expr2);
}
}
-



Re: Space before parens in all function definitions

2018-04-07 Thread Sönke Ludwig via Digitalmars-d

Am 07.04.2018 um 04:23 schrieb Andrei Alexandrescu:

Why is there a space before "(" in our /library/ docs?

https://dlang.org/library/std/stdio/file.tmpfile.html

The paren here has role similar to that in mathematics, not literary.


Thanks,

Andrei


Has been a regression during the diet-ng transition. Fix in DDOX:

https://github.com/rejectedsoftware/ddox/pull/203


[Issue 18471] std.experimental.checkedint.Checked doesn't check on assignment or construction

2018-04-07 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18471

petrug  changed:

   What|Removed |Added

 CC||petru.guri...@gmail.com
   Assignee|nob...@puremagic.com|petru.guri...@gmail.com

--


Re: that is bug?

2018-04-07 Thread bauss via Digitalmars-d

On Saturday, 7 April 2018 at 09:07:48 UTC, sdvcn wrote:


true?stt="AA":stt="BB";-///Out:BB


It's an UB.

Not a bug.


Re: Game and GC

2018-04-07 Thread Danni Coy via Digitalmars-d-learn
gc causes unpredictabilities in performance*. With games it tends to be
worst case performance that matters.

I would reccomend using std.experimental.allocator (even if you still use
the default GC backed allocator). This will allow you to swap out your
allocator for a more specialised one as your requirements become more
concrete.

auto foo = new CustomStruct();

becomes

auto foo = allocator.make!CustomStruct();

The next thing you probably want is @nogc - Last time I checked getting
IAllocator objects are a bit tricky to use in @nogc code. Currently I am
using https://github.com/radcapricorn/alloctraits to get around this
limitation (You will still need an allocator that doesn't use the GC, I use
Mallocator for test purposes).

* The GC itself is deterministic, but it is really easy to write code that
triggers GC pauses at times that is difficult track down.







On Sat, Apr 7, 2018 at 7:55 AM, Chris Katko via Digitalmars-d-learn <
digitalmars-d-learn@puremagic.com> wrote:

> I'm in the same boat. I do games. But I love D's syntax and template
> power. So I'm doing a full experiment.
>
> Honestly, if D is that big a liability, you'll encounter it long before
> it's "too late" to port it to C++.
>
> Last night I had stuttering issues, but I realized there was a single,
> C-function, being called too many times (and never deallocating!).
>
> But previously, I've also had stutter issues. Now granted, I test on a
> "crap" laptop 2 GB RAM / Celeron processor. But it'll be 60 FPS ... then
> spike down. If this happens again with my current project, what I'm going
> to do, is hack the open source garbage collector to fire off an
> event/console message EVERY TIME it actually pauses to collect. Because
> it's possible the GC isn't actually the problem, or, some simple change to
> a line of code may prevent the GC from being a problem.
>
> That said, there's also @nogc (but that's also a bit of a lie because they
> never tell you that ANY THREAD running GC code can pause ALL THREADS for a
> collection.)
>
> But if you're making games, you should really be using static pools
> anyway. What's the MAXIMUM number of objects/trees/maps your game will have
> at a time? It's simple (regardless of D, C, Python, or Lua). Static. Pools.
> Basically, you just allocate at startup a simple fixed-length array for all
> your objects. That way, you're never asking the OS for memory = Never
> needing the garbage collector. If you don't use all that memory? Who cares.
> RAM is cheap. And if your program CAN swell in size, that means your
> low-end PCs will fail without knowing why.
>
> So you just put all your objects in fixed length arrays of size
> MAX_OBJECTS, MAX_ENEMIES, MAX_ITEMS, etc. And deleting an object is as
> simple as erasing it, or marking it as "bool is_deleted = true;" and adding
> a new object is simply finding the first "is_deleted" and re-running the
> constructor / re-using the carcass of the dead object.
>
> 99% of AAA studios use static pools. Now technically, static pools are
> "chunks" of fixed length arrays. So you could have one pool for a "map",
> and start loading another pool for the next map you're going to enter, and
> then when you finally transfer to the next map, you then free the static
> pool by marking it as deleted. And repeat as necessary. So it's a very
> macro-level amount of allocations. We're talking like, less than a dozen
> actual entities. (Depends on gametype, of course. But the
> order-of-magnitude helps convey it.)
>


Re: that is bug?

2018-04-07 Thread Jonathan M Davis via Digitalmars-d
On Saturday, April 07, 2018 09:07:48 sdvcn via Digitalmars-d wrote:
>   string stt = "none";
>   true?writeln("AA"):writeln("BB");   ///Out:AA
>  true?stt="AA":stt="BB";-///Out:BB
>   writeln(stt);

Assignment takes precendence over the ternary operator. So, no, I don't
think that it is. Putting parens around the assignment expressions makes it
print AA. As it stands, it evaluates both assignment expressions before
evaluating the ternary operator.

In general, I'd advise against using expressions with side effects in the
branches of a ternary operator, since it's easy to end up with a result that
doesn't do what you think it does (or which readers of your code will
misinterpret) - or you can just always use parens, but the folks who do that
generally end up using parens when they're completely unnecessary, which
IMHO makes the code uglier and harder to read. Either way, if you're doing
assignment, it generally makes more sense to put it outside the ternary
operator. e.g.

stt = condition ? "AA" : "BB";

Also FYI, questions should generally be asked in the D.Learn newsgroup/forum
instead of the main newsgroup/forum, which is for more general discussions
on D and how to improve it.

- Jonathan M Davis



that is bug?

2018-04-07 Thread sdvcn via Digitalmars-d



string stt = "none";
true?writeln("AA"):writeln("BB");   ///Out:AA
true?stt="AA":stt="BB";-///Out:BB
writeln(stt);






Re: How to destruct class instances allocated by a Region-allocator over a single GC block

2018-04-07 Thread Eduard Staniloiu via Digitalmars-d-learn

On Friday, 6 April 2018 at 21:49:37 UTC, Per Nordlöw wrote:
On Tuesday, 3 April 2018 at 09:14:28 UTC, Eduard Staniloiu 
wrote:

So, say `reg` is your allocator, your workflow would be

auto obj = reg.make!Type(args);
/* do stuff */
reg.dispose(obj); // If Type has a __dtor, it will call 
obj.__dtor

  // and then reg.deallocate(obj)


If I do sucessive calls to reg.make!X where X are different 
kinds of classes of different sizes how does reg.dispose(obj) 
figure out at which address(es) (where emplace filled in the 
data) the objects reside?


It can't figure out. With custom allocators you have to manually 
do
the memory management, so the responsibility of when and which 
object needs

to be destroyed falls on the user of the custom allocator.


Re: Function template argument deduction

2018-04-07 Thread Ali Çehreli via Digitalmars-d-learn

On 04/06/2018 11:26 PM, Uknown wrote:
> On Saturday, 7 April 2018 at 05:58:10 UTC, Paul Backus wrote:
>> On Saturday, 7 April 2018 at 05:46:07 UTC, Uknown wrote:
>>> I don't see the error you are talking about:
>>> https://run.dlang.io/is/XWPIc1
>>>
>>> Are you using the latest compiler?
>>
>> Compile with -unittest.
>>
>> And yes; I'm using DMD 2.079.0.
>
> Now I feel silly. Anyway, I played around with your code. One thing I
> found was `cons.head` returns a `T`, which can't be appended to a
> string. You can fix this with `cons.head.to!string`, where `to` is from
> std.conv. I'm not sure why IFTI isn't deducing `T` to be `int` though.
> Hopefully some one else can help out here.
>
> What I did notice though is that when
> `string list2string(T)(List!T list)` was changed to
> `string list2string(T)(VariantN!(16LU, Nil, Tuple!(T, "head", This*,
> "tail")) list)`
> The compiler correctly deduce `T` to be `int`

I played with it as well by hacking the following:

string list2string(L)(L list)
{
import std.traits : TemplateArgsOf;
alias T = TemplateArgsOf!L[2][0];

// ...
}

I hit the same problem that you describe. (Additionally, list2string 
does not return anything.)


Ali



Re: Function template argument deduction

2018-04-07 Thread Uknown via Digitalmars-d-learn

On Saturday, 7 April 2018 at 05:58:10 UTC, Paul Backus wrote:

On Saturday, 7 April 2018 at 05:46:07 UTC, Uknown wrote:
I don't see the error you are talking about: 
https://run.dlang.io/is/XWPIc1


Are you using the latest compiler?


Compile with -unittest.

And yes; I'm using DMD 2.079.0.


Now I feel silly. Anyway, I played around with your code. One 
thing I found was `cons.head` returns a `T`, which can't be 
appended to a string. You can fix this with 
`cons.head.to!string`, where `to` is from std.conv. I'm not sure 
why IFTI isn't deducing `T` to be `int` though. Hopefully some 
one else can help out here.


What I did notice though is that when
`string list2string(T)(List!T list)` was changed to
`string list2string(T)(VariantN!(16LU, Nil, Tuple!(T, "head", 
This*, "tail")) list)`

The compiler correctly deduce `T` to be `int`


Re: Function template argument deduction

2018-04-07 Thread Paul Backus via Digitalmars-d-learn

On Saturday, 7 April 2018 at 05:46:07 UTC, Uknown wrote:
I don't see the error you are talking about: 
https://run.dlang.io/is/XWPIc1


Are you using the latest compiler?


Compile with -unittest.

And yes; I'm using DMD 2.079.0.