Re: lambda syntax with curly braces

2015-08-10 Thread bachmeier via Digitalmars-d-learn

On Monday, 10 August 2015 at 15:05:55 UTC, sigod wrote:
I see. But it's really counter intuitive after working with C#. 
Probably documentation should stress out the difference.


Thanks, Adam.


I assume you mean this page:

http://dlang.org/expression.html

There's an Improve this page button in the upper right corner. 
It's very easy to recommend a change.


Re: lambda syntax with curly braces

2015-08-10 Thread sigod via Digitalmars-d-learn

On Monday, 10 August 2015 at 16:02:31 UTC, bachmeier wrote:

On Monday, 10 August 2015 at 15:05:55 UTC, sigod wrote:
I see. But it's really counter intuitive after working with 
C#. Probably documentation should stress out the difference.


Thanks, Adam.


I assume you mean this page:

http://dlang.org/expression.html

There's an Improve this page button in the upper right 
corner. It's very easy to recommend a change.


Good point.

But I seldom do this because English isn't my native language.


Re: lambda syntax with curly braces

2015-08-10 Thread bachmeier via Digitalmars-d-learn

On Monday, 10 August 2015 at 16:15:40 UTC, sigod wrote:


Good point.

But I seldom do this because English isn't my native language.


Your English looks fine to me. Close enough to native that I 
can't tell the difference.


Re: std.array: array, ulong and Win32

2015-08-10 Thread Steven Schveighoffer via Digitalmars-d-learn

On 8/9/15 4:40 PM, ixid wrote:

On Sunday, 9 August 2015 at 20:33:10 UTC, anonymous wrote:

On Sunday, 9 August 2015 at 20:13:38 UTC, ixid wrote:



Yup, bug. Please file an issue at http://issues.dlang.org/.


It seems like bearophile beat me to it. Good to see he's still alive.

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


PR: https://github.com/D-Programming-Language/phobos/pull/3544

-Steve


Re: lambda syntax with curly braces

2015-08-10 Thread sigod via Digitalmars-d-learn

On Monday, 10 August 2015 at 14:05:30 UTC, Adam D. Ruppe wrote:

On Monday, 10 August 2015 at 13:57:50 UTC, sigod wrote:

[...]


It does exactly what that says: rewrites it to

(a) {
  return {
   writeln(a);
  };
}


which is returning a delegate.


[...]


So your code passed a delegate that returned a delegate to 
each. Since the one returned wasn't called, the writeln never 
happened.


If you call it like so:

[1,2,3,4,5]
.each!(a = {
writeln(a);
}()); // added parens call the returned delegate

then you see it.




The = thing in D is meant only for trivial, single line 
things. If you want multiple lines, that's where the {} syntax 
comes in with no need for the =.


.each!( (a) {
   writeln(a);
  });


I see. But it's really counter intuitive after working with C#. 
Probably documentation should stress out the difference.


Thanks, Adam.


Re: Measuring test coverage

2015-08-10 Thread Alexei Bykov via Digitalmars-d-learn

On Monday, 10 August 2015 at 08:06:35 UTC, Stefan Frijters wrote:

On Sunday, 9 August 2015 at 20:24:22 UTC, Alexei Bykov wrote:
D has builtin support for coverage analysis but it produces 
only .lst files. This is a bit inconvenient. Is there any tool 
which can create something like an html report from .lst files?
For now I'm using OpenCppCoverage which is not the best tool 
and works only on Windows but at least it produces html 
reports which can be customized (sort of).


If your code is hosted at Github or similar, 
https://github.com/ColdenCullen/doveralls allows you to use 
coveralls.io for D code. Not made by me, but I've been using it 
for a while now and it works very well for me.


Thanks for the link. I'll try that.


Re: Measuring test coverage

2015-08-10 Thread Alexei Bykov via Digitalmars-d-learn

