Re: guard condition for a callable thingy, with THESE arguments

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

On Sunday, 15 May 2016 at 02:12:38 UTC, Ann W. Griffith wrote:
use "Parameters" in the constraint or make a template that you 
can reeuse.


This is what I've got going so far. Using static asserts to have 
clearer errors when an incorrect callback is supplied. I'm not... 
sure storage class is important.


import std.traits: isSomeFunction, isCallable,
  ParameterTypeTuple, ParameterStorageClassTuple, ReturnType,
  isDelegate;

import std.stdio;

template isCompatibleFunction(alias Src, alias Dest) {
 static assert(isSomeFunction!Src || isCallable!Src,
   "Source is not callable");
 static assert(isSomeFunction!Dest || isCallable!Dest,
   "Destination is not callable");

  static assert(is(ParameterTypeTuple!Src == 
ParameterTypeTuple!Dest),

"Type Tuples differ");
  pragma(msg,ParameterStorageClassTuple!Src ==
ParameterStorageClassTuple!Dest);
  static assert(ParameterStorageClassTuple!Src ==
ParameterStorageClassTuple!Dest,
"Storage classes differ");
  static assert(is(ReturnType!Src == ReturnType!Dest),
"Return type differs");
  immutable bool isCompatibleFunction = true;
}


bool function_callback(string a) {
  return true;
}

template foobar(Callable) 
if(isCompatibleFunction!(function_callback,Callable)) {

  template foobar(Callable c) {
immutable bool foobar = c("foo");
  }
}

void main() {
  bool result = true;
  bool delegate_callback(string a) {
return result;
  }
  bool delegate(string) dg = &delegate_callback;
  static assert(isDelegate!dg);
  static assert(isCompatibleFunction!(function_callback, 
delegate_callback));

  struct Derp {
static bool opCall(string a) {
  return true;
}
bool opCall(string a) {
  return false;
}
bool member(string a) {
  return true;
}
  };
  static 
assert(isCompatibleFunction!(function_callback,Derp.init.member));
  static 
assert(isCompatibleFunction!(function_callback,Derp.init));

  static assert(isCompatibleFunction!(function_callback,Derp));
  static assert(isCompatibleFunction!(delegate_callback,Derp));
  if(foobar!function_callback) {
writeln("foo");
  } else {
writeln("bar");
  }
  writeln("derp");
}



Re: guard condition for a callable thingy, with THESE arguments

2016-05-15 Thread Ann W. Griffith via Digitalmars-d-learn

On Sunday, 15 May 2016 at 07:22:57 UTC, cy wrote:

On Sunday, 15 May 2016 at 02:12:38 UTC, Ann W. Griffith wrote:
use "Parameters" in the constraint or make a template that you 
can reeuse.


This is what I've got going so far. Using static asserts to 
have clearer errors when an incorrect callback is supplied. I'm 
not... sure storage class is important.


It could be important, especially "ref" and "out" that could lead 
to UB if not checked, without compile error. "shared" also but 
when supplied, invalid callback will not compile.


Re: Why doesn't this chain of ndslices work?

2016-05-15 Thread 9il via Digitalmars-d-learn

On Saturday, 14 May 2016 at 21:59:48 UTC, Stiff wrote:

Here's the code that doesn't compile:

import std.stdio, std.experimental.ndslice, std.range, 
std.algorithm;


[...]


Coming soon 
https://github.com/libmir/mir/issues/213#issuecomment-219271447 
--Ilya


Re: Why doesn't this chain of ndslices work?

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

On Sunday, 15 May 2016 at 08:31:17 UTC, 9il wrote:

On Saturday, 14 May 2016 at 21:59:48 UTC, Stiff wrote:

Here's the code that doesn't compile:

import std.stdio, std.experimental.ndslice, std.range, 
std.algorithm;


[...]


Coming soon 
https://github.com/libmir/mir/issues/213#issuecomment-219271447 
--Ilya


Awesome, thanks to both of you. I think I can get what I want 
from mir.sparse. I was aware of it, but hadn't made the 
connection to what I'm trying to do for some reason.


More generally, I'm eagerly looking forward to a more complete 
Mir. I've been using bindings to GSL for non-uniform (and quasi-) 
random number generation, and a cleaner interface would be great. 
I'll be watching on github.


How do you use a non-dmd compiler within dub as default compiler?

2016-05-15 Thread Jamal via Digitalmars-d-learn
I made this little sdl2 game and written in D, and the project 
was initialized with dub.


When in the project directory and I type:

$ dub

It fetches all the dependencies and compiles with dmd.

So, what do I chance so that instead it compiles with ldc2 or 
even gdc for that matter?


Re: How do you use a non-dmd compiler within dub as default compiler?

2016-05-15 Thread rikki cattermole via Digitalmars-d-learn

On 16/05/2016 12:38 AM, Jamal wrote:

I made this little sdl2 game and written in D, and the project was
initialized with dub.

When in the project directory and I type:

$ dub

It fetches all the dependencies and compiles with dmd.

So, what do I chance so that instead it compiles with ldc2 or even gdc
for that matter?


Assuming ldc and gdc are installed:

$ dub --compiler=ldc2
$ dub --compiler=gdc


Using shorthand *= leads to unexpected result?

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

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

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


Re: Using shorthand *= leads to unexpected result?

2016-05-15 Thread Saurabh Das via Digitalmars-d-learn

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

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

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


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


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


~ sd



Re: How do you use a non-dmd compiler within dub as default compiler?

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

On Sunday, 15 May 2016 at 12:42:05 UTC, rikki cattermole wrote:

On 16/05/2016 12:38 AM, Jamal wrote:
I made this little sdl2 game and written in D, and the project 
was

