Re: Status of Win32 C++ interop

2015-09-08 Thread Benjamin Thaut via Digitalmars-d-learn

On Monday, 7 September 2015 at 19:30:44 UTC, drug wrote:

07.09.2015 21:37, Benjamin Thaut пишет:
snip


So far I haven't found a situation where I couldn't make it 
work the way
I wanted.  Its just some work to write the D headers for the 
C++ classes
and vise versa, because you have to duplicate everything once 
more. An
automated tool for this would be nice, but unfotunately there 
is

currently none.

Kind Regards
Benjamin Thaut


It's great. But isn't it based on your custom modifications of 
compiler and the others?


No, the compiler modifications are only for the Windows DLL 
support. All modifications I did to the c++ binding are already 
in 2.068


Re: What's the "right" way to do openmp-style parallelism?

2015-09-08 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn

On Tuesday, 8 September 2015 at 05:50:30 UTC, Russel Winder wrote:

void main() {
  immutable imax = 10;
  immutable jmax = 10;
  float[imax][jmax] x;
  foreach(int j; 1..jmax){
foreach(int i, ref item; parallel(x[j-1])){
  x[j][i] = complicatedFunction(i, item);
}
  }
}

(though sadly, this doesn't compile for a reason I can't fathom 
instantly)

Hmm. Shouldn't you instead parallel the outer loop?



Re: OSX prompt limit

2015-09-08 Thread Joel via Digitalmars-d-learn

On Friday, 4 September 2015 at 03:31:40 UTC, Adam D. Ruppe wrote:

On Friday, 4 September 2015 at 02:17:57 UTC, Joel wrote:
In Mac OS, when typing with readln etc. I can't use the cursor 
keys. Works in Windows though.


That's normal, line editing on Unix terminals is a kinda 
advanced library feature. The most common lib to do it, GNU 
readline, is actually a big thing that pushed the GPL because 
of how useful it was and it happened to use that license.


I wrote one too though it is a bit bulky.
https://github.com/adamdruppe/arsd/blob/master/terminal.d

import terminal;
void main() {
   auto terminal = Terminal(ConsoleOutputMode.linear);
   auto line = terminal.getline("your prompt: ");
   terminal.writeln("You wrote: ", line);
}

compile:

dmd yourapp.d terminal.d


I get these errors with terminal.d (on OSX):

Joels-MacBook-Pro:small joelcnz$ rdmd term.d
arsd/terminal.d(1268): Error: undefined identifier 'SIGWINCH'
arsd/terminal.d(1381): Error: undefined identifier 'SIGWINCH'
Joels-MacBook-Pro:small joelcnz$

Note: I've got term.d as the main file, I've got terminal.d in 
arsd folder


I've put up an issue on your github site.



Re: Regression?

2015-09-08 Thread FreeSlave via Digitalmars-d-learn
On Tuesday, 8 September 2015 at 04:04:16 UTC, Sebastiaan Koppe 
wrote:

Fixed it by changing into:

```
import std.conv : text;
	string json = 
File("../languages.json","r").byLineCopy().joiner.text;

auto ls = json.parseJSON();
```


Why would you read file by line and then merge all into one 
string? You end up with reading the whole file (well, getting rid 
of line ends) anyway, so probably the more efficient solution 
would be just read the whole file at once with std.file.read and 
cast to string.


Re: Why 1f.iota(100f).array returns double[] not float[]?

2015-09-08 Thread Ali Çehreli via Digitalmars-d-learn

On 09/08/2015 12:00 AM, drug wrote:

import std.array : array;
import std.range : iota;

pragma(msg, typeof(iota(1f, 100f).array)); // why double[] not float[]?

void main()
{
}


It is probably because the type of floating point literals like 1.0 is 
double. Probably there is a 1.0 in iota's implementation, converting the 
element type to double according to rule number 2 here:


  http://dlang.org/type.html#usual-arithmetic-conversions

Yep, here it is:


https://github.com/D-Programming-Language/phobos/blob/master/std/range/package.d#L4630

auto iota(B, E)(B begin, E end)
if (isFloatingPoint!(CommonType!(B, E)))
{
return iota(begin, end, 1.0);
}

Although any such expression can become double easily, I think the 
literal should be 1.0f in this case.


Ali



Why 1f.iota(100f).array returns double[] not float[]?

2015-09-08 Thread drug via Digitalmars-d-learn

import std.array : array;
import std.range : iota;

pragma(msg, typeof(iota(1f, 100f).array)); // why double[] not float[]?

void main()
{
}


What is "FilterResult" type?

2015-09-08 Thread Bahman Movaqar via Digitalmars-d-learn
From what I can gather the output of `std.algorithm.iteration : 
filter` is a `FilterResult` type.