On Monday, 10 August 2015 at 04:03:36 UTC, Rikki Cattermole wrote:

On 10/08/2015 8:24 a.m., Alexei Bykov wrote:
D has builtin support for coverage analysis but it produces 
only .lst
files. This is a bit inconvenient. Is there any tool which can 
create

something like an html report from .lst files?
For now I'm using OpenCppCoverage which is not the best tool 
and works
only on Windows but at least it produces html reports which 
can be

customized (sort of).


Good news, looks like you'll be working on a new D tool ;)


Well, it came into my thought to make some helper scripts :


Re: Concurrency Confusion

2015-08-10 Thread sigod via Digitalmars-d-learn

On Monday, 10 August 2015 at 22:21:18 UTC, 岩倉 澪 wrote:

On Saturday, 8 August 2015 at 06:24:30 UTC, sigod wrote:
Use negative value for `receiveTimeout`. 
http://stackoverflow.com/q/31616339/944911


actually this no longer appears to be true?
Passing -1.msecs as the duration gives me an assertion failure:

core.exception.AssertError@std/concurrency.d(1902): Assertion 
failure


Took a look in phobos and it appears to be from this line:
https://github.com/D-Programming-Language/phobos/blob/master/std/concurrency.d#L1904

If you look at the implementation of receiveTimeout, you'll see 
that it no longer has these lines from the stack overflow 
answer:


if( period.isNegative || !m_putMsg.wait( period ) )
return false;

https://github.com/D-Programming-Language/phobos/blob/master/std/concurrency.d#L824


That's weird. Especially when latest commit is mine: 
https://github.com/D-Programming-Language/phobos/commit/c8048fa48832a97f033b748f5e6b8edde3f2ae29


Re: Concurrency Confusion

2015-08-10 Thread sigod via Digitalmars-d-learn

On Monday, 10 August 2015 at 22:21:18 UTC, 岩倉 澪 wrote:

On Saturday, 8 August 2015 at 06:24:30 UTC, sigod wrote:
Use negative value for `receiveTimeout`. 
http://stackoverflow.com/q/31616339/944911


actually this no longer appears to be true?
Passing -1.msecs as the duration gives me an assertion failure:

core.exception.AssertError@std/concurrency.d(1902): Assertion 
failure


Took a look in phobos and it appears to be from this line:
https://github.com/D-Programming-Language/phobos/blob/master/std/concurrency.d#L1904


It looks like you're trying to use `receiveTimeout` like this:

bool value;
receiveTimeout(-1.msecs, value);

But you must use it like this:

bool value;
receiveTimeout(-1.msecs, (bool b) { value = b; });

See [`receive`][0] for example.

[0]: http://dlang.org/phobos/std_concurrency.html#.receive


Re: Concurrency Confusion

2015-08-10 Thread sigod via Digitalmars-d-learn

On Monday, 10 August 2015 at 22:21:18 UTC, 岩倉 澪 wrote:

On Saturday, 8 August 2015 at 06:24:30 UTC, sigod wrote:
Use negative value for `receiveTimeout`. 
http://stackoverflow.com/q/31616339/944911


actually this no longer appears to be true?
Passing -1.msecs as the duration gives me an assertion failure:

core.exception.AssertError@std/concurrency.d(1902): Assertion 
failure


Took a look in phobos and it appears to be from this line:
https://github.com/D-Programming-Language/phobos/blob/master/std/concurrency.d#L1904


It should be this line: 
https://github.com/D-Programming-Language/phobos/blob/master/std/concurrency.d#L1910


If you look at the implementation of receiveTimeout, you'll see 
that it no longer has these lines from the stack overflow 
answer:


if( period.isNegative || !m_putMsg.wait( period ) )
return false;

https://github.com/D-Programming-Language/phobos/blob/master/std/concurrency.d#L824


This lines still there: 
https://github.com/D-Programming-Language/phobos/blob/master/std/concurrency.d#L2081