initialized with dub.

When in the project directory and I type:

$ dub

It fetches all the dependencies and compiles with dmd.

So, what do I chance so that instead it compiles with ldc2 or 
even gdc

for that matter?


Assuming ldc and gdc are installed:

$ dub --compiler=ldc2
$ dub --compiler=gdc


Wow, easy enough.

Thank you!




Re: Using shorthand *= leads to unexpected result?

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

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

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

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

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


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


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


~ sd


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


Re: Using shorthand *= leads to unexpected result?

2016-05-15 Thread Saurabh Das via Digitalmars-d-learn

On Sunday, 15 May 2016 at 13:25:42 UTC, Michael wrote:
Well I'm pretty sure the code was working just fine earlier in 
the week at the office, but running the code at home with the 
newest version of DMD started producing these odd results.


Typing this function into asm.dlang.org shows a minor difference 
in the assembly generated:


auto f1(double d1)
{
  d1 *= -1.0;
  return d1;
}

With DMD 2.070.2:
pure nothrow @nogc @safe double example.f1(double):
 push   %rbp
 mov%rsp,%rbp
 sub$0x10,%rsp
 movsd  %xmm0,-0x8(%rbp)
 xorb   $0x80,-0x1(%rbp)
 rex.W movsd  -0x8(%rbp),%xmm0
 leaveq
 retq
 nopl   0x0(%rax)

With DMD 2.071.0:
pure nothrow @nogc @safe double example.f1(double):
 push   %rbp
 mov%rsp,%rbp
 sub$0x10,%rsp
 movsd  %xmm0,-0x8(%rbp)
 xorb   $0x80,-0x8(%rbp)
 rex.W movsd  -0x8(%rbp),%xmm0
 leaveq
 retq
 nopl   0x0(%rax)

The xorb line is different and I conjecture that it is causing 
the bug. I have never used floating-point assembly instructions, 
so I cannot understand what the logic is here. I'll read up and 
try to interpret to confirm.


Hope this helps.


Re: Using shorthand *= leads to unexpected result?

2016-05-15 Thread Marc Schütz via Digitalmars-d-learn

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

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

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


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

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


Re: Using shorthand *= leads to unexpected result?

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

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

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

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

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


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

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


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


docs generation for mixins

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

Hello,

sorry if this question was asked before...

How can I get docs generated for int z?

-
string V(string var) {
return "int " ~ var ~ ";";
}
///
struct X {
/// comment for y
int y;
/// comment for z
mixin(V("z"));
}

void main()
{
}
-

"dmd -D -Dddocs" generate docs for "y" only.

Thanks


Re: docs generation for mixins

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

On 05/15/2016 08:41 PM, ikod wrote:

How can I get docs generated for int z?

-
string V(string var) {
 return "int " ~ var ~ ";";
}
///
struct X {
 /// comment for y
 int y;
 /// comment for z
 mixin(V("z"));
}

void main()
{
}
-

"dmd -D -Dddocs" generate docs for "y" only.


Looks like doc generation doesn't expand mixins. I'm afraid there is no 
way to do this.


Some loosely related thoughts:

Instead of mixing in the whole declaration, generate the type (or 
function parameters, or whatever) with a template:


template V() { alias V = int; }

///
struct X {
/// comment for y
int y;
/// comment for z
V!() z;
}


Use a dummy declaration for doc generation:

/// comment for z
version (D_Ddoc) int z;
else mixin(V("z"));


By the way, `-Dddocs` implies `-D`. You don't need both.


Re: docs generation for mixins

2016-05-15 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, May 15, 2016 18:41:26 ikod via Digitalmars-d-learn wrote:
> Hello,
>
> sorry if this question was asked before...
>
> How can I get docs generated for int z?
>
> -
> string V(string var) {
>  return "int " ~ var ~ ";";
> }
> ///
> struct X {
>  /// comment for y
>  int y;
>  /// comment for z
>  mixin(V("z"));
> }
>
> void main()
> {
> }
> -
>
> "dmd -D -Dddocs" generate docs for "y" only.
>
> Thanks

AFAIK, ddoc doesn't work with string mixins. It _was_ fixed at some point so
that it works for template mixins, but as I understand it, the documentation
itself then goes on the symbol in the template, and then you need to put an
empty ddoc comment on the mixin itself to make the documentation that was in
the template itself show up. An example of this would be

http://dlang.org/phobos/std_exception.html#.basicExceptionCtors

It _might_ be the case that if you put the ddoc comment inside of the string
mixin that it will then end up in the documentation, but I doubt it. AFAIK,
the fact that it works with template mixins is recent, though given that you
need to document both the symbol inside of the template and the point where
it's mixed in, I suppose that it could just be that it's worked for a while,
but no one knew how to actually use it in a way that worked. I've never
heard of documentation working with string mixins though.

- Jonathan M Davis



Re: Reading ASCII file with some codes above 127 (exten ascii)

2016-05-15 Thread Era Scarecrow via Digitalmars-d-learn

On Thursday, 24 May 2012 at 19:47:06 UTC, era scarecrow wrote:

On Wednesday, 23 May 2012 at 21:02:27 UTC, Paul wrote:
I wonder about the speed between this method and Era's 
home-spun solution?
 Who knows? Perhaps it will be added to phobos once the table 
is verified.


 Well after taking to heart about a gc-less solution and doing a 
inputRange I re-wrote the entire thing. Of course to make it even 
faster/simpler a full lookup table conversion is used instead. 
Further reduction has made a very tiny simple filter.


 Curiously relooking at it there's actually very few codes that 
are there that really require special attention. If there's still 
any interest in this I can release it.