I need a bit of help dealing with this type:
  1. Why this type is there in the first place instead of simply 
using the type of input range?
  2. Where is the documentation for this type?  The documentation 
always uses `auto` for `filter` return values.

  3. How can I convert this type back into a range?

Thanks.


Re: What is "FilterResult" type?

2015-09-08 Thread cym13 via Digitalmars-d-learn
On Tuesday, 8 September 2015 at 09:48:35 UTC, Bahman Movaqar 
wrote:
From what I can gather the output of `std.algorithm.iteration : 
filter` is a `FilterResult` type.

I need a bit of help dealing with this type:
  1. Why this type is there in the first place instead of 
simply using the type of input range?
  2. Where is the documentation for this type?  The 
documentation always uses `auto` for `filter` return values.

  3. How can I convert this type back into a range?

Thanks.


Filter is a template and returns a FilterResult range which is 
used to lazily compute the result. This behaviour is the same for 
map and the majority of functions in std.algorithm.


It is an input range really (ie: it has front, popFront and 
empty). You can chain it just like any other range with other 
functions and normally don't have to know the exact type (which 
would be complicated since it is a templated thing).


To store it in a variable if you don't know the exact type you 
can use auto to use type deduction. If you need the type (for a 
template for example) you can then use typeof.


Example:

void main() {
import std.stdio: writeln;
import std.algorithm: filter, map;

int[] arr = [1, 2, 3, 4, 5];
auto result = arr.filter!(x => x%2); // filter out even 
numbers


result.writeln; // Writes [1, 3, 5];

// What is the type of result?
typeid(result).writeln;
//-> temporary.main.FilterResult!(__lambda2, 
int[]).FilterResult


// Map takes a range, this works because result is one.
auto result2 = result.map!(x => 2*x);
//-> temporary.main.MapResult!(__lambda3, 
FilterResult!(__lambda2,int[])).MapResult


// Here is the reason you don't want to type them yourself. 
auto FTW!
typeid(result).writeln; // main.FilterResult!(__lambda2, 
int[]).FilterResult


// You can put it back in an array too
import std.array: array;
int[] resultArr = result2.array;
}

If you want more precise documentation the best is to look to the 
source code (/usr/include/dlang/dmd/std/algorithm/iteration if 
you are on linux).




Re: What is "FilterResult" type?

2015-09-08 Thread Edwin van Leeuwen via Digitalmars-d-learn
On Tuesday, 8 September 2015 at 11:08:59 UTC, Bahman Movaqar 
wrote:

On Tuesday, 8 September 2015 at 10:08:03 UTC, cym13 wrote:
Filter is a template and returns a FilterResult range which is 
used to lazily compute the result. This behaviour is the same 
for map and the majority of functions in std.algorithm.


You can also use .array to (greedily) evaluate the results, which 
(for filter) will return a range of the same type as went in:


void main()
{
import std.array : array;
int[] arr = [1, 2, 3, 4, 5];
int[] result = arr.filter!(x => x%2).array;
}


Re: Status of Win32 C++ interop

2015-09-08 Thread drug via Digitalmars-d-learn

On 08.09.2015 11:45, Benjamin Thaut wrote:

On Monday, 7 September 2015 at 19:30:44 UTC, drug wrote:

07.09.2015 21:37, Benjamin Thaut пишет:
snip


So far I haven't found a situation where I couldn't make it work the way
I wanted.  Its just some work to write the D headers for the C++ classes
and vise versa, because you have to duplicate everything once more. An
automated tool for this would be nice, but unfotunately there is
currently none.

Kind Regards
Benjamin Thaut


It's great. But isn't it based on your custom modifications of
compiler and the others?


No, the compiler modifications are only for the Windows DLL support. All
modifications I did to the c++ binding are already in 2.068

It's good. Thank you!


Re: What is "FilterResult" type?

2015-09-08 Thread Bahman Movaqar via Digitalmars-d-learn

On Tuesday, 8 September 2015 at 10:08:03 UTC, cym13 wrote:
Filter is a template and returns a FilterResult range which is 
used to lazily compute the result. This behaviour is the same 
for map and the majority of functions in std.algorithm.


Ah...now it makes sense why use a proxy to the results.

It is an input range really (ie: it has front, popFront and 
empty). You can chain it just like any other range with other 
functions and normally don't have to know the exact type (which 
would be complicated since it is a templated thing).


I agree.  Some types are better left unspecified; like some 300+ 
characters long type signatures one would get from a generic 
Scala function :-D


However, I have made this a strict practice of mine to specify 
the full signature of my public API.  I suppose, if I want to be 
pedantic, I have to realise the lazy value first and pass the 
resulting array out.  Is this correct?