I'll remove mentioned assert.


Re: Concurrency Confusion

2015-08-10 Thread sigod via Digitalmars-d-learn

On Monday, 10 August 2015 at 22:31:33 UTC, sigod wrote:

On Monday, 10 August 2015 at 22:21:18 UTC, 岩倉 澪 wrote:

[...]


It should be this line: 
https://github.com/D-Programming-Language/phobos/blob/master/std/concurrency.d#L1910



[...]


This lines still there: 
https://github.com/D-Programming-Language/phobos/blob/master/std/concurrency.d#L2081


I'll remove mentioned assert.


https://github.com/D-Programming-Language/phobos/pull/3545


Re: Concurrency Confusion

2015-08-10 Thread 岩倉 澪

On Saturday, 8 August 2015 at 06:24:30 UTC, sigod wrote:
Use negative value for `receiveTimeout`. 
http://stackoverflow.com/q/31616339/944911


actually this no longer appears to be true?
Passing -1.msecs as the duration gives me an assertion failure:

core.exception.AssertError@std/concurrency.d(1902): Assertion 
failure


Took a look in phobos and it appears to be from this line:
https://github.com/D-Programming-Language/phobos/blob/master/std/concurrency.d#L1904

If you look at the implementation of receiveTimeout, you'll see 
that it no longer has these lines from the stack overflow answer:


if( period.isNegative || !m_putMsg.wait( period ) )
return false;

https://github.com/D-Programming-Language/phobos/blob/master/std/concurrency.d#L824


Re: Concurrency Confusion

2015-08-10 Thread 岩倉 澪

On Monday, 10 August 2015 at 22:50:15 UTC, sigod wrote:

On Monday, 10 August 2015 at 22:21:18 UTC, 岩倉 澪 wrote:

Took a look in phobos and it appears to be from this line:
https://github.com/D-Programming-Language/phobos/blob/master/std/concurrency.d#L1904


It looks like you're trying to use `receiveTimeout` like this:

bool value;
receiveTimeout(-1.msecs, value);


Ah, nope I just assumed the closest assert to the line mentioned 
in the assertion failure was the culprit without thinking about 
it much. You are correct that the assertion your pull requests 
removes is the one that gave me trouble. I'll leave it as 0.msecs 
until your pull request is merged and a new release made, thanks 
for the help!





Re: Concurrency Confusion

2015-08-10 Thread Kagamin via Digitalmars-d-learn
There's indeed a good reason: Variant is a kitchen sink wrapper 
and tries to declare questionable code for shared type, and 
compiler catches that. Quite an impressive example of shared type 
qualifier in action, even though Variant uses a lot of casting so 
there's not a lot of type system at work there.


Re: Measuring test coverage

2015-08-10 Thread Stefan Frijters via Digitalmars-d-learn

On Sunday, 9 August 2015 at 20:24:22 UTC, Alexei Bykov wrote:
D has builtin support for coverage analysis but it produces 
only .lst files. This is a bit inconvenient. Is there any tool 
which can create something like an html report from .lst files?
For now I'm using OpenCppCoverage which is not the best tool 
and works only on Windows but at least it produces html reports 
which can be customized (sort of).


If your code is hosted at Github or similar, 
https://github.com/ColdenCullen/doveralls allows you to use 
coveralls.io for D code. Not made by me, but I've been using it 
for a while now and it works very well for me.


website update

2015-08-10 Thread Tony via Digitalmars-d-learn

It looks like this page:

http://dlang.org/hash-map.html

Should have the override keyword added the the member functions 
in Foo:


class Foo
{
int a, b;

size_t toHash() { return a + b; }

bool opEquals(Object o)
{
Foo foo = cast(Foo) o;
return foo  a == foo.a  b == foo.b;
}
}


Re: Importing local modules in C style

