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

2017-12-18 Thread Mike Franklin via Digitalmars-d-learn

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


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


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



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


Mike


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

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

On Tuesday, 19 December 2017 at 01:30:07 UTC, Mike Franklin wrote:


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


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

i.e.
// 
import std.stdio;

struct S
{
int j;
}

void main()
{
writeln(typeof(S.j).stringof);
   // prints: int
}
// -

"AliasDeclarations create a symbol that is an alias for another 
type, and can be used anywhere that other type may appear. ".


Since typeof S.j is an int, that seems consistent with this 
requirement, that alias is an alias for another type.




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

2017-12-18 Thread Mike Franklin via Digitalmars-d-learn

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

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


struct S { static int i; }
S s;

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

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


I think the example is wrong.  Consider this:


import std.stdio;

struct S
{
static int i;
int j;
}
S s;

void main()
{
s.i = 1;
s.j = 2;

writeln(s.i);  // OK: Static symbols can be used through 
instances

writeln(S.i);  // OK: Static symbols can be used through types
writeln(s.j);  // OK: Instance symbols can be used through 
instances
//writeln(S.j);  // Error: Instance symbols cannot be used 
through types.

}


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

Please file a bug report at http://issues.dlang.org/

Mike



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

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

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

Hello,

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


struct S { static int i; }
S s;

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

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

a = 3;

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


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


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

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

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


alias a = s.i; // illegal, s.i is an expression


Actually, as I understand it, the example provided in 10. is 
legal (because it aliases a type), and the example provided in 3. 
is illegal (because it aliases an expression)


perhaps the examples in 10 and 3 should be swapped.

https://dlang.org/spec/declaration.html#alias



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

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

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


alias a = s.i; // illegal, s.i is an expression



alias a = s.i; (this is an alias to a type, since s.i is an int)

Hence it is actually 'legal', as far as I understand.

i.e... "AliasDeclarations create a symbol that is an alias for 
another type, and can be used anywhere that other type may 
appear. "


What is 'illegal', is an alias to an expression.. for example:

alias strlen = string.sizeof;



Re: How do I pass a type as parameter in this method?

2017-12-18 Thread Ali Çehreli via Digitalmars-d-learn

On 12/18/2017 03:54 PM, Ali Çehreli wrote:

On 12/18/2017 02:58 PM, Marc wrote:


Here's another experiment:

template FirstOf(T...) {
template otherwise(D) {
static if (T.length == 0) {
enum otherwise = D.init;
} else {
enum otherwise = T[0];
}
}
}

void main() {
static assert (FirstOf!(1.5, "hello").otherwise!int == 1.5);
static assert (FirstOf!("world", [1]).otherwise!int == "world");
static assert (FirstOf!().otherwise!int == 0);
}

Ali


Re: How do I pass a type as parameter in this method?

2017-12-18 Thread Ali Çehreli via Digitalmars-d-learn

On 12/18/2017 02:58 PM, Marc wrote:

Imaginary code:


int index = FirstOrDefault!(int)(__traits(getAttributes, C.a));


In that case, if the tuple is empty, the value is the int's type default 
value.


The method is defined as  following:


template FirstOrDefault(X)(T...) {
static if(T.length > 0) {
    enum FirstOrDefault = T[0];
} else {
    enum FirstOrDefault = X.init;
}
}


template FirstOrDefault(D) {
template FirstOrDefault(T...) {
static if(T.length > 0) {
enum FirstOrDefault = T[0];
} else {
enum FirstOrDefault = D.init;
}
}
}

template FirstOrDefault_2(T...) {
static if(T.length > 1) {
enum FirstOrDefault_2 = T[1];
} else {
enum FirstOrDefault_2 = T[0].init;
}
}

template FirstOrDefault_3(D) {
template of(T...) {
static if(T.length > 0) {
enum of = T[0];
} else {
enum of = D.init;
}
}
}

void main() {
// This one requires an alias because I could not get rid of "Error:
// multiple ! arguments are not allowed".
alias IntDefault = FirstOrDefault!int;
static assert (IntDefault!() == 0);
static assert (IntDefault!([1], "hello") == [1]);
static assert (IntDefault!("world", 1.5) == "world");

// This one puts everything into the same argument list
static assert (FirstOrDefault_2!(double, "yo") == "yo");
import std.math;
static assert (isNaN(FirstOrDefault_2!(double)));

// This one invents .of for an arguably more readable syntax
static assert (FirstOrDefault_3!int.of!(7) == 7);
struct S {
int i = 42;
}
static assert (FirstOrDefault_3!S.of!().i == 42);
}