To store it in a variable if you don't know the exact type you 
can use auto to use type deduction.


True.


Example:


Great.  The usage is crystal clear to me now.

If you want more precise documentation the best is to look to 
the source code (/usr/include/dlang/dmd/std/algorithm/iteration 
if you are on linux).


Thanks for the help and pointers.



Re: Why 1f.iota(100f).array returns double[] not float[]?

2015-09-08 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn

On Tuesday, 8 September 2015 at 07:17:01 UTC, Ali Çehreli wrote:

https://github.com/D-Programming-Language/phobos/blob/master/std/range/package.d#L4630

auto iota(B, E)(B begin, E end)
if (isFloatingPoint!(CommonType!(B, E)))
{
return iota(begin, end, 1.0);
}


Such kind of stuff would better be written as

auto iota(B, E)(B begin, E end)
{
return iota(begin, end, cast(CommonType!(B, E))1.0);
}

this doesn't need a constraint anymore, or maybe use

if(isNumeric!(CommonType!(B, E)))

I tend to use the above kind of cast often, because I like to 
work with ubyte or ushort, and every f***ing number literal 
changes the type to uint :-/


Re: Regression?

2015-09-08 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, September 08, 2015 07:12:50 FreeSlave via Digitalmars-d-learn wrote:
> On Tuesday, 8 September 2015 at 04:04:16 UTC, Sebastiaan Koppe
> wrote:
> > Fixed it by changing into:
> >
> > ```
> > import std.conv : text;
> > string json =
> > File("../languages.json","r").byLineCopy().joiner.text;
> > auto ls = json.parseJSON();
> > ```
>
> Why would you read file by line and then merge all into one
> string? You end up with reading the whole file (well, getting rid
> of line ends) anyway, so probably the more efficient solution
> would be just read the whole file at once with std.file.read and
> cast to string.

Or just use std.file.readText:

http://dlang.org/phobos/std_file.html#readText

- Jonathan M Davis



Re: Concurency wtf?

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

On 9/8/15 2:54 PM, Prudence wrote:


I can't seem to receive certain messages, my code is very simple and it
all works except for receiving:


in one thread I do


locate("MyMonitor").send(cast(shared)pt);


You are casting to shared here.



which sends the message(pt is a windows POINT structure).