2015-08-10 Thread Binarydepth via Digitalmars-d-learn
On Thursday, 25 June 2015 at 14:10:00 UTC, Steven Schveighoffer 
wrote:

On 6/25/15 9:57 AM, Binarydepth wrote:
I want to import a module from my local project  in C style 
(#include

local.h).


No.



I know I can do dmd main.d local.d but I wonder if it can be 
done C

style.


What is your goal? Why doesn't D import work for you?

-Steve


No goal just wondering, Thanks!

In the future when GDC and MAKE can work together I want to just 
do make code and have the non-standard, custom libraries be 
supplied to the compiler by MAKE.


For a project I would just write the Makefile for this


Re: website update

2015-08-10 Thread tcak via Digitalmars-d-learn

On Monday, 10 August 2015 at 10:34:56 UTC, Tony wrote:

It looks like this page:

http://dlang.org/hash-map.html

Should have the override keyword added the the member functions 
in Foo:


class Foo
{
int a, b;

size_t toHash() { return a + b; }

bool opEquals(Object o)
{
Foo foo = cast(Foo) o;
return foo  a == foo.a  b == foo.b;
}
}


Also that return line is confusing. Some parenthesis could be put 
there.


format of trace.log

2015-08-10 Thread yawniek via Digitalmars-d-learn

is there a reason the trace log is a bit weirdly formatted?

a) different tables within one file
b) column separation is something like (fill with space until it 
exceeds 7 digits



could this be improved to use a standard format (e.g. tsv) or are 
there some legacy reasons?


also it would be nice to automatically pipe it trough ddemange if 
that is available.



speaking of ddemangle, would it be possible to support lambda 
functions?





Re: website update

2015-08-10 Thread bachmeier via Digitalmars-d-learn

On Monday, 10 August 2015 at 11:20:32 UTC, tcak wrote:

On Monday, 10 August 2015 at 10:34:56 UTC, Tony wrote:

It looks like this page:

http://dlang.org/hash-map.html

Should have the override keyword added the the member 
functions in Foo:


class Foo
{
int a, b;

size_t toHash() { return a + b; }

bool opEquals(Object o)
{
Foo foo = cast(Foo) o;
return foo  a == foo.a  b == foo.b;
}
}


Also that return line is confusing. Some parenthesis could be 
put there.


Click the Improve this page button in the upper right corner.


lambda syntax with curly braces

2015-08-10 Thread sigod via Digitalmars-d-learn

From docs:
The following part = AssignExpression is rewritten to 
FunctionLiteralBody:

{ return AssignExpression ; }


So, I wonder what happens when curly braces already in place?

Consider this example:
```
import std.algorithm;
import std.stdio;

void main() {
[1,2,3,4,5]
.each!(a = { // remove `=` and you'll get output
writeln(a);
});
}
```

This code compiles and doesn't output anything. Which is very 
counterintuitive for me, because my main experience with lambdas 
was in C#. Where it's perfectly fine to write `identifiers = { 
/* some code */ }`.




Re: lambda syntax with curly braces

2015-08-10 Thread Adam D. Ruppe via Digitalmars-d-learn

On Monday, 10 August 2015 at 13:57:50 UTC, sigod wrote:

From docs:
The following part = AssignExpression is rewritten to 
FunctionLiteralBody:

{ return AssignExpression ; }


So, I wonder what happens when curly braces already in place?


It does exactly what that says: rewrites it to

(a) {
  return {
   writeln(a);
  };
}


which is returning a delegate.


This code compiles and doesn't output anything.


So your code passed a delegate that returned a delegate to each. 
Since the one returned wasn't called, the writeln never happened.


If you call it like so:

[1,2,3,4,5]
.each!(a = {
writeln(a);
}()); // added parens call the returned delegate

then you see it.




The = thing in D is meant only for trivial, single line things. 
If you want multiple lines, that's where the {} syntax comes in 
with no need for the =.


.each!( (a) {
   writeln(a);
  });