Ali


Alias example should supposedly be illegal, but runs fine

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

Hello,

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


struct S { static int i; }
S s;

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

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

a = 3;

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


How do I pass a type as parameter in this method?

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

Imaginary code:


int index = FirstOrDefault!(int)(__traits(getAttributes, C.a));


In that case, if the tuple is empty, the value is the int's type 
default value.


The method is defined as  following:


template FirstOrDefault(X)(T...) {
static if(T.length > 0) {
enum FirstOrDefault = T[0];
} else {
enum FirstOrDefault = X.init;
}
}


Re: Dub project has both .sdl and .json files. Is this normal or did I do something wrong?

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

On Monday, 18 December 2017 at 22:36:44 UTC, WhatMeWorry wrote:


I've been using Dub for a while but from the very beginning I 
decided to go with SDL 100% of the time, So I've got a dub.sdl 
file like:


name "01_10_camera_view_space"
description "A minimal D application."
authors "kheaser"
copyright "Copyright © 2017, kheaser"
license "proprietary"

dependency "derelict-al"  version="~>1.0.3"
dependency "derelict-assimp3" version="~>1.3.0"
dependency "derelict-fi"  version="~>2.0.3"
dependency "derelict-fmod"version="~>2.0.4"
dependency "derelict-ft"  version="~>1.1.3"
dependency "derelict-gl3" version="~>1.0.23"
dependency "derelict-glfw3"   version="~>3.1.3"
dependency "derelict-util"version="~>2.0.6"
dependency "gl3n" version="~>1.3.1"
  .


But when I look the directory that has the dub.sdl file, I also 
see a file called dub.selections.json


{
"fileVersion": 1,
"versions": {
"derelict-al": "1.0.3",
"derelict-assimp3": "1.3.0",
"derelict-fi": "2.0.3",
"derelict-fmod": "2.0.4",
"derelict-ft": "1.1.3",
"derelict-gl3": "1.0.23",
"derelict-glfw3": "3.1.3",
"derelict-util": "2.0.6",
"gl3n": "1.3.1"
}
}


So how did this .json file get created and can I just delete 
it?  I only noticed this because when I was troubleshooting the 
project, I changed the dub.sdl library versions but the 
compile/run was using the library versions in 
dub.selections.json.


I did switch from using DMD to LDC, if that has any bearing.


dub.selections.json is basically broken design, once it's there 
it will ignore any version value you write in dub.json/dub.sdl 
until you dub upgrade. This can lead to many bugs very easily, 
but just remember to dub upgrade every time you change versions 
and it will be fine.


dub.selections.json stores the versions which got picked when 
first adding the dependency so that others can get the same 
version of the dependency and should hopefully get a working 
build if you managed to build it. The two major problems: if your 
new version range doesn't actually allow that version anymore dub 
will still use it anyway until you dub upgrade. Second it doesn't 
even store commit hashes when using ~master. So basically 
assuming the dependency author properly uses SemVer (don't break 
backwards compatibility on minor releases) and your version range 
only accepts minor updates it is literally nonsense to freeze the 
package on a minor version if your range allows a higher version. 
Basically you are missing security patches if you use 
dub.selections.json


To be honest I wouldn't push it to git, it keeps changing, always 
only gives conflicts and breaks things, especially when using 
"path". But the dub devs say it should be pushed, though I have 
never seen anything good come out of it.


Re: weird exception on windows

2017-12-18 Thread unleashy via Digitalmars-d-learn
On Friday, 15 December 2017 at 21:56:48 UTC, Steven Schveighoffer 
wrote:

On 12/15/17 10:08 AM, Kagamin wrote:

Maybe this https://issues.dlang.org/show_bug.cgi?id=18084


Thanks for looking into this. I created a PR to fix.

Szabo, can you please try with this patch and see if it fixes 
your issue?


https://github.com/dlang/phobos/pull/5932

-Steve


I created the original issue in Szabo's post. I applied your fix, 
but nothing changed—the test program still crashes with the same 
exception :/


What gives?


Dub project has both .sdl and .json files. Is this normal or did I do something wrong?

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


I've been using Dub for a while but from the very beginning I 
decided to go with SDL 100% of the time, So I've got a dub.sdl 
file like:


name "01_10_camera_view_space"
description "A minimal D application."
authors "kheaser"
copyright "Copyright © 2017, kheaser"
license "proprietary"