In the MyMonitor spawned thread, I have


 while (true)
 {
 POINT y;
 receiveTimeout(100.msecs,
 (POINT p)


But not receiving a shared(POINT) here.

So the types are different.

What is a POINT struct? If it's simple POD (with no pointers), then you 
don't need the shared type modifier.


-Steve


Re: Is D suitable for my latest project?

2015-09-08 Thread chris stevens via Digitalmars-d-learn

On Sunday, 6 September 2015 at 14:45:45 UTC, BBasile wrote:
You have Object.factory for this. You can also use a custom 
factory based on string comparison. (with some: static 
if(condition) return new This; else static if(otherCondition) 
return new That; etc).


I just had a look at Object.factory and this isn't actually what 
I wanted. I was looking for something that would allow me to 
create new (previously undefined) classes in D at runtime that I 
could then use with Object.factory to create instances of.


I think I can do this with Variants and dynamic, is this 
possible? Or is there another way?


Re: Implicit conversion with ctor like C++

2015-09-08 Thread Pierre via Digitalmars-d-learn

I made a mistake it's more like:

 //Sample class
 class CClass
 {
this(string MyValue){...}
 }

 //Called function
 void MyFunction(CClass MyClass){}

 void main()
 {
   MyFunction("Hello World!"); //Failed : MyFunction not  
callable...

 }



Re: Implicit conversion with ctor like C++

2015-09-08 Thread Meta via Digitalmars-d-learn

On Tuesday, 8 September 2015 at 19:23:47 UTC, Pierre wrote:

Hi everybody,

I would like to use implicit conversion like this:

//Sample class
class MyClass
{
   this(string MyValue){...}
}

//Called function
void MyFunction(Foo MyFoo){}

void main()
{
  MyFunction("Hello World!"); //Failed : MyFunction not 
callable...

}

I saw in forum this is OK because D doesn't do implicit 
conversion with ctor like C++

But how can I do ? May I use alias ?

Thank you for your attention.


No, as far as I know, D does not support implicit construction of 
classes or structs. There is *some* implicit conversion allowed, 
but in the opposite direction.


struct Test
{
string s;
alias s this;

//Necessary for nice construction syntax
this(string s) { this.s = s; }
}

void foo(string s)
{
writeln(s);
}

void main()
{
Test t = "asdf";
foo(t); //Prints "asdf"
}

So with alias this, you can pass a Test to a function expecting a 
string, but not vice-versa.


Re: Implicit conversion with ctor like C++

2015-09-08 Thread Pierre via Digitalmars-d-learn

OK that's very clear thank you for the answer.


Re: What is "FilterResult" type?

2015-09-08 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, September 08, 2015 11:08:57 Bahman Movaqar via Digitalmars-d-learn 
wrote:
> However, I have made this a strict practice of mine to specify
> the full signature of my public API.

If your API returns ranges, that's general not only bad practice but
arguably impossible. Most range-based functions purposefully return
Voldemort types (the type is declared inside of the function, meaning that
you cannot name it). FilterResult really should be to, but I think that it's
not in order to work around a bug. Regardless, it's private and should never
be used explicitly.

If you want to put a range type in an API, you're forced to do stuff like

typeof(rangeFunc!someFunc(SomeOtherRange.init)) myFunc(int);

If you're returning a range, you should be returning auto. The documentation
should then say whether it's an input range, forward range, etc. - but you
should pretty much never be using range types explicitly. Your code will
become an unmaintainable, unreadable mess if you try. And really, it's
unnecessary. Simply having the documentation say what sort of range it's
returning is plenty. Exact types are unnecessary in this case and
counterproductive.

- Jonathan M Davis



Concurency wtf?

2015-09-08 Thread Prudence via Digitalmars-d-learn


I can't seem to receive certain messages, my code is very simple 
and it all works except for receiving:



in one thread I do


locate("MyMonitor").send(cast(shared)pt);

which sends the message(pt is a windows POINT structure).

In the MyMonitor spawned thread, I have


while (true)
{
POINT y;
receiveTimeout(100.msecs,
(POINT p)
{
y = p;
}
);


Thread.sleep(100.msecs);
continue;
}


Note that everything works except the matching in receiveTimeout. 
(I've tired various things and simplifications to no avail).


I can send simple types like int and bool. e.g., sending a 
literal works fine. My guess is the shared is causing problems 
but I've tried all common sense combinations. But I have to send 
shared, else send complains about sending unshared types.


Of course, the great thing is, all examples use literals and 
hence not real world examples(isn't that nice?).


Please don't ask me to provide source. The issue has nothing to 
do with the other code but specifically the TYPE that is being 
sent. Works for some types and not others. It is almost surely 
due to the shared issue, any ideas?





Re: What is "FilterResult" type?

2015-09-08 Thread Meta via Digitalmars-d-learn
On Tuesday, 8 September 2015 at 11:08:59 UTC, Bahman Movaqar 
wrote:
However, I have made this a strict practice of mine to specify 
the full signature of my public API.  I suppose, if I want to 
be pedantic, I have to realise the lazy value first and pass 
the resulting array out.  Is this correct?


If you _really_ want to specify the return type, you can import 
std.range.interfaces[1] and use the appropriate return type 
(e.g., InputRange!int, RandomAccessFinite!char, etc.) and then 
append a `.inputRangeObject` to the end of your range chain.


Ex:

import std.algorithm;
import std.range;

InputRange!int doRangeyThings(R)(R r)
if (isInputRange!R)
{
return r.filter!(x => !(x & 1))
.map!(x => x * 2)
.inputRangeObject;
}

void main()
{
auto n = [1, 2, 3, 4];
auto m = n.doRangeyThings();
assert(is(typeof(m) == InputRange!int));
assert(m.equal([4, 8]));
}

You should use this sparingly, however. The types in 
std.range.interfaces are interfaces that allow you to combine 
ranges with runtime polymorphism, and you have to pay the 
corresponding price for that, namely, you'll be hitting the GC 
and the virtual functions entail a speed hit.





1. http://dlang.org/phobos/std_range_interfaces.html


Implicit conversion with ctor like C++

2015-09-08 Thread Pierre via Digitalmars-d-learn

Hi everybody,

I would like to use implicit conversion like this:

//Sample class
class MyClass
{
   this(string MyValue){...}
}

//Called function
void MyFunction(Foo MyFoo){}

void main()
{
  MyFunction("Hello World!"); //Failed : MyFunction not 
callable...

}

I saw in forum this is OK because D doesn't do implicit 
conversion with ctor like C++

But how can I do ? May I use alias ?

Thank you for your attention.




Re: Is D suitable for my latest project?

2015-09-08 Thread chris stevens via Digitalmars-d-learn

On Monday, 7 September 2015 at 07:57:07 UTC, Kagamin wrote:
On Sunday, 6 September 2015 at 15:15:03 UTC, chris stevens 
wrote:
I guess you're right it wouldn't be too difficult to do it all 
using strings. The code generation I'd done before in c# I'd 
used some 3rd person library where you build up an object 
model rather than using strings.


Maybe with dparse you can construct an AST and later convert it 
to string.


Thanks for the reply Kagamin, just had a quick look at dparse and 
not sure how I could use it in the way you describe. Any examples 
of this?


Re: Is D suitable for my latest project?

2015-09-08 Thread BBasile via Digitalmars-d-learn

On Tuesday, 8 September 2015 at 19:30:16 UTC, chris stevens wrote:

On Sunday, 6 September 2015 at 14:45:45 UTC, BBasile wrote:
You have Object.factory for this. You can also use a custom 
factory based on string comparison. (with some: static 
if(condition) return new This; else static if(otherCondition) 
return new That; etc).


I just had a look at Object.factory and this isn't actually 
what I wanted. I was looking for something that would allow me 
to create new (previously undefined) classes in D at runtime 
that I could then use with Object.factory to create instances 
of.


I think I can do this with Variants and dynamic, is this 
possible? Or is there another way?


No, it's not possible with variants. What you want to do is 
actually complex and won't be solved here.


To create a new class instance, the runtime needs the TypeInfo 
class for the class type. Why ? because for example if in a class 
declaration you declare an int initially equal to 1, the TypeInfo 
class provide the memory layout that matches to this initital 
value.


For example this is how class instances are creates in D:

https://github.com/D-Programming-Language/druntime/blob/master/src/rt/lifetime.d#L71

---
extern (C) Object _d_newclass(const ClassInfo ci)
---

without the 'ClassInfo' parameter, you can't get the initial 
state of a class.

This is what the runtime needs to create a class instance.


Re: Is D suitable for my latest project?

2015-09-08 Thread wobbles via Digitalmars-d-learn

On Tuesday, 8 September 2015 at 19:30:16 UTC, chris stevens wrote:

On Sunday, 6 September 2015 at 14:45:45 UTC, BBasile wrote:
You have Object.factory for this. You can also use a custom 
factory based on string comparison. (with some: static 
if(condition) return new This; else static if(otherCondition) 
return new That; etc).


I just had a look at Object.factory and this isn't actually 
what I wanted. I was looking for something that would allow me 
to create new (previously undefined) classes in D at runtime 
that I could then use with Object.factory to create instances 
of.


I think I can do this with Variants and dynamic, is this 
possible? Or is there another way?


"Previously undefined". As far as I know, this is impossible in 
D. Thr compiler has to know how much memory to allocate/request 
and it has to know that at compiletime (else it wouldn't be the 
compiler!)


This functionality in Java/C# is possible because it's running on 
a vm that allows special instructions to make the vm compile and 
make available a class dynamically (and by extension, slowly)


Re: Status of Win32 C++ interop

2015-09-08 Thread Kagamin via Digitalmars-d-learn

On Tuesday, 8 September 2015 at 12:56:00 UTC, Laeeth Isharc wrote:
How does it work when external APIs expect objects from the C++ 
standard library?  strings, and so on?  How about funny pointer 
types?  shared_ptr  etc?  std::vector, std::list?


No, in current state nothing smart is supported. See 
https://issues.dlang.org/show_bug.cgi?id=14086


Re: OSX prompt limit

2015-09-08 Thread via Digitalmars-d-learn

Or just take it from the man page:

https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man3/signal.3.html


Re: Why 1f.iota(100f).array returns double[] not float[]?

2015-09-08 Thread Meta via Digitalmars-d-learn
On Tuesday, 8 September 2015 at 12:28:07 UTC, Dominikus Dittes 
Scherkl wrote:

On Tuesday, 8 September 2015 at 07:17:01 UTC, Ali Çehreli wrote:

https://github.com/D-Programming-Language/phobos/blob/master/std/range/package.d#L4630

auto iota(B, E)(B begin, E end)
if (isFloatingPoint!(CommonType!(B, E)))
{
return iota(begin, end, 1.0);
}


Such kind of stuff would better be written as

auto iota(B, E)(B begin, E end)
{
return iota(begin, end, cast(CommonType!(B, E))1.0);
}

this doesn't need a constraint anymore, or maybe use

if(isNumeric!(CommonType!(B, E)))

I tend to use the above kind of cast often, because I like to 
work with ubyte or ushort, and every f***ing number literal 
changes the type to uint :-/


Even better, use D's universal construction feature.

auto iota(B, E)(B begin, E end)
{
return iota(begin, end, CommonType!(B, E)(1.0));
}


Re: OSX prompt limit

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

On 9/8/15 9:20 AM, Adam D. Ruppe wrote:

On Tuesday, 8 September 2015 at 13:17:31 UTC, Ola Fosheim Grøstad wrote:

Or just take it from the man page:

https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man3/signal.3.html



ah excellent. My web search came up with
https://developer.apple.com/library/ios/documentation/System/Conceptual/ManPages_iPhoneOS/man2/sigaction.2.html
which didn't give the value!


That's because it's iOS. You have to be careful with apple 
documentation, they look the same for both MacOS and ios, but often they 
are slightly different.


-Steve


Re: Why 1f.iota(100f).array returns double[] not float[]?

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

On 9/8/15 3:17 AM, Ali Çehreli wrote:

On 09/08/2015 12:00 AM, drug wrote:

import std.array : array;
import std.range : iota;

pragma(msg, typeof(iota(1f, 100f).array)); // why double[] not float[]?

void main()
{
}


It is probably because the type of floating point literals like 1.0 is
double. Probably there is a 1.0 in iota's implementation, converting the
element type to double according to rule number 2 here:

   http://dlang.org/type.html#usual-arithmetic-conversions

Yep, here it is:


https://github.com/D-Programming-Language/phobos/blob/master/std/range/package.d#L4630


auto iota(B, E)(B begin, E end)
if (isFloatingPoint!(CommonType!(B, E)))
{
 return iota(begin, end, 1.0);
}

Although any such expression can become double easily, I think the
literal should be 1.0f in this case.


I think this warrants a bug report, iota with only floats as parameters 
should result in floats.


-Steve


Re: OSX prompt limit

2015-09-08 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 8 September 2015 at 13:17:31 UTC, Ola Fosheim Grøstad 
wrote:

Or just take it from the man page:

https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man3/signal.3.html


ah excellent. My web search came up with 
https://developer.apple.com/library/ios/documentation/System/Conceptual/ManPages_iPhoneOS/man2/sigaction.2.html which didn't give the value!



anyway the git is updated now


Re: Status of Win32 C++ interop

2015-09-08 Thread Laeeth Isharc via Digitalmars-d-learn

On Monday, 7 September 2015 at 18:37:49 UTC, Benjamin Thaut wrote:
On Friday, 4 September 2015 at 16:19:49 UTC, Laeeth Isharc 
wrote:

Hi Benjamin

Would you be able to give a little more colour on what the 
limits are of interoperability for C++ with DMD master or 
release ?  As I understand it destructors and constructors 
don't work, and obviously it will get tricky passing 
structures and classes from C++ libraries not ported to D.



So, things that work really well are classes...
So far I haven't found a situation where I couldn't make it 
work the way I wanted.  Its just some work to write the D 
headers for the C++ classes and vise versa, because you have to 
duplicate everything once more. An automated tool for this 
would be nice, but unfotunately there is currently none.



This is really very clear and helpful, and I appreciate your 
taking the time.  I will place it on the wiki if that's okay.


Library support is surely one of the largest impediments to the 
adoption of D, and we ought to place some emphasis on updating 
the documentation here:

http://dlang.org/cpp_interface.html

How does it work when external APIs expect objects from the C++ 
standard library?  strings, and so on?  How about funny pointer 
types?  shared_ptr  etc?  std::vector, std::list?


Here is one C++ library used by many in finance (at least as a 
backup).  I think there might be a decent amount of value in 
making this usable from D.  (Trying to put my own interests 
aside!)  Paging Andy Smith ?


http://quantlib.org/reference/_bermudan_swaption_8cpp-example.html

Are there any well-known C++ libraries that you have interfaced 
to ?  Could you give some examples of how long it takes ?


Would you be able to drop me an email about something else?  No 
contact info on your blog, but my domain is 
kaleidicassociates.com and my user id is laeeth@



Laeeth.


Re: OSX prompt limit

2015-09-08 Thread via Digitalmars-d-learn

On Tuesday, 8 September 2015 at 13:02:35 UTC, Adam D. Ruppe wrote:

On Tuesday, 8 September 2015 at 06:24:12 UTC, Joel wrote:

arsd/terminal.d(1268): Error: undefined identifier 'SIGWINCH'



There's a missing value in the signal header for OSX !

Could you run this little C program for me on your Mac and let 
me know the output?


---
#include
#include

int main() {
printf("%d\n", SIGWINCH);
}
---


I can't find the numeric value online either and I don't have a 
mac myself to check the headers :( ugh.


 28SIGWINCH discard signal   Window size change



Re: How to partially forward properties of struct array member to struct (disable length property) ?

2015-09-08 Thread Kenji Hara via Digitalmars-d-learn

On Sunday, 6 September 2015 at 10:12:58 UTC, ParticlePeter wrote:
In the end all that I want is "just" to disable access to 
array.length through vector and alias this array.


struct Vec(T, size_t n = 3)
{
T[n] data;

alias data this;

@disable @property size_t length() const;
}

void main()
{
Vec!int v;
v[0] = 1;   // ok
assert(v[0] == 1);  // ok
int n = v.length;   // error
}

- Kenji


Re: Are there any Phobos functions to check file permissions on Windows and Posix?

2015-09-08 Thread Jay Norwood via Digitalmars-d-learn

On Monday, 7 September 2015 at 15:48:56 UTC, BBasile wrote:
On Sunday, 6 September 2015 at 23:05:29 UTC, Jonathan M Davis 
For example you can retieve the flags: 
archive/readonly/hidden/system/indexable(?) and even if it 
looks writable or readable, the file won't be open at all 
because the ACL for the file don't include the current user 
account.


This guy enhanced the cross-platform fox toolkit capabilities.  
It would be worth looking at it if you intend to write something 
similar.


See the section 7. Superior provision of host OS facilities 
portably


http://tnfox.sourceforge.net/TnFOX/html/main.html



Win32 function vs delegate issues with api

2015-09-08 Thread Prudence via Digitalmars-d-learn

I have

hook = SetWindowsHookEx(WH_MOUSE, , NULL, ThreadID);   

Proc is the standard hook proc:

public extern (Windows) LRESULT Proc(int code, WPARAM wParam, 
LPARAM lParam)


I get a type mismatch because Proc is a delegate and 
SetWindowsHookEx expects a function. Making proc static works but 
not the behavior I want since all this stuff is wrapped in a 
class.


Is there any way to pass Proc to SetWindowsHookEx without issues 
of GB and such?




Error: function windows.winuser.SetWindowsHookExA (int, extern 
(Windows) int function(int, uint, int), void*, uint) is not 
callable using argument types (const(int), extern (Windows) int 
delegate(int code, uint wParam, int lParam), void*, uint)		


I could cast Proc to a function, obviously, but I'll loose the 
delegate behavior and create problems when I try to use this 
inside Proc?





Re: OSX prompt limit

2015-09-08 Thread Joel via Digitalmars-d-learn

On Tuesday, 8 September 2015 at 13:20:20 UTC, Adam D. Ruppe wrote:
On Tuesday, 8 September 2015 at 13:17:31 UTC, Ola Fosheim 
Grøstad wrote:

Or just take it from the man page:

https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man3/signal.3.html


ah excellent. My web search came up with 
https://developer.apple.com/library/ios/documentation/System/Conceptual/ManPages_iPhoneOS/man2/sigaction.2.html which didn't give the value!



anyway the git is updated now


Now I get the error:
object.Exception@terminal.d(2745): too narrow terminal to draw

It has a negative number in it.

Thanks for working on it.



Re: OSX prompt limit

2015-09-08 Thread via Digitalmars-d-learn
On Wed, Sep 09, 2015 at 12:05:52AM +, Joel via Digitalmars-d-learn wrote:
> Now I get the error:

What is your code calling the function? The prompt might
just be too long.



Re: OSX prompt limit

2015-09-08 Thread Joel via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 00:44:57 UTC, via 
Digitalmars-d-learn wrote:
On Wed, Sep 09, 2015 at 12:05:52AM +, Joel via 
Digitalmars-d-learn wrote:

Now I get the error:


What is your code calling the function? The prompt might just 
be too long.


import terminal;

void main() {
auto terminal = Terminal(ConsoleOutputType.linear); // I 
think I changed ConsoleOutputType from some thing else that 
didn't work

auto line = terminal.getline("your prompt: ");
terminal.writeln("You wrote: ", line);
}



Re: Regression?

2015-09-08 Thread Sebastiaan Koppe via Digitalmars-d-learn

On Tuesday, 8 September 2015 at 07:12:52 UTC, FreeSlave wrote:
On Tuesday, 8 September 2015 at 04:04:16 UTC, Sebastiaan Koppe 
wrote:

Fixed it by changing into:

```
import std.conv : text;
	string json = 
File("../languages.json","r").byLineCopy().joiner.text;

auto ls = json.parseJSON();
```


Why would you read file by line and then merge all into one 
string? You end up with reading the whole file (well, getting 
rid of line ends) anyway, so probably the more efficient 
solution would be just read the whole file at once with 
std.file.read and cast to string.


Thanks for your advice. But that is not what I asked for.

The question was, why doesn't this work anymore with the latest 
(2.068.0 and 2.068.1) compiler:


```
auto ls = 
File("../languages.json","r").byLineCopy().joiner.parseJSON();

```

It should. Right?


Re: Win32 function vs delegate issues with api

2015-09-08 Thread Rikki Cattermole via Digitalmars-d-learn

On 09/09/15 12:18 PM, Prudence wrote:

I have

hook = SetWindowsHookEx(WH_MOUSE, , NULL, ThreadID);

Proc is the standard hook proc:

public extern (Windows) LRESULT Proc(int code, WPARAM wParam, LPARAM
lParam)

I get a type mismatch because Proc is a delegate and SetWindowsHookEx
expects a function. Making proc static works but not the behavior I want
since all this stuff is wrapped in a class.

Is there any way to pass Proc to SetWindowsHookEx without issues of GB
and such?



Error: function windows.winuser.SetWindowsHookExA (int, extern (Windows)
int function(int, uint, int), void*, uint) is not callable using
argument types (const(int), extern (Windows) int delegate(int code, uint
wParam, int lParam), void*, uint)

I could cast Proc to a function, obviously, but I'll loose the delegate
behavior and create problems when I try to use this inside Proc?


You have the ability to store some user info along with the pointer. 
Store an integer. Use a global (private) array to map the integer to the 
actual delegate. Use a free function as the proc function.


Of course, that has some indirection thats to the lookup. You could if 
able to rewrite as the free-function and pass in the class as user data, 
you could be smart about it ;)


https://github.com/Devisualization/window/blob/master/platforms/win32/devisualization/window/window.d#L384
https://github.com/Devisualization/window/blob/master/platforms/win32/devisualization/window/window.d#L401


Re: Are there any Phobos functions to check file permissions on Windows and Posix?

2015-09-08 Thread Jesse Phillips via Digitalmars-d-learn

On Monday, 7 September 2015 at 15:48:56 UTC, BBasile wrote:
On Sunday, 6 September 2015 at 23:05:29 UTC, Jonathan M Davis 
wrote:
[...] which makes treating some of this stuff in a 
cross-platform fashion quite difficult.


And even more with ACLs that it could be:


Not to mention, Windows locks files that are open and the 
recommended way to handle that is to open the file and see if you 
get an error.





Re: OSX prompt limit

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

On Tuesday, 8 September 2015 at 06:24:12 UTC, Joel wrote:

arsd/terminal.d(1268): Error: undefined identifier 'SIGWINCH'



There's a missing value in the signal header for OSX !

Could you run this little C program for me on your Mac and let me 
know the output?


---
#include
#include

int main() {
printf("%d\n", SIGWINCH);
}
---


I can't find the numeric value online either and I don't have a 
mac myself to check the headers :( ugh.


Re: spawn X different workers & wait for results from all of them

2015-09-08 Thread Justin Whear via Digitalmars-d-learn
On Sat, 05 Sep 2015 12:21:33 +0200, Robert M. Münch wrote:

> My "pieceOfWork" is not the same. So I don't have the case: Do 4 time
> this 1thing. Instead, do 1 time these 4 things.

Ah, so you want to receive one each of various types?  Something like 
this might work (untested):

// These could be inferred using std.traits.ReturnType
alias ResultTypes = AliasSeq!(int, float, Baz);

bool received(T) = false;
bool receivedAll()
{
foreach (T; ResultTypes)
if (!received!T) return false;
return true;
}

while (!receivedAll)
{
receive(
(int x)   { received!int = true; /* other work... */ },
(float x) { received!float = true; /* other work... */ },
(Baz x)   { received!Baz = true; /* other work... */ }
);
}


Re: Windows Header consts

2015-09-08 Thread NX via Digitalmars-d-learn

On Tuesday, 8 September 2015 at 17:22:44 UTC, NX wrote:

 I have figure out


typo:
...I had to figure out...


Re: Windows Header consts

2015-09-08 Thread NX via Digitalmars-d-learn

On Monday, 7 September 2015 at 19:06:48 UTC, Prudence wrote:


It's called encapsulation.


Do you have any idea how much I struggled when I try to use enums 
in OpenTK library because they were "encapsulated" ?
Whenever I read OpenGL tutorials I have figure out which 
enum-name they used as container...


Re: What is "FilterResult" type?

2015-09-08 Thread cym13 via Digitalmars-d-learn
On Tuesday, 8 September 2015 at 11:08:59 UTC, Bahman Movaqar 
wrote:
However, I have made this a strict practice of mine to specify 
the full signature of my public API.  I suppose, if I want to 
be pedantic, I have to realise the lazy value first and pass 
the resulting array out.  Is this correct?


Yes, using an array will work here, but if you are designing a 
library then I'd prefer that you don't force me into being non 
lazy where I could be just because you want to have a clear type: 
laziness is a virtue, reducing possibilities isn't a great idea.


What I would do is a designated wrapper template which will give 
you a clear type while still being lazy: exactly what 
FilterResult and MapResult are.