dependency "derelict-al"  version="~>1.0.3"
dependency "derelict-assimp3" version="~>1.3.0"
dependency "derelict-fi"  version="~>2.0.3"
dependency "derelict-fmod"version="~>2.0.4"
dependency "derelict-ft"  version="~>1.1.3"
dependency "derelict-gl3" version="~>1.0.23"
dependency "derelict-glfw3"   version="~>3.1.3"
dependency "derelict-util"version="~>2.0.6"
dependency "gl3n" version="~>1.3.1"
  .


But when I look the directory that has the dub.sdl file, I also 
see a file called dub.selections.json


{
"fileVersion": 1,
"versions": {
"derelict-al": "1.0.3",
"derelict-assimp3": "1.3.0",
"derelict-fi": "2.0.3",
"derelict-fmod": "2.0.4",
"derelict-ft": "1.1.3",
"derelict-gl3": "1.0.23",
"derelict-glfw3": "3.1.3",
"derelict-util": "2.0.6",
"gl3n": "1.3.1"
}
}


So how did this .json file get created and can I just delete it?  
I only noticed this because when I was troubleshooting the 
project, I changed the dub.sdl library versions but the 
compile/run was using the library versions in dub.selections.json.


I did switch from using DMD to LDC, if that has any bearing.







Re: weird exception on windows

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

On Saturday, 16 December 2017 at 14:05:28 UTC, Vino wrote:

On Saturday, 16 December 2017 at 13:59:11 UTC, Vino wrote:

On Saturday, 16 December 2017 at 12:39:53 UTC, Kagamin wrote:

[...]


H, All,

  Are are also getting the same exception on Windows after 
updating the dmd to version v2.077.1, our code was working 
fine for the past 2 months, the exception is just crashes the 
program, and it occur's every 1 time  among in 3 runs. As per 
Microsoft it stated to download the package apps.diagcab and 
execute, but still no luck.


ExceptionCode: C005

From,
Vino.B


Moreover we were able to find the line of code which was 
causing this exception


string a = "1"
a.to!int.isNumber /* exception is occurring at this point.

From,
Vino.B


the compiler might be parsing the expr like (a.to!(int.isNumber)) 
so it becomes a.to!bool.


Re: Write native GUI applications for Windows

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

On Monday, 18 December 2017 at 08:49:51 UTC, Binghoo Dang wrote:

On Monday, 18 December 2017 at 07:55:25 UTC, Andrey wrote:

Hello!
I have a question about creating native GUI applications for 
Windows 7 or/and Windows 10.
I know that exist DWT, DlangUI and other... But I'm 
interesting in native GUI. If it will be C++ then I would use 
WinAPI from SDK.
And what about D? What should I do? Make some kind of wrapper 
above C WinApi?
I also know that on GitHub exists such wrapper 
(https://github.com/AndrejMitrovic/DWinProgramming) but it is 
old - last commit was 4 years ago.


Could you help me?


You can use libuid which can be found here 
https://code.dlang.org/packages/libuid.


It wrapped the native os gui for d, and it's cross-platform.


Any chance of having a version that allows static linking?

Zz


Re: Fold in Parallelism

2017-12-18 Thread Russel Winder via Digitalmars-d-learn
Ali,

Shouldn't this be a pull request for std.parallelism to be extended? 

If the function is in std.algorithm, then people should not have to
write it for themselves in std.parallelism.


On Mon, 2017-12-18 at 11:01 -0800, Ali Çehreli via Digitalmars-d-learn
wrote:
> 
[…]
> > Hi Ali,
> > 
> >Thank you very much, may we know if possible as to when this
> > would be 
> > added.
> > 
> > From,
> > Vino.B
> 
> The implementation is almost a copy+paste from std.algorithm.fold.
> You 
> can simply copy the following fold template to your project and
> start 
> using it:
> 
> import std.parallelism;
> import std.stdio;
> 
> int adder(int result, int element) {
>  return result + element;
> }
> 
> template fold(fun...)
> if (fun.length >= 1)
> {
>  import std.parallelism : TaskPool;
>  auto fold(R, S...)(TaskPool t, R r, S seed)
>  {
>  static if (S.length < 2)
>  {
>  return t.reduce!fun(seed, r);
>  }
>  else
>  {
>  import std.typecons : tuple;
>  return t.reduce!fun(tuple(seed), r);
>  }
>  }
> }
> 
> unittest {
>  import std.range;
> 
>  const N = 10_000;
>  const expected = N * (N - 1) / 2;
> 
>  foreach (numThreads; 1 .. 100) {
>  auto t = new TaskPool(numThreads);
>  const result = t.fold!adder(N.iota);
>  assert(result == expected);
>  t.finish();
>  }
> }
> 
> void main() {
> }
> 
> If you want to provide an explicit seed value, good luck making sense
> of 
> how it affects the final result. :) (The documentation of 
> TaskPool.reduce explains it but I find it too involved to
> understand.)
> 
> Ali
-- 
Russel.
===
Dr Russel Winder  t: +44 20 7585 2200
41 Buckmaster Roadm: +44 7770 465 077
London SW11 1EN, UK   w: www.russel.org.uk


signature.asc
Description: This is a digitally signed message part


Re: DMD Test Suite Windows

2017-12-18 Thread kinke via Digitalmars-d-learn
On Monday, 18 December 2017 at 16:06:33 UTC, Jonathan Marler 
wrote:
Trying to run the dmd test suite on windows, looks like Digital 
Mars "make" doesn't work with the Makefile, I tried Gnu Make 
3.81 but no luck with that either.  Anyone know which version 
of make it is supposed to work with on windows?  Is it supposed 
to work on windows at all?


LDC is running the dmd-testsuite with GNU make v4.2.1 (whose 
source comes with a Visual Studio solution btw) on Win32 and 
Win64. IIRC, the OS detection needed to be tweaked 
(OS=win32|win64) and additional GNU tools were needed (=> using 
the ones git ships with). I didn't realize there's a Digital Mars 
make. ;)


Re: Fold in Parallelism

2017-12-18 Thread Ali Çehreli via Digitalmars-d-learn

On 12/18/2017 02:18 AM, Vino wrote:

On Sunday, 17 December 2017 at 20:00:53 UTC, Ali Çehreli wrote:

On 12/17/2017 08:11 AM, Vino wrote:

>   As per the document form std.parallelism it states that we
can use
> taskPool.reduce so can we use the same for fold
(taskPool.fold) as
> basically both are same with slight variation on seed values,
if
> possible can can we define the same in the below lines

fold has only been added to std.algorithm. Opened an enhancement request:

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

Ali


Hi Ali,

   Thank you very much, may we know if possible as to when this would be 
added.


From,
Vino.B


The implementation is almost a copy+paste from std.algorithm.fold. You 
can simply copy the following fold template to your project and start 
using it:


import std.parallelism;
import std.stdio;

int adder(int result, int element) {
return result + element;
}

template fold(fun...)
if (fun.length >= 1)
{
import std.parallelism : TaskPool;
auto fold(R, S...)(TaskPool t, R r, S seed)
{
static if (S.length < 2)
{
return t.reduce!fun(seed, r);
}
else
{
import std.typecons : tuple;
return t.reduce!fun(tuple(seed), r);
}
}
}

unittest {
import std.range;

const N = 10_000;
const expected = N * (N - 1) / 2;

foreach (numThreads; 1 .. 100) {
auto t = new TaskPool(numThreads);
const result = t.fold!adder(N.iota);
assert(result == expected);
t.finish();
}
}

void main() {
}

If you want to provide an explicit seed value, good luck making sense of 
how it affects the final result. :) (The documentation of 
TaskPool.reduce explains it but I find it too involved to understand.)


Ali


Re: weird exception on windows

2017-12-18 Thread Steven Schveighoffer via Digitalmars-d-learn

On 12/18/17 7:20 AM, Szabo Bogdan wrote:

On Saturday, 16 December 2017 at 12:01:49 UTC, Steven Schveighoffer wrote:

On 12/16/17 5:12 AM, bauss wrote:

On Saturday, 16 December 2017 at 08:07:30 UTC, Szabo Bogdan wrote:
On Friday, 15 December 2017 at 21:56:48 UTC, Steven Schveighoffer 
wrote:

On 12/15/17 10:08 AM, Kagamin wrote:

Maybe this https://issues.dlang.org/show_bug.cgi?id=18084


Thanks for looking into this. I created a PR to fix.

Szabo, can you please try with this patch and see if it fixes your 
issue?


https://github.com/dlang/phobos/pull/5932

-Steve


I have installed DMD 2.77.1 and I can not find the patched file in 
the phobos folder... should I try this by building the compiler?


It seams that I can not build phobos without compiling dmd.. or 
maybe I don't know how...


Just go and do the changes manually in your local phobos folder, 
wherever you have DMD installed, since you can't build phobos or dmd.


Yes, this won't get into the release for a while. So please do this 
manually (just copy the file changed by the pull over the existing one).


It's something that doesn't need to be compiled into the phobos 
library, as it's a misrepresentation of the actual object when you 
compile with unittests, so there is no reason to recompile phobos.




I'm actually a linux and a mac user...


Me too :)

this issue happens on a windows 
ci machine at work. I tried to update the file and compile phobos with 
that change, and I don't know how to make it work...


Hm... you shouldn't need to recompile phobos, it should be identical 
when not in unittest mode.


Just replace the one file and see if the CI starts working.

I don't know where I can find a 64bit toolchain for vs2010... I was 
expecting that dmd uses a newer compiler on windows...


I hope someone can help you there, but I would expect most folks here to 
either not be Windows developers, or to be using the interactive version 
(not CI version). There may be someone with some experience than can help.


I guess that the best approach for me is to wait the next beta release 
of dmd and try it then...


That is also an option. However, the PR hasn't been pulled yet...

-Steve


Re: DMD Test Suite Windows

2017-12-18 Thread Seb via Digitalmars-d-learn
On Monday, 18 December 2017 at 16:06:33 UTC, Jonathan Marler 
wrote:
Trying to run the dmd test suite on windows, looks like Digital 
Mars "make" doesn't work with the Makefile, I tried Gnu Make 
3.81 but no luck with that either.  Anyone know which version 
of make it is supposed to work with on windows?  Is it supposed 
to work on windows at all?


Have you tried a 4.x release of GnuMake.
AFAICT it's the one used at auto-tester: 
https://auto-tester.puremagic.com/show-run.ghtml?projectid=1=2950828=20880978=true



Also have a look at this PR: 
https://github.com/dlang/dmd/pull/7214 (it uses gmake 4.2)


If any case, it would be great if you could update the wiki page 
[1] if you manage to get it working on your machine. It looks 
rather outdated.



[1] https://wiki.dlang.org/Building_under_Windows


DMD Test Suite Windows

2017-12-18 Thread Jonathan Marler via Digitalmars-d-learn
Trying to run the dmd test suite on windows, looks like Digital 
Mars "make" doesn't work with the Makefile, I tried Gnu Make 3.81 
but no luck with that either.  Anyone know which version of make 
it is supposed to work with on windows?  Is it supposed to work 
on windows at all?


Why dynamic lib can't be converted to static and vise versa

2017-12-18 Thread Suliman via Digitalmars-d-learn
I understand that dll can be loaded dynamically, and static lib 
is allow export functions than embedded to binaries. But what 
difference in their structure? What stop to export needed 
function from dynamic lib and embed it to bin?


Re: Clarity about extern(Windows)/extern(System)

2017-12-18 Thread Mike Parker via Digitalmars-d-learn

On Monday, 18 December 2017 at 14:31:38 UTC, Kagamin wrote:

https://gcc.gnu.org/onlinedocs/gcc-7.2.0/gcc/x86-Function-Attributes.html#index-functions-that-pop-the-argument-stack-on-x86-32-3
 looks like gcc doesn't see it as OS dependent.


Thanks. I was playing around on asm.dlang.org and found there's a 
definite difference in 32-bit output.


Re: Clarity about extern(Windows)/extern(System)

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

From https://gcc.godbolt.org/

__attribute__((stdcall))
int square(int num) {
return num * num;
}

_Z6squarei:
  push ebp
  mov ebp, esp
  mov eax, DWORD PTR [ebp+8]
  imul eax, DWORD PTR [ebp+8]
  pop ebp
  ret 4


Re: Clarity about extern(Windows)/extern(System)

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

https://gcc.gnu.org/onlinedocs/gcc-7.2.0/gcc/x86-Function-Attributes.html#index-functions-that-pop-the-argument-stack-on-x86-32-3
 looks like gcc doesn't see it as OS dependent.


Re: Write native GUI applications for Windows

2017-12-18 Thread Jacob Carlborg via Digitalmars-d-learn

On 2017-12-18 08:55, Andrey wrote:

Hello!
I have a question about creating native GUI applications for Windows 7 
or/and Windows 10.
I know that exist DWT, DlangUI and other... But I'm interesting in 
native GUI. If it will be C++ then I would use WinAPI from SDK.


DWT _is_ a native GUI, it uses the WinAPI.

--
/Jacob Carlborg


Re: Clarity about extern(Windows)/extern(System)

2017-12-18 Thread Mike Parker via Digitalmars-d-learn

On Monday, 18 December 2017 at 10:52:22 UTC, Kagamin wrote:

On Sunday, 17 December 2017 at 13:36:15 UTC, Mike Parker wrote:
My limited testing on a 64-bit Linux VM shows no problems when 
binding a C function as extern(C) or extern(Windows), and the 
disassembly looks the same.


64-bit ABI fixed calling convention proliferation, only one cc 
is used there.


What about extern(Windows) on 32-bit Posix?


Re: Passing anonymous enums as function parameters

2017-12-18 Thread Jacob Carlborg via Digitalmars-d-learn

On 2017-12-17 20:45, Jonathan M Davis wrote:


That's pretty much just declaring manifest constants with braces so that you
don't repeat the keyword enum a bunch of times.


Anonymous enum is what the spec calls it and was available before 
manifest constants.


--
/Jacob Carlborg


Re: weird exception on windows

2017-12-18 Thread Szabo Bogdan via Digitalmars-d-learn
On Saturday, 16 December 2017 at 12:01:49 UTC, Steven 
Schveighoffer wrote:

On 12/16/17 5:12 AM, bauss wrote:
On Saturday, 16 December 2017 at 08:07:30 UTC, Szabo Bogdan 
wrote:
On Friday, 15 December 2017 at 21:56:48 UTC, Steven 
Schveighoffer wrote:

On 12/15/17 10:08 AM, Kagamin wrote:

Maybe this https://issues.dlang.org/show_bug.cgi?id=18084


Thanks for looking into this. I created a PR to fix.

Szabo, can you please try with this patch and see if it 
fixes your issue?


https://github.com/dlang/phobos/pull/5932

-Steve


I have installed DMD 2.77.1 and I can not find the patched 
file in the phobos folder... should I try this by building 
the compiler?


It seams that I can not build phobos without compiling dmd.. 
or maybe I don't know how...


Just go and do the changes manually in your local phobos 
folder, wherever you have DMD installed, since you can't build 
phobos or dmd.


Yes, this won't get into the release for a while. So please do 
this manually (just copy the file changed by the pull over the 
existing one).


It's something that doesn't need to be compiled into the phobos 
library, as it's a misrepresentation of the actual object when 
you compile with unittests, so there is no reason to recompile 
phobos.


-Steve


I'm actually a linux and a mac user... this issue happens on a 
windows ci machine at work. I tried to update the file and 
compile phobos with that change, and I don't know how to make it 
work...


`
C:\D\dmd2\src\phobos>make -f win64.mak
cd etc\c\zlib
make -f win64.mak MODEL=64 zlib64.lib "CC=\"\Program Files 
(x86)\Microsoft Visual Studio 10.0\VC\bin\amd64\cl""\"" 
"LIB=\"\Program Files (x86)\Microsoft Visual Studio 
10.0\VC\bin\amd64\lib""\"" "VCDIR=\Program Files (x86)\Microsoft 
Visual Studio 10.0\VC"
"\Program Files (x86)\Microsoft Visual Studio 
10.0\VC\bin\amd64\cl" /c /O2 /nologo /I"\Program Files 
(x86)\Microsoft Visual Studio 10.0\VC\INCLUDE" /Zl adler32.c
Error: '\Program Files (x86)\Microsoft Visual Studio 
10.0\VC\bin\amd64\cl' not found

`

I don't know where I can find a 64bit toolchain for vs2010... I 
was expecting that dmd uses a newer compiler on windows...


I guess that the best approach for me is to wait the next beta 
release of dmd and try it then...


Thanks for the support!



Re: Write native GUI applications for Windows

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

On Monday, 18 December 2017 at 10:08:13 UTC, Andrey wrote:
Is core.sys.windows.windows equals fully to C WinApi, do you 
know?


Should be enough for most things.


Re: Array Template

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

On Saturday, 16 December 2017 at 14:14:28 UTC, Vino wrote:


Yes, will give a try.

From,
Vino.B



well, this sort of gets there ;-)

// -
module test;

import std.stdio;
import std.variant;
import std.typecons;
import std.conv;
import std.string;

void main()
{
Variant[] arr;

auto x = tuple(5, "hello", 4.3);
arr ~= cast(Variant)x;

auto y = tuple("hello", 4.3);
arr ~= cast(Variant)y;

auto z = tuple("hello", "world", 1, 2, 3, 5.5);
arr ~= cast(Variant)z;

int i = 0;
foreach(elem; arr)
{
writeln(
"arr[", i, "] values are : ",
to!(string)((to!(string)(elem))
[( indexOf( to!(string)(elem), ")" ) + 
2)..($-1)]) );

i++;
}

}
// -


Re: Clarity about extern(Windows)/extern(System)

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

On Sunday, 17 December 2017 at 13:36:15 UTC, Mike Parker wrote:
My limited testing on a 64-bit Linux VM shows no problems when 
binding a C function as extern(C) or extern(Windows), and the 
disassembly looks the same.


64-bit ABI fixed calling convention proliferation, only one cc is 
used there.


Re: Fold in Parallelism

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

On Sunday, 17 December 2017 at 20:00:53 UTC, Ali Çehreli wrote:

On 12/17/2017 08:11 AM, Vino wrote:

>   As per the document form std.parallelism it states that we
can use
> taskPool.reduce so can we use the same for fold
(taskPool.fold) as
> basically both are same with slight variation on seed values,
if
> possible can can we define the same in the below lines

fold has only been added to std.algorithm. Opened an 
enhancement request:


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

Ali


Hi Ali,

  Thank you very much, may we know if possible as to when this 
would be added.


From,
Vino.B


Re: Write native GUI applications for Windows

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

On Monday, 18 December 2017 at 09:45:38 UTC, Mike Parker wrote:

You can use the C Windows API out of the box:


Aaa, excelent! I always thought that first one should port winapi 
to D and then use it...


Is core.sys.windows.windows equals fully to C WinApi, do you know?


Re: Write native GUI applications for Windows

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

On Monday, 18 December 2017 at 08:49:51 UTC, Binghoo Dang wrote:
You can use libuid which can be found here 
https://code.dlang.org/packages/libuid.


It wrapped the native os gui for d, and it's cross-platform.


Nice...
But I want to use WinApi. Is it possible? Or what one should do 
first to make it possible?


Re: Write native GUI applications for Windows

2017-12-18 Thread Mike Parker via Digitalmars-d-learn

On Monday, 18 December 2017 at 07:55:25 UTC, Andrey wrote:

Hello!
I have a question about creating native GUI applications for 
Windows 7 or/and Windows 10.
I know that exist DWT, DlangUI and other... But I'm interesting 
in native GUI. If it will be C++ then I would use WinAPI from 
SDK.
And what about D? What should I do? Make some kind of wrapper 
above C WinApi?


You can use the C Windows API out of the box:

import core.sys.windows.windows;

// And away you go

I also know that on GitHub exists such wrapper 
(https://github.com/AndrejMitrovic/DWinProgramming) but it is 
old - last commit was 4 years ago.




The purpose of that repository was to port Petzold's examples to 
D. The Win32 API bindings (it's not a wrapper) were included to 
make building easier. I'm pretty sure somebody else set up a 
github mirror of the original DSource.org repository and Andrej 
simply copied it into his directory tree under the WindowsAPI 
directory. Meaning, I don't think the purpose of DWinProgramming 
was ever to actually host Windows bindings.


Regardless, third-party bindings are no longer necessary. All the 
examples in that repository should work (perhaps with minor 
changes) if you replace the win32.* imports with 
core.sys.windows. For example, the HelloMsg sample in the Chapter 
01 folder could use a couple f changes. toUTF16z is now part of 
std.utf, so no need for a custom implementation. And the versions 
of Runtime.initialize/terminate that take a delegate are 
deprecated. So this is what it should look like now:


module HelloMsg;

import core.runtime;
import std.utf;

import core.sys.windows.windows;

extern (Windows)
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR 
lpCmdLine, int iCmdShow)

{
int result;
try
{
Runtime.initialize();
result = myWinMain(hInstance, hPrevInstance, lpCmdLine, 
iCmdShow);

Runtime.terminate();
}
catch (Throwable o)
{
MessageBox(null, o.toString().toUTF16z, "Error", MB_OK | 
MB_ICONEXCLAMATION);

result = 0;
}

return result;
}

int myWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR 
lpCmdLine, int iCmdShow)

{
MessageBox(NULL, "Hello, Windows!", "Your Application", 0);
return 0;
}

On the other hand, you can dispense with the WinMain nonsense 
just do this:


import core.runtime;
import std.utf;

import core.sys.windows.windows;

void main()
{
MessageBox(null, "Hello, Windows!", "Your Application", 0);
}

Then compile with this to the same behavior as WinMain (i.e. no 
console window attached to the program):


dmd -L/SUBSYSTEM:windows HelloMsg.d

Or, when using the MS linker:

dmd -L/SUBSYSTEM:windows -L/ENTRY:mainCRTStartup -m64 HelloMsg.d 
user32.lib


Replace -m64 with -m32mscoff for 32-bit COFF output. Also note 
that when using the MS linker, you have to explicitly link with 
user32.lib. The same is true for the original WinMain version.






Re: How to pack a struct to a ubyte[] in a more "The D way" style ?

2017-12-18 Thread Binghoo Dang via Digitalmars-d-learn

hi Davis,

I read the std.bitmanip, and I tried to test the code like below:

```
import std.stdio;
import std.array;
import std.bitmanip;
void main(string[] args)
{
align(1) struct c {
ushort c1;
uint c2;
//ubyte[8] c3;
}
ubyte[] buffer;
auto ap = appender();
uint a = 0x11223344;
ushort b = 0x6677;
ap.append!uint(a);
ap.append!ushort(b);

c cobj;
cobj.c1 = 0xEEFF;
cobj.c2 = 0xDEADBEAF;
//cobj.c3 = [0x12, 0x34, 0x56, 0x78];
ap.append(cobj);

ubyte[3] d = [0xAA, 0xBB, 0xCC];
ap.append(d);

foreach(e; buffer) {
writef("%02X ", e);
}
}
```
For compiling this code, I got error like this

onlineapp.d(22): Error: template std.bitmanip.append cannot 
deduce function from >argument types !()(RefAppender!(ubyte[]), 
c), candidates are:
/dlang/dmd/linux/bin64/../../src/phobos/std/bitmanip.d(3623):
   std.bitmanip.append(T, Endian endianness = Endian.bigEndian, 
R)(R range, T value) >if (canSwapEndianness!T && 
isOutputRange!(R, ubyte))
onlineapp.d(25): Error: template std.bitmanip.append cannot 
deduce function from >argument types !()(RefAppender!(ubyte[]), 
ubyte[3]), candidates are:
/dlang/dmd/linux/bin64/../../src/phobos/std/bitmanip.d(3623):
   std.bitmanip.append(T, Endian endianness = Endian.bigEndian, 
R)(R range, T value) >if (canSwapEndianness!T && 
isOutputRange!(R, ubyte))


It seems that the appending is just allow using the fundamental 
types like uint, ushort, it does not support struct, and can't 
support dynamic array too. As the hardware protocol is a 
dynamic-length style, so I also need to support append array or 
another buffer directly.


It seems that I can't get the point how to using the bitmanip to 
do the packing I need, and also I have no idea what the unpacking 
will look like.


Thanks!


Re: Write native GUI applications for Windows

2017-12-18 Thread Binghoo Dang via Digitalmars-d-learn

On Monday, 18 December 2017 at 07:55:25 UTC, Andrey wrote:

Hello!
I have a question about creating native GUI applications for 
Windows 7 or/and Windows 10.
I know that exist DWT, DlangUI and other... But I'm interesting 
in native GUI. If it will be C++ then I would use WinAPI from 
SDK.
And what about D? What should I do? Make some kind of wrapper 
above C WinApi?
I also know that on GitHub exists such wrapper 
(https://github.com/AndrejMitrovic/DWinProgramming) but it is 
old - last commit was 4 years ago.


Could you help me?


You can use libuid which can be found here 
https://code.dlang.org/packages/libuid.


It wrapped the native os gui for d, and it's cross-platform.


Re: How to debug GC leak

2017-12-18 Thread Andrew Benton via Digitalmars-d-learn

On Monday, 18 December 2017 at 07:03:14 UTC, Andrew Benton wrote:

[snip]


Looking at dmd's gc profile, it looks like only 
std.array.Appender!string has allocated enough to be the culprit. 
End program memory was 110MB and the Appender!string had 
allocated 127MB totaly with Appender!(Json[]) coming in second at 
5.1MB.


Write native GUI applications for Windows

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

Hello!
I have a question about creating native GUI applications for 
Windows 7 or/and Windows 10.
I know that exist DWT, DlangUI and other... But I'm interesting 
in native GUI. If it will be C++ then I would use WinAPI from SDK.
And what about D? What should I do? Make some kind of wrapper 
above C WinApi?
I also know that on GitHub exists such wrapper 
(https://github.com/AndrejMitrovic/DWinProgramming) but it is old 
- last commit was 4 years ago.


Could you help me?