Re: specifying an auto array type

2015-12-26 Thread Ali Çehreli via Digitalmars-d-learn

On 12/26/2015 09:45 PM, Jay Norwood wrote:

> This is getting kind of a long example,

There are issues with that code that make it hard for me to guess the 
intent.


> a way to have the Tuple array defined as auto instead of having to 
specify
> the types.  I tried using .array() at the end of the last 
samples.each!, but

> couldn't find an implementation that worked.

It looks like you need map(), not each():

import std.algorithm;
import std.typecons;
import std.array;

void main() {
auto a = [ 1, 2 ];
auto arr = a.map!(e => tuple(2 * e, e * e)).array;

static assert(is(typeof(arr) == Tuple!(int, int)[]));
}

Ali



GCD build wiringPi for 'Raspberry Pi',here is error info

2015-12-26 Thread FrankLike via Digitalmars-d-learn
Hi,everyone,I build wiringPi for  'Raspberry 
Pi'.(http://wiringpi.com/)

Here is error info:
---gdcbuild
#! /bin/sh
dfiles="max31855.d max5322.d mcp23008.d mcp23016.d mcp23016reg.d 
mcp23017.d mcp23s08.d mcp23s17.d mcp23x08.d mcp23x0817.d 
mcp3002.d mcp3004.d mcp3422.d mcp4802.d pcf8574.d pcf8591.d 
sn3218.d softPwm.d softServo.d softTone.d sr595.d wiringPi.d 
wiringPiI2C.d wiringPiSPI.d wiringSerial.d wiringShift.d 
wpiExtensions.d"


ofiles="drcSerial.o max31855.o max5322.o mcp23008.o mcp23016.o  
mcp23017.o mcp23s08.o mcp23s17.o mcp3002.o mcp3004.o mcp3422.o 
mcp4802.o pcf8574.o pcf8591.o piHiPri.o piThead.o sn3218.o 
softPwm.o softServo.o softTone.o sr595.o wiringPi.o wiringPiI2C.o 
wiringPiSPI.o wiringSerial.o wiringShift.o wpiExtensions.o"


 /opt/arm-unknown-linux-gnueabihf/bin/arm-linux-gnueabihf-gdc  -o 
aa.so $ofiels $dfiles  -shared



sudo ./gdcbuild
/opt/arm-unknown-linux-gnueabihf/bin/../lib/gcc/arm-unknown-linux-gnueabihf/5.2.0/../../../../arm-unknown-linux-gnueabihf/bin/ld:
 
/opt/arm-unknown-linux-gnueabihf/bin/../lib/gcc/arm-unknown-linux-gnueabihf/5.2.0/../../../../arm-unknown-linux-gnueabihf/lib/libgphobos2.a(lifetime.o)(.text+0x30):
 R_ARM_TLS_LE32 relocation not permitted in shared object
/opt/arm-unknown-linux-gnueabihf/bin/../lib/gcc/arm-unknown-linux-gnueabihf/5.2.0/../../../../arm-unknown-linux-gnueabihf/bin/ld:
 
/opt/arm-unknown-linux-gnueabihf/bin/../lib/gcc/arm-unknown-linux-gnueabihf/5.2.0/../../../../arm-unknown-linux-gnueabihf/lib/libgphobos2.a(lifetime.o)(.text+0x2e0):
 R_ARM_TLS_LE32 relocation not permitted in shared object
/opt/arm-unknown-linux-gnueabihf/bin/../lib/gcc/arm-unknown-linux-gnueabihf/5.2.0/../../../../arm-unknown-linux-gnueabihf/bin/ld:
 
/opt/arm-unknown-linux-gnueabihf/bin/../lib/gcc/arm-unknown-linux-gnueabihf/5.2.0/../../../../arm-unknown-linux-gnueabihf/lib/libgphobos2.a(lifetime.o)(.text+0x3f0):
 R_ARM_TLS_LE32 relocation not permitted in shared object
/opt/arm-unknown-linux-gnueabihf/bin/../lib/gcc/arm-unknown-linux-gnueabihf/5.2.0/../../../../arm-unknown-linux-gnueabihf/bin/ld:
 
/opt/arm-unknown-linux-gnueabihf/bin/../lib/gcc/arm-unknown-linux-gnueabihf/5.2.0/../../../../arm-unknown-linux-gnueabihf/lib/libgphobos2.a(lifetime.o)(.text+0x488):
 R_ARM_TLS_LE32 relocation not permitted in shared object
/opt/arm-unknown-linux-gnueabihf/bin/../lib/gcc/arm-unknown-linux-gnueabihf/5.2.0/../../../../arm-unknown-linux-gnueabihf/bin/ld:
 
/opt/arm-unknown-linux-gnueabihf/bin/../lib/gcc/arm-unknown-linux-gnueabihf/5.2.0/../../../../arm-unknown-linux-gnueabihf/lib/libgphobos2.a(tlsgc.o)(.text+0x28):
 R_ARM_TLS_LE32 relocation not permitted in shared object
/opt/arm-unknown-linux-gnueabihf/bin/../lib/gcc/arm-unknown-linux-gnueabihf/5.2.0/../../../../arm-unknown-linux-gnueabihf/bin/ld:
 
/opt/arm-unknown-linux-gnueabihf/bin/../lib/gcc/arm-unknown-linux-gnueabihf/5.2.0/../../../../arm-unknown-linux-gnueabihf/lib/libgphobos2.a(deh.o)(.text+0x158):
 R_ARM_TLS_LE32 relocation not permitted in shared object
/opt/arm-unknown-linux-gnueabihf/bin/../lib/gcc/arm-unknown-linux-gnueabihf/5.2.0/../../../../arm-unknown-linux-gnueabihf/bin/ld:
 
/opt/arm-unknown-linux-gnueabihf/bin/../lib/gcc/arm-unknown-linux-gnueabihf/5.2.0/../../../../arm-unknown-linux-gnueabihf/lib/libgphobos2.a(deh.o)(.text+0x22c):
 R_ARM_TLS_LE32 relocation not permitted in shared object
/opt/arm-unknown-linux-gnueabihf/bin/../lib/gcc/arm-unknown-linux-gnueabihf/5.2.0/../../../../arm-unknown-linux-gnueabihf/bin/ld:
 
/opt/arm-unknown-linux-gnueabihf/bin/../lib/gcc/arm-unknown-linux-gnueabihf/5.2.0/../../../../arm-unknown-linux-gnueabihf/lib/libgphobos2.a(deh.o)(.text+0x7e0):
 R_ARM_TLS_LE32 relocation not permitted in shared object
/opt/arm-unknown-linux-gnueabihf/bin/../lib/gcc/arm-unknown-linux-gnueabihf/5.2.0/../../../../arm-unknown-linux-gnueabihf/bin/ld:
 
/opt/arm-unknown-linux-gnueabihf/bin/../lib/gcc/arm-unknown-linux-gnueabihf/5.2.0/../../../../arm-unknown-linux-gnueabihf/lib/libgphobos2.a(thread.o)(.text+0x4c):
 R_ARM_TLS_LE32 relocation not permitted in shared object
/opt/arm-unknown-linux-gnueabihf/bin/../lib/gcc/arm-unknown-linux-gnueabihf/5.2.0/../../../../arm-unknown-linux-gnueabihf/bin/ld:
 
/opt/arm-unknown-linux-gnueabihf/bin/../lib/gcc/arm-unknown-linux-gnueabihf/5.2.0/../../../../arm-unknown-linux-gnueabihf/lib/libgphobos2.a(thread.o)(.text+0x50):
 R_ARM_TLS_LE32 relocation not permitted in shared object
/opt/arm-unknown-linux-gnueabihf/bin/../lib/gcc/arm-unknown-linux-gnueabihf/5.2.0/../../../../arm-unknown-linux-gnueabihf/bin/ld:
 
/opt/arm-unknown-linux-gnueabihf/bin/../lib/gcc/arm-unknown-linux-gnueabihf/5.2.0/../../../../arm-unknown-linux-gnueabihf/lib/libgphobos2.a(thread.o)(.text+0x3b8):
 R_ARM_TLS_LE32 relocation not permitted in shared object
/opt/arm-unknown-linux-gnueabihf/bin/../lib/gcc/arm-unknown-linux-gnueabihf/5.2.0/../../../../arm-unknown-linux-gnueabihf/bin/ld:
 
/opt/arm-unknown-linux-gnueabihf/bin/../lib/gcc/arm-unknown-linux-gnueabihf/5.2.0/.

GDC build wiringPi for 'Raspberry Pi',here is error info

2015-12-26 Thread FrankLike via Digitalmars-d-learn
Hi,everyone,I build wiringPi for  'Raspberry Pi' by GDC 
(arm-unknown-linux-gnueabihf2.066.1).('wiringPi' download by 
http://wiringpi.com/)

Here is error info:
---gdcbuild
#! /bin/sh
dfiles="max31855.d max5322.d mcp23008.d mcp23016.d mcp23016reg.d 
mcp23017.d mcp23s08.d mcp23s17.d mcp23x08.d mcp23x0817.d 
mcp3002.d mcp3004.d mcp3422.d mcp4802.d pcf8574.d pcf8591.d 
sn3218.d softPwm.d softServo.d softTone.d sr595.d wiringPi.d 
wiringPiI2C.d wiringPiSPI.d wiringSerial.d wiringShift.d 
wpiExtensions.d"


ofiles="drcSerial.o max31855.o max5322.o mcp23008.o mcp23016.o  
mcp23017.o mcp23s08.o mcp23s17.o mcp3002.o mcp3004.o mcp3422.o 
mcp4802.o pcf8574.o pcf8591.o piHiPri.o piThead.o sn3218.o 
softPwm.o softServo.o softTone.o sr595.o wiringPi.o wiringPiI2C.o 
wiringPiSPI.o wiringSerial.o wiringShift.o wpiExtensions.o"


 /opt/arm-unknown-linux-gnueabihf/bin/arm-linux-gnueabihf-gdc  -o 
aa.so $ofiels $dfiles  -shared



sudo ./gdcbuild
/opt/arm-unknown-linux-gnueabihf/bin/../lib/gcc/arm-unknown-linux-gnueabihf/5.2.0/../../../../arm-unknown-linux-gnueabihf/bin/ld:
 
/opt/arm-unknown-linux-gnueabihf/bin/../lib/gcc/arm-unknown-linux-gnueabihf/5.2.0/../../../../arm-unknown-linux-gnueabihf/lib/libgphobos2.a(lifetime.o)(.text+0x30):
 R_ARM_TLS_LE32 relocation not permitted in shared object
/opt/arm-unknown-linux-gnueabihf/bin/../lib/gcc/arm-unknown-linux-gnueabihf/5.2.0/../../../../arm-unknown-linux-gnueabihf/bin/ld:
 
/opt/arm-unknown-linux-gnueabihf/bin/../lib/gcc/arm-unknown-linux-gnueabihf/5.2.0/../../../../arm-unknown-linux-gnueabihf/lib/libgphobos2.a(lifetime.o)(.text+0x2e0):
 R_ARM_TLS_LE32 relocation not permitted in shared object
/opt/arm-unknown-linux-gnueabihf/bin/../lib/gcc/arm-unknown-linux-gnueabihf/5.2.0/../../../../arm-unknown-linux-gnueabihf/bin/ld:
 
/opt/arm-unknown-linux-gnueabihf/bin/../lib/gcc/arm-unknown-linux-gnueabihf/5.2.0/../../../../arm-unknown-linux-gnueabihf/lib/libgphobos2.a(lifetime.o)(.text+0x3f0):
 R_ARM_TLS_LE32 relocation not permitted in shared object
/opt/arm-unknown-linux-gnueabihf/bin/../lib/gcc/arm-unknown-linux-gnueabihf/5.2.0/../../../../arm-unknown-linux-gnueabihf/bin/ld:
 
/opt/arm-unknown-linux-gnueabihf/bin/../lib/gcc/arm-unknown-linux-gnueabihf/5.2.0/../../../../arm-unknown-linux-gnueabihf/lib/libgphobos2.a(lifetime.o)(.text+0x488):
 R_ARM_TLS_LE32 relocation not permitted in shared object
/opt/arm-unknown-linux-gnueabihf/bin/../lib/gcc/arm-unknown-linux-gnueabihf/5.2.0/../../../../arm-unknown-linux-gnueabihf/bin/ld:
 
/opt/arm-unknown-linux-gnueabihf/bin/../lib/gcc/arm-unknown-linux-gnueabihf/5.2.0/../../../../arm-unknown-linux-gnueabihf/lib/libgphobos2.a(tlsgc.o)(.text+0x28):
 R_ARM_TLS_LE32 relocation not permitted in shared object
/opt/arm-unknown-linux-gnueabihf/bin/../lib/gcc/arm-unknown-linux-gnueabihf/5.2.0/../../../../arm-unknown-linux-gnueabihf/bin/ld:
 
/opt/arm-unknown-linux-gnueabihf/bin/../lib/gcc/arm-unknown-linux-gnueabihf/5.2.0/../../../../arm-unknown-linux-gnueabihf/lib/libgphobos2.a(deh.o)(.text+0x158):
 R_ARM_TLS_LE32 relocation not permitted in shared object
/opt/arm-unknown-linux-gnueabihf/bin/../lib/gcc/arm-unknown-linux-gnueabihf/5.2.0/../../../../arm-unknown-linux-gnueabihf/bin/ld:
 
/opt/arm-unknown-linux-gnueabihf/bin/../lib/gcc/arm-unknown-linux-gnueabihf/5.2.0/../../../../arm-unknown-linux-gnueabihf/lib/libgphobos2.a(deh.o)(.text+0x22c):
 R_ARM_TLS_LE32 relocation not permitted in shared object
/opt/arm-unknown-linux-gnueabihf/bin/../lib/gcc/arm-unknown-linux-gnueabihf/5.2.0/../../../../arm-unknown-linux-gnueabihf/bin/ld:
 
/opt/arm-unknown-linux-gnueabihf/bin/../lib/gcc/arm-unknown-linux-gnueabihf/5.2.0/../../../../arm-unknown-linux-gnueabihf/lib/libgphobos2.a(deh.o)(.text+0x7e0):
 R_ARM_TLS_LE32 relocation not permitted in shared object
/opt/arm-unknown-linux-gnueabihf/bin/../lib/gcc/arm-unknown-linux-gnueabihf/5.2.0/../../../../arm-unknown-linux-gnueabihf/bin/ld:
 
/opt/arm-unknown-linux-gnueabihf/bin/../lib/gcc/arm-unknown-linux-gnueabihf/5.2.0/../../../../arm-unknown-linux-gnueabihf/lib/libgphobos2.a(thread.o)(.text+0x4c):
 R_ARM_TLS_LE32 relocation not permitted in shared object
/opt/arm-unknown-linux-gnueabihf/bin/../lib/gcc/arm-unknown-linux-gnueabihf/5.2.0/../../../../arm-unknown-linux-gnueabihf/bin/ld:
 
/opt/arm-unknown-linux-gnueabihf/bin/../lib/gcc/arm-unknown-linux-gnueabihf/5.2.0/../../../../arm-unknown-linux-gnueabihf/lib/libgphobos2.a(thread.o)(.text+0x50):
 R_ARM_TLS_LE32 relocation not permitted in shared object
/opt/arm-unknown-linux-gnueabihf/bin/../lib/gcc/arm-unknown-linux-gnueabihf/5.2.0/../../../../arm-unknown-linux-gnueabihf/bin/ld:
 
/opt/arm-unknown-linux-gnueabihf/bin/../lib/gcc/arm-unknown-linux-gnueabihf/5.2.0/../../../../arm-unknown-linux-gnueabihf/lib/libgphobos2.a(thread.o)(.text+0x3b8):
 R_ARM_TLS_LE32 relocation not permitted in shared object
/opt/arm-unknown-linux-gnueabihf/bin/../lib/gcc/arm-unknown-linux-gnueabihf/5.2.0/../../../../arm-unknown-linux-gnueabihf/bin/ld:
 
/opt/arm-unknow

Re: argument type const char* can pass string, buf why const wchar* can not pass wstring

2015-12-26 Thread Basile B. via Digitalmars-d-learn

On Sunday, 27 December 2015 at 05:29:44 UTC, riki wrote:

On Sunday, 27 December 2015 at 04:54:07 UTC, Basile B. wrote:

On Sunday, 27 December 2015 at 03:34:18 UTC, riki wrote:

void ccf(const char* str){}
void cwf(const wchar* str){}

void main()
{
ccf("aaa");//ok
cwf("xxx"w); // error and why ?
}


IDK but usually the const storage class is used for narrow 
strings because it allows to pass either `char[]` or 
`string[]`:


```
void ccf(const char[] str){}
void cwf(const wchar[] str){}

void main()
{
ccf("aaa");
cwf("xxx"w);
ccf("aaa".dup);
cwf("xxx"w.dup);
}
```

I'm actually surprised that one works, maybe both should fail.


windows api is use const(wchar)*, not const wchar[]


To be clear:

My remark was about how it's used in phobos.
In fact your usage is wrong since you should pass either:

"sfsdf".ptr"
"sdfsf"w.ptr

That's also why i said that I was surpsied that the first call 
didn't generate a compilation error. Anyway, it looks like there 
is an implicit convertion in this case...


Re: argument type const char* can pass string, buf why const wchar* can not pass wstring

2015-12-26 Thread Jimmy Cao via Digitalmars-d-learn

On Sunday, 27 December 2015 at 03:34:18 UTC, riki wrote:

void ccf(const char* str){}
void cwf(const wchar* str){}

void main()
{
ccf("aaa");//ok
cwf("xxx"w); // error and why ?
}


You need to remove the w suffix.  Otherwise it is forcibly typed 
as a dynamic array and is no longer implicitly convertible.


void cwf(const wchar* str){}
void main()
{
ccf("aaa");//ok
cwf("xxx"); // a string literal
}


How to use GDC for 'Raspberry Pi' on Linux x86_64?

2015-12-26 Thread FrankLike via Digitalmars-d-learn

Hi,everyone,
I've download the arm-unknown-linux-gnueabi and 
arm-unknown-linux-gnueabihf,which is I must to use on ' Raspberry 
Pi'?

Now,I've chosen the  arm-unknown-linux-gnueabihf.That's ok?
I've made the hello.d,and made the hello.
The file 'hello' can be used on  'Raspberry Pi'?
Now I'm not having the  'Raspberry Pi'.

Thank you.


specifying an auto array type

2015-12-26 Thread Jay Norwood via Digitalmars-d-learn
This is getting kind of a long example, but I'm really only 
interested in the last 4 or 5 lines. This works as desired, 
creating the array of tuples, but I'm wondering if there is a way 
to have the Tuple array defined as auto instead of having to 
specify the types.  I tried using .array() at the end of the last 
samples.each!, but couldn't find an implementation that worked.


Yes, I know, some of these imports aren't required (yet).

import std.stdio;
import std.algorithm;
import std.conv;
import std.range;
import std.typecons;
import std.parallelism;
import std.array;

struct S { ulong a; ulong b; ulong c; ulong d; double e; ulong f;}
ulong f1(ref S s) { with(s){return a+b;}}
double f2(ref S s) { with(s){return (c+d)/e;}}
double f3(ref S s) { with(s){return (c+f)/e;}}

int main()
{

S[10] samples;
// initialize some values
foreach ( int i, ref s; samples){
int j=i+1;
with (s){
a=j; b=j*2; c=j*3; d=j*4; e=j*10; f=j*5;
}
}

// apply several functions on each  sample
	samples.each!((int i, ref 
a)=>tuple!("sample","f1","f2","f3")(i,f1(a),f2(a),f3(a)).writeln());


// output the function results to an array of tuples
Tuple!(int, ulong, double, double)[] arr;

	samples.each!((int i, ref a)=> arr ~= 
tuple!("sample","f1","f2","f3")(i,f1(a),f2(a),f3(a)));

writeln(arr);
return 0;
}


Re: argument type const char* can pass string, buf why const wchar* can not pass wstring

2015-12-26 Thread riki via Digitalmars-d-learn

On Sunday, 27 December 2015 at 04:54:07 UTC, Basile B. wrote:

On Sunday, 27 December 2015 at 03:34:18 UTC, riki wrote:

void ccf(const char* str){}
void cwf(const wchar* str){}

void main()
{
ccf("aaa");//ok
cwf("xxx"w); // error and why ?
}


IDK but usually the const storage class is used for narrow 
strings because it allows to pass either `char[]` or `string[]`:


```
void ccf(const char[] str){}
void cwf(const wchar[] str){}

void main()
{
ccf("aaa");
cwf("xxx"w);
ccf("aaa".dup);
cwf("xxx"w.dup);
}
```

I'm actually surprised that one works, maybe both should fail.


windows api is use const(wchar)*, not const wchar[]


Re: argument type const char* can pass string, buf why const wchar* can not pass wstring

2015-12-26 Thread Basile B. via Digitalmars-d-learn

On Sunday, 27 December 2015 at 04:54:07 UTC, Basile B. wrote:

it allows to pass either `char[]` or `string[]`:


I meant "char[]` or `string", string without square brackets of 
course...





Re: argument type const char* can pass string, buf why const wchar* can not pass wstring

2015-12-26 Thread Basile B. via Digitalmars-d-learn

On Sunday, 27 December 2015 at 03:34:18 UTC, riki wrote:

void ccf(const char* str){}
void cwf(const wchar* str){}

void main()
{
ccf("aaa");//ok
cwf("xxx"w); // error and why ?
}


IDK but usually the const storage class is used for narrow 
strings because it allows to pass either `char[]` or `string[]`:


```
void ccf(const char[] str){}
void cwf(const wchar[] str){}

void main()
{
ccf("aaa");
cwf("xxx"w);
ccf("aaa".dup);
cwf("xxx"w.dup);
}
```

I'm actually surprised that one works, maybe both should fail.


Re: How to instantiate a map with multiple functions

2015-12-26 Thread Jay Norwood via Digitalmars-d-learn

On Sunday, 27 December 2015 at 03:22:50 UTC, Jay Norwood wrote:
I would probably want to associate names with the tuple metric 
results, and I've seen that somewhere in the docs in parameter 
tuples.   I suppose I'll try those in place of the current 
tuple ...




This worked to associate names with the tuple values. Just the 
one line modified.
samples.each!((int i, ref 
a)=>tuple!("sample","f1","f2","f3")(i,f1(a),f2(a),f3(a)).writeln());


=== output
Tuple!(int, "sample", ulong, "f1", double, "f2", double, "f3")(0, 
3, 0.7, 0.8)
Tuple!(int, "sample", ulong, "f1", double, "f2", double, "f3")(1, 
6, 0.7, 0.8)
Tuple!(int, "sample", ulong, "f1", double, "f2", double, "f3")(2, 
9, 0.7, 0.8)
Tuple!(int, "sample", ulong, "f1", double, "f2", double, "f3")(3, 
12, 0.7, 0.8)
Tuple!(int, "sample", ulong, "f1", double, "f2", double, "f3")(4, 
15, 0.7, 0.8)
Tuple!(int, "sample", ulong, "f1", double, "f2", double, "f3")(5, 
18, 0.7, 0.8)
Tuple!(int, "sample", ulong, "f1", double, "f2", double, "f3")(6, 
21, 0.7, 0.8)
Tuple!(int, "sample", ulong, "f1", double, "f2", double, "f3")(7, 
24, 0.7, 0.8)
Tuple!(int, "sample", ulong, "f1", double, "f2", double, "f3")(8, 
27, 0.7, 0.8)
Tuple!(int, "sample", ulong, "f1", double, "f2", double, "f3")(9, 
30, 0.7, 0.8)




Re: argument type const char* can pass string, buf why const wchar* can not pass wstring

2015-12-26 Thread riki via Digitalmars-d-learn

On Sunday, 27 December 2015 at 03:40:50 UTC, Alex Parrill wrote:

On Sunday, 27 December 2015 at 03:34:18 UTC, riki wrote:

void ccf(const char* str){}
void cwf(const wchar* str){}

void main()
{
ccf("aaa");//ok
cwf("xxx"w); // error and why ?
}


Unrelated to your error, but those functions should probably 
take a `string` and `wstring` respectively instead.


xx.d(7): Error: function xx.cwf (const(wchar*) str) is not 
callable using argument types (wstring)


Re: argument type const char* can pass string, buf why const wchar* can not pass wstring

2015-12-26 Thread Alex Parrill via Digitalmars-d-learn

On Sunday, 27 December 2015 at 03:34:18 UTC, riki wrote:

void ccf(const char* str){}
void cwf(const wchar* str){}

void main()
{
ccf("aaa");//ok
cwf("xxx"w); // error and why ?
}


Unrelated to your error, but those functions should probably take 
a `string` and `wstring` respectively instead.


argument type const char* can pass string, buf why const wchar* can not pass wstring

2015-12-26 Thread riki via Digitalmars-d-learn

void ccf(const char* str){}
void cwf(const wchar* str){}

void main()
{
ccf("aaa");//ok
cwf("xxx"w); // error and why ?
}


Re: How to instantiate a map with multiple functions

2015-12-26 Thread Jay Norwood via Digitalmars-d-learn
I'm playing around with something also trying to apply multiple 
functions.
In my case, a sample is some related group of measurements taken 
simultaneously, and I'm calculating a group of metrics from the 
measured data of each sample.


This produces the correct results for the input data, and it 
seems pretty clear what functions are being applied.


I would probably want to associate names with the tuple metric 
results, and I've seen that somewhere in the docs in parameter 
tuples.   I suppose I'll try those in place of the current tuple 
...


import std.stdio;
import std.algorithm;
import std.conv;
import std.range;
import std.typecons;

struct S { ulong a; ulong b; ulong c; ulong d; double e; ulong f;}

ulong f1(ref S s) { with(s){return a+b;}}
double f2(ref S s) { with(s){return (c+d)/e;}}
double f3(ref S s) { with(s){return (c+f)/e;}}

int main()
{

S[10] samples;
// initialize some values
foreach ( int i, ref s; samples){
int j=i+1;
with (s){
a=j; b=j*2; c=j*3; d=j*4; e=j*10; f=j*5;
}
}

// apply several functions on each  sample
	samples.each!((int i, ref 
a)=>tuple(i,f1(a),f2(a),f3(a)).writeln());

return 0;
}

== output is

Tuple!(int, ulong, double, double)(0, 3, 0.7, 0.8)
Tuple!(int, ulong, double, double)(1, 6, 0.7, 0.8)
Tuple!(int, ulong, double, double)(2, 9, 0.7, 0.8)
Tuple!(int, ulong, double, double)(3, 12, 0.7, 0.8)
Tuple!(int, ulong, double, double)(4, 15, 0.7, 0.8)
Tuple!(int, ulong, double, double)(5, 18, 0.7, 0.8)
Tuple!(int, ulong, double, double)(6, 21, 0.7, 0.8)
Tuple!(int, ulong, double, double)(7, 24, 0.7, 0.8)
Tuple!(int, ulong, double, double)(8, 27, 0.7, 0.8)
Tuple!(int, ulong, double, double)(9, 30, 0.7, 0.8)




Re: How to instantiate a map with multiple functions

2015-12-26 Thread Ali Çehreli via Digitalmars-d-learn

On 12/26/2015 05:26 PM, Karthikeyan wrote:

> if I need to map on a array of tuples will that work with the tuple being
> unpacked or do I need to get it as single element and do unpacking 
myself?


Unfortunately, there is no automatic unpacking of tuples.

The only exception that I know is when tuples are elements of a range 
(but not a proper slice, in which case the first element is the 
automatic element index).


import std.stdio;
import std.typecons;
import std.range;
import std.algorithm;

void main() {
auto range = 5.iota.map!(i => tuple(2 * i, i * i));

// automatic tuple expansion:
foreach (twice, square; range) {
writefln("twice: %s, square: %s", twice, square);
}
}

Prints:

twice: 0, square: 0
twice: 2, square: 1
twice: 4, square: 4
twice: 6, square: 9
twice: 8, square: 16

The problem is when the same elements are inside a slice:

import std.stdio;
import std.typecons;
import std.range;
import std.algorithm;

void main() {
auto range = [ tuple(0, 0), tuple(2, 1) ];

foreach (twice, square; range) {
writefln("twice: %s, square: %s", twice, square);
}
}

Now 'twice' is the automatic index, and 'square' is the entire element 
(i.e. the tuple):


twice: 0, square: Tuple!(int, int)(0, 0)
twice: 1, square: Tuple!(int, int)(2, 1)

Ali



Re: basic interactive readf from stdin

2015-12-26 Thread Karthikeyan via Digitalmars-d-learn

On Sunday, 27 December 2015 at 02:08:05 UTC, Ali Çehreli wrote:

On 12/26/2015 05:15 PM, Karthikeyan wrote:

>> The answer is nine chapters later. :) (Use readln() and
strip() (or
>> chomp())).
>>
>>   http://ddili.org/ders/d.en/strings.html
>>
>> Ali
>
> Many thanks Ali. The book says ctrl + D to end input. But I
used two
> enters to get the output. Any idea why?

I guess that means that my understanding was not portable. It 
requires Ctrl-D on my console environment on Linux. No matter 
how many Enters I enter :p they become parts of the same string.


Ali


:) I was on zsh with gnome terminal alike on Linux Mint 15. 
Thanks for clearing that up.




Re: basic interactive readf from stdin

2015-12-26 Thread Ali Çehreli via Digitalmars-d-learn

On 12/26/2015 05:15 PM, Karthikeyan wrote:

>> The answer is nine chapters later. :) (Use readln() and strip() (or
>> chomp())).
>>
>>   http://ddili.org/ders/d.en/strings.html
>>
>> Ali
>
> Many thanks Ali. The book says ctrl + D to end input. But I used two
> enters to get the output. Any idea why?

I guess that means that my understanding was not portable. It requires 
Ctrl-D on my console environment on Linux. No matter how many Enters I 
enter :p they become parts of the same string.


Ali



Re: How to instantiate a map with multiple functions

2015-12-26 Thread Karthikeyan via Digitalmars-d-learn

On Sunday, 27 December 2015 at 00:27:12 UTC, Ali Çehreli wrote:

On 12/26/2015 11:46 AM, karthikeyan wrote:

> Thanks but the following returns an error for me
>
>import std.algorithm.comparison : equal;
>import std.range : chain;
>int[] arr1 = [ 1, 2, 3, 4 ];
>int[] arr2 = [ 5, 6 ];
>auto dd = map!(z => z * z, c => c * c * c)(chain(arr1,
arr2));
>writeln(dd);
>
> Error :
>
> /usr/include/dmd/phobos/std/meta.d(546): Error: template
instance
> F!(__lambda2) cannot use local '__lambda2' as parameter to
non-global
> template AppliedReturnType(alias f)

That looks like a bug to me. Please report here:

  https://issues.dlang.org/

You can call tuple() as a workaround:

import std.stdio;
import std.algorithm;
import std.range;
import std.typecons;

void main() {
int[] arr1 = [ 1, 2, 3, 4 ];
int[] arr2 = [ 5, 6 ];
auto dd = map!(z => tuple(z * z, z * z * z))(chain(arr1, 
arr2));

writeln(dd);
}

Ali


Thanks Ali. I think it's been around like this for a long time. I 
searched issue tracker but no issues of this type. Also if I need 
to map on a array of tuples will that work with the tuple being 
unpacked or do I need to get it as single element and do 
unpacking myself? Sorry on mobile so couldn't check.


Re: basic interactive readf from stdin

2015-12-26 Thread Karthikeyan via Digitalmars-d-learn

On Sunday, 27 December 2015 at 00:20:51 UTC, Ali Çehreli wrote:

On 12/26/2015 12:11 PM, karthikeyan wrote:

> I read http://ddili.org/ders/d.en/input.html and inserted a
space before %s
> but still no use. Am I missing something here with the latest
version?

The answer is nine chapters later. :) (Use readln() and strip() 
(or chomp())).


  http://ddili.org/ders/d.en/strings.html

Ali


Many thanks Ali. The book says ctrl + D to end input. But I used 
two enters to get the output. Any idea why? The book was great. 
Thanks a lot.




Re: basic interactive readf from stdin

2015-12-26 Thread Jay Norwood via Digitalmars-d-learn

On Sunday, 27 December 2015 at 00:20:51 UTC, Ali Çehreli wrote:

On 12/26/2015 12:11 PM, karthikeyan wrote:

> I read http://ddili.org/ders/d.en/input.html and inserted a
space before %s
> but still no use. Am I missing something here with the latest
version?

The answer is nine chapters later. :) (Use readln() and strip() 
(or chomp())).


  http://ddili.org/ders/d.en/strings.html

Ali


Yes, thank you, strip() appears to be more useful than chomp() in 
this case.






Re: How to instantiate a map with multiple functions

2015-12-26 Thread Ali Çehreli via Digitalmars-d-learn

On 12/26/2015 11:46 AM, karthikeyan wrote:

> Thanks but the following returns an error for me
>
>import std.algorithm.comparison : equal;
>import std.range : chain;
>int[] arr1 = [ 1, 2, 3, 4 ];
>int[] arr2 = [ 5, 6 ];
>auto dd = map!(z => z * z, c => c * c * c)(chain(arr1, arr2));
>writeln(dd);
>
> Error :
>
> /usr/include/dmd/phobos/std/meta.d(546): Error: template instance
> F!(__lambda2) cannot use local '__lambda2' as parameter to non-global
> template AppliedReturnType(alias f)

That looks like a bug to me. Please report here:

  https://issues.dlang.org/

You can call tuple() as a workaround:

import std.stdio;
import std.algorithm;
import std.range;
import std.typecons;

void main() {
int[] arr1 = [ 1, 2, 3, 4 ];
int[] arr2 = [ 5, 6 ];
auto dd = map!(z => tuple(z * z, z * z * z))(chain(arr1, arr2));
writeln(dd);
}

Ali



Re: basic interactive readf from stdin

2015-12-26 Thread Ali Çehreli via Digitalmars-d-learn

On 12/26/2015 12:11 PM, karthikeyan wrote:

> I read http://ddili.org/ders/d.en/input.html and inserted a space 
before %s

> but still no use. Am I missing something here with the latest version?

The answer is nine chapters later. :) (Use readln() and strip() (or 
chomp())).


  http://ddili.org/ders/d.en/strings.html

Ali



Re: basic interactive readf from stdin

2015-12-26 Thread Ali Çehreli via Digitalmars-d-learn

On 12/26/2015 11:40 AM, Jay Norwood wrote:

Simple VS console app in D.  Reading lines to a string variable
interactively. Object is to have no extra blank lines in the console
output.  Seems very broken for this use, requiring two extra "enter"
entries before the outputs both appear. Version DMD32 D Compiler v2.069.2

import std.stdio;

int main(string[] argv)
{
  string nm;
  stdin.readf("%s\n",&nm);
  writeln("nm:",nm);
  stdin.readf("%s\n",&nm);
  writeln("nm:",nm);
  return 0;
}

 io shown below
123
456
nm:123

nm:456



Reading lines with readln works in a Linux console:

import std.stdio;
import std.string;

int main(string[] argv)
{
string nm;

nm = readln.strip;
writeln("nm:",nm);

nm = readln.strip;
writeln("nm:",nm);

return 0;
}

Ali



Re: basic interactive readf from stdin

2015-12-26 Thread Jay Norwood via Digitalmars-d-learn
On Saturday, 26 December 2015 at 20:19:08 UTC, Adam D. Ruppe 
wrote:
On Saturday, 26 December 2015 at 20:11:27 UTC, karthikeyan 
wrote:
I experience the same as the OP on Linux Mint 15 with dmd2.069 
and 64 bit machine.  I have to press enter twice to get the 
output. I read http://ddili.org/ders/d.en/input.html and 
inserted a space before %s but still no use. Am I missing 
something here with the latest version?


Oh, I'm sorry, it isn't buffering, it is readfing into a string 
here which is weird. Maybe try readln instead of readf.


The use of readf into a string is demonstrated in a stdio.d unit 
test.  I assumed it might also work with stdin.


string s;
auto f = File(deleteme);
f.readf("%s\n", &s);
assert(s == "hello", "["~s~"]");
f.readf("%s\n", &s);
assert(s == "world", "["~s~"]");

=
I did get this below to work with readln, although since readln 
didn't consume the terminator, I had to add the chomp() call.


import std.stdio;
import std.string;

int main(string[] argv)
{
  string nm, nm2;
  nm=readln('\n');
  nm2 = nm.chomp();
  writeln("nm:",nm2);

  nm=readln('\n');
  nm2 = nm.chomp();
  writeln("nm:",nm2);

  return 0;
}


Re: basic interactive readf from stdin

2015-12-26 Thread Jay Norwood via Digitalmars-d-learn

On Saturday, 26 December 2015 at 20:38:52 UTC, tcak wrote:
On Saturday, 26 December 2015 at 20:19:08 UTC, Adam D. Ruppe 
wrote:
On Saturday, 26 December 2015 at 20:11:27 UTC, karthikeyan 
wrote:
I experience the same as the OP on Linux Mint 15 with 
dmd2.069 and 64 bit machine.  I have to press enter twice to 
get the output. I read http://ddili.org/ders/d.en/input.html 
and inserted a space before %s but still no use. Am I missing 
something here with the latest version?


Oh, I'm sorry, it isn't buffering, it is readfing into a 
string here which is weird. Maybe try readln instead of readf.


As far as I remember, in C, if I was to be putting "\n" in 
scanf after %s, that double entering was happening. I guess 
that's the same problem. Trying same code without \n in readf 
can fix it I guess.


import std.stdio;

int main(string[] argv)
{
 string nm;
 stdin.readf("%s",&nm);
 writeln("nm:",nm);
 stdout.flush();
 stdin.readf("%s",&nm);
 writeln("nm:",nm);
 stdout.flush();

 return 0;
}

ok, I tried above, adding both the stdout.flush() and removing 
the \n from the format. It didn't write to output even after a 
couple of enter's.  When I  entered ctrl-Z,  it output below.


 output running from command prompt
123
456

^Z
nm:123
456


nm:123
456




Re: basic interactive readf from stdin

2015-12-26 Thread Jay Norwood via Digitalmars-d-learn
On Saturday, 26 December 2015 at 19:52:15 UTC, Adam D. Ruppe 
wrote:
On Saturday, 26 December 2015 at 19:40:59 UTC, Jay Norwood 
wrote:

Simple VS console app in D.


If you are running inside visual studio, you need to be aware 
that output will be block buffered, not line buffered, because 
VS pipes the output making the program think it is talking to 
another program instead of to an interactive console (well, 
because it is!)


Add a stdout.flush(); after writing to force it to show 
immediately. I really think the read functions ought to flush 
output too because this is such a FAQ. (indeed, my terminal.d 
does flush output when you request input)


It doesn't make a difference if I run in VS or from a console 
window.  I had also already tried various forms stdout.flush().  
It doesn't make a difference ... still requires two extra enters 
before it outputs the data.  I haven't tried it in linux yet.





Re: Derelict SFML2 - structs are forward referenced

2015-12-26 Thread Lucien via Digitalmars-d-learn

On Saturday, 26 December 2015 at 12:47:51 UTC, drug wrote:
You have old version of libcsfml that lacks of symbol 
sfJoystick_getIdentification. Try another version, may be build 
it from sources to have the newest one.


Indeed, the sfml library in the ubuntu repository isn't 
up-to-date.


Thanks for your help.


Re: basic interactive readf from stdin

2015-12-26 Thread tcak via Digitalmars-d-learn
On Saturday, 26 December 2015 at 20:19:08 UTC, Adam D. Ruppe 
wrote:
On Saturday, 26 December 2015 at 20:11:27 UTC, karthikeyan 
wrote:
I experience the same as the OP on Linux Mint 15 with dmd2.069 
and 64 bit machine.  I have to press enter twice to get the 
output. I read http://ddili.org/ders/d.en/input.html and 
inserted a space before %s but still no use. Am I missing 
something here with the latest version?


Oh, I'm sorry, it isn't buffering, it is readfing into a string 
here which is weird. Maybe try readln instead of readf.


As far as I remember, in C, if I was to be putting "\n" in scanf 
after %s, that double entering was happening. I guess that's the 
same problem. Trying same code without \n in readf can fix it I 
guess.


Re: basic interactive readf from stdin

2015-12-26 Thread Adam D. Ruppe via Digitalmars-d-learn

On Saturday, 26 December 2015 at 20:11:27 UTC, karthikeyan wrote:
I experience the same as the OP on Linux Mint 15 with dmd2.069 
and 64 bit machine.  I have to press enter twice to get the 
output. I read http://ddili.org/ders/d.en/input.html and 
inserted a space before %s but still no use. Am I missing 
something here with the latest version?


Oh, I'm sorry, it isn't buffering, it is readfing into a string 
here which is weird. Maybe try readln instead of readf.




Re: basic interactive readf from stdin

2015-12-26 Thread karthikeyan via Digitalmars-d-learn
On Saturday, 26 December 2015 at 19:52:15 UTC, Adam D. Ruppe 
wrote:
On Saturday, 26 December 2015 at 19:40:59 UTC, Jay Norwood 
wrote:

Simple VS console app in D.


If you are running inside visual studio, you need to be aware 
that output will be block buffered, not line buffered, because 
VS pipes the output making the program think it is talking to 
another program instead of to an interactive console (well, 
because it is!)


Add a stdout.flush(); after writing to force it to show 
immediately. I really think the read functions ought to flush 
output too because this is such a FAQ. (indeed, my terminal.d 
does flush output when you request input)


I experience the same as the OP on Linux Mint 15 with dmd2.069 
and 64 bit machine.  I have to press enter twice to get the 
output. I read http://ddili.org/ders/d.en/input.html and inserted 
a space before %s but still no use. Am I missing something here 
with the latest version?


Code

import std.stdio;

int main(string[] argv)
{
  string nm;
  readf(" %s\n",&nm);
  writeln("nm:",nm);
  // readf(" %s\n",&nm);
  // writeln("nm:",nm);
  return 0;
}


Output

56
2
nm:56


Re: GTKD - Get the size of the context

2015-12-26 Thread Bubbasaur via Digitalmars-d-learn

On Saturday, 26 December 2015 at 13:28:31 UTC, TheDGuy wrote:
I get the error "value of 'this' is not known at compile time" 
which refers to the line where i create the int-array "space"

Why is it not possible to use it there?


Just for future newcomers, the answer for the above was given 
here:

http://forum.dlang.org/post/tqvgmsluuhzzscbxh...@forum.dlang.org

By Adam D. Ruppe:

"
Try:

auto arr = new int[](size.width*size.height*3+1);

The int[x] syntax declares a statically sized array - statically 
sized meaning it must be known at compile time and thus cannot be 
variables, along a few other differences.


The new array syntax though returns one of variable size.
"

Bubba.


Re: basic interactive readf from stdin

2015-12-26 Thread Adam D. Ruppe via Digitalmars-d-learn

On Saturday, 26 December 2015 at 19:40:59 UTC, Jay Norwood wrote:

Simple VS console app in D.


If you are running inside visual studio, you need to be aware 
that output will be block buffered, not line buffered, because VS 
pipes the output making the program think it is talking to 
another program instead of to an interactive console (well, 
because it is!)


Add a stdout.flush(); after writing to force it to show 
immediately. I really think the read functions ought to flush 
output too because this is such a FAQ. (indeed, my terminal.d 
does flush output when you request input)


Re: How to instantiate a map with multiple functions

2015-12-26 Thread karthikeyan via Digitalmars-d-learn

On Saturday, 26 December 2015 at 19:38:16 UTC, Fusxfaranto wrote:
On Saturday, 26 December 2015 at 19:30:24 UTC, karthikeyan 
wrote:
How to instantiate a map with multiple functions. I looked 
into the docs at 
http://dlang.org/phobos/std_algorithm_iteration.html#map. They 
contain a string which I suppose is a mixin and when I change 
"a" to some other name it results in an error for me. Are 
there any ways to use lambda functions directly instead of 
strings and any explanation of the strings used in the map 
example and why a is used will be helpful.


I tried reading the source 
https://github.com/D-Programming-Language/phobos/blob/master/std/algorithm/iteration.d#L520 .Some hint that "a" should be used at https://github.com/D-Programming-Language/phobos/blob/master/std/functional.d#L101 but how do I change that since map doesn't allow me any params to specify the parameter name. Also how can I map an array of tuples with two or more elements with a function of two or more params like unpack the tuple into a function like that. I am D beginner so any will insights will be very helpful for me.


I am using dmd version 2.069 on Linux Mint 15 - 64bit


You should be able to just use any function (including lambdas) 
as a template argument to map.  The string version is from 
before the more concise "=>" lambda syntax was developed, and 
generally isn't what you want to use nowadays.


Thanks but the following returns an error for me

  import std.algorithm.comparison : equal;
  import std.range : chain;
  int[] arr1 = [ 1, 2, 3, 4 ];
  int[] arr2 = [ 5, 6 ];
  auto dd = map!(z => z * z, c => c * c * c)(chain(arr1, arr2));
  writeln(dd);

Error :

/usr/include/dmd/phobos/std/meta.d(546): Error: template instance 
F!(__lambda2) cannot use local '__lambda2' as parameter to 
non-global template AppliedReturnType(alias f)
/usr/include/dmd/phobos/std/meta.d(552): Error: template instance 
maps_square.main.staticMap!(AppliedReturnType, __lambda2) error 
instantiating
/usr/include/dmd/phobos/std/algorithm/iteration.d(447):
instantiated from here: staticMap!(AppliedReturnType, __lambda2, 
__lambda3)

maps_square.d(71):instantiated from here: map!(Result)
/usr/include/dmd/phobos/std/meta.d(546): Error: template instance 
F!(__lambda3) cannot use local '__lambda3' as parameter to 
non-global template AppliedReturnType(alias f)
/usr/include/dmd/phobos/std/meta.d(553): Error: template instance 
maps_square.main.staticMap!(AppliedReturnType, __lambda3) error 
instantiating
/usr/include/dmd/phobos/std/algorithm/iteration.d(447):
instantiated from here: staticMap!(AppliedReturnType, __lambda2, 
__lambda3)

maps_square.d(71):instantiated from here: map!(Result)

Am I missing something here over how the lambda notation can be 
used? I personally prefer the lambda notation to be clear than 
passing strings as arguments. Kindly help me on this.


basic interactive readf from stdin

2015-12-26 Thread Jay Norwood via Digitalmars-d-learn
Simple VS console app in D.  Reading lines to a string variable 
interactively. Object is to have no extra blank lines in the 
console output.  Seems very broken for this use, requiring two 
extra "enter" entries before the outputs both appear. Version 
DMD32 D Compiler v2.069.2


import std.stdio;

int main(string[] argv)
{
 string nm;
 stdin.readf("%s\n",&nm);
 writeln("nm:",nm);
 stdin.readf("%s\n",&nm);
 writeln("nm:",nm);
 return 0;
}

 io shown below
123
456
nm:123

nm:456



Re: How to instantiate a map with multiple functions

2015-12-26 Thread Fusxfaranto via Digitalmars-d-learn

On Saturday, 26 December 2015 at 19:30:24 UTC, karthikeyan wrote:
How to instantiate a map with multiple functions. I looked into 
the docs at 
http://dlang.org/phobos/std_algorithm_iteration.html#map. They 
contain a string which I suppose is a mixin and when I change 
"a" to some other name it results in an error for me. Are there 
any ways to use lambda functions directly instead of strings 
and any explanation of the strings used in the map example and 
why a is used will be helpful.


I tried reading the source 
https://github.com/D-Programming-Language/phobos/blob/master/std/algorithm/iteration.d#L520 .Some hint that "a" should be used at https://github.com/D-Programming-Language/phobos/blob/master/std/functional.d#L101 but how do I change that since map doesn't allow me any params to specify the parameter name. Also how can I map an array of tuples with two or more elements with a function of two or more params like unpack the tuple into a function like that. I am D beginner so any will insights will be very helpful for me.


I am using dmd version 2.069 on Linux Mint 15 - 64bit


You should be able to just use any function (including lambdas) 
as a template argument to map.  The string version is from before 
the more concise "=>" lambda syntax was developed, and generally 
isn't what you want to use nowadays.


How to instantiate a map with multiple functions

2015-12-26 Thread karthikeyan via Digitalmars-d-learn
How to instantiate a map with multiple functions. I looked into 
the docs at 
http://dlang.org/phobos/std_algorithm_iteration.html#map. They 
contain a string which I suppose is a mixin and when I change "a" 
to some other name it results in an error for me. Are there any 
ways to use lambda functions directly instead of strings and any 
explanation of the strings used in the map example and why a is 
used will be helpful.


I tried reading the source 
https://github.com/D-Programming-Language/phobos/blob/master/std/algorithm/iteration.d#L520 .Some hint that "a" should be used at https://github.com/D-Programming-Language/phobos/blob/master/std/functional.d#L101 but how do I change that since map doesn't allow me any params to specify the parameter name. Also how can I map an array of tuples with two or more elements with a function of two or more params like unpack the tuple into a function like that. I am D beginner so any will insights will be very helpful for me.


I am using dmd version 2.069 on Linux Mint 15 - 64bit


Re: Must I compile on the target architecture?

2015-12-26 Thread Orfeo via Digitalmars-d-learn

On Friday, 25 December 2015 at 12:43:05 UTC, Jakob Jenkov wrote:

Hi, just a quick question:

If I write a program in D and I use Windows for development but 
want it to run on Linux, do I have to copy the source code to 
the target Linux machine and compile it there, to make an 
executable for that machine? What is the standard process for 
cross platform compilation?


See also [Should I compile D program on Linux for 
windows?](http://stackoverflow.com/questions/13501595/should-i-compile-d-program-on-linux-for-windows/13502264#13502264)


Re: Must I compile on the target architecture?

2015-12-26 Thread Jakob Jenkov via Digitalmars-d-learn
For Linux programs built on Windows... you'll prolly just want 
to copy it to a linux box.


Thanks, both of you.

I guess the easiest would be to compile it on a virtual machine 
with the OS I want to build for. I mean, I could run a Linux VM 
on my Windows box and compile my code there. Or the other way 
around.


Re: DMD -L Flag, maybe a bug?

2015-12-26 Thread Bubbasaur via Digitalmars-d-learn
On Saturday, 26 December 2015 at 11:53:55 UTC, Ivan Kazmenko 
wrote:
Note that -L passes flags (options) but not necessarily 
arguments or paths.  For example, I use "dmd 
-L/STACK:268435456" by default along with other options to 
increase the default stack size to 256Mb.


Your comment is reasonable enough, but unfortunately the main 
problem is there are examples on the internet using this "-L" for 
this kind of thing.


If go here: 
http://wiki.dlang.org/Compiling_and_linking_with_DMD_on_Windows#Static_Libraries_and_Import_Paths


There is an example in: "Passing search directories for static 
library files to Optlink", which follows:


C:\Project\main.d
C:\Project\lib\mylib.lib

where main.d depends on the mylib library, you can compile 
via:


dmd -L+.\lib\ driver.d mylib.lib

Yes there is a "+" plus sign and a "." dot there, but I believe 
people gets confuse and uses it as "-I".



Clearly, the forward slash (/) is reserved for switches, so the 
program will have trouble parsing paths with forward slashes.


About this in fact this was my mistake, because originally I had 
tried "\" and since it wasn't working so I change to "/" and that 
remains.


Bubba.


Re: GTKD - Get the size of the context

2015-12-26 Thread TheDGuy via Digitalmars-d-learn
Thank you very much for your answer! I really appreciate it 
because it is kind of hard to find explanations for GTKD.


But know i face a strange problem:

this(Vector3D camera, Context cr, Widget widget){
this.camera = camera;
this.cr = cr;
this.widget = widget;

GtkAllocation size;
widget.getAllocation(size);
this.width = size.width;
this.height = size.height;
}
void restartProgressiveRendering(){
int[this.width*this.height*3+1] space;
this.accumulator = space;
}

I get the error "value of 'this' is not known at compile time" 
which refers to the line where i create the int-array "space"

Why is it not possible to use it there?


Re: DMD -L Flag, maybe a bug?

2015-12-26 Thread Bubbasaur via Digitalmars-d-learn

On Saturday, 26 December 2015 at 11:19:27 UTC, anonymous wrote:

...
Note that in the docs I linked it's `dmd hello.d -L+gtkd.lib` 
with a plus sign. I'm not sure if it's significant, but it's a 
difference.


There are two ways in the doc you linked:

dmd hello.d -L+gtkd.lib
or
dmd hello.d -Lgtkd.lib -m64

The second doesn't uses "+" but it has "-m64". Anyway even the 
example with "+" it doesn't working here either.


Also, and this may be it, the link.exe that's distributed with 
dmd doesn't like forward slashes as path separators. You can 
try it with backslashes instead:


dmd test.d -LC:\gtkd\src\build\GtkD.lib


I had tried that before, without any success.

-L doesn't take a space, either. Putting a space there isn't 
even optional, it's wrong. The stuff after the space is not 
passed to the linker, it's interpreted by dmd.


In fact I already had understood what happened after your first 
answer, which "-L" with space wasn't been "evaluated" because DMD 
was reading a flag without arguments. So I could omit it there, 
but like I said, many examples out there uses:
"-Lpath/to/whatever", and then you see many topics about people 
complaining about this.


Bubba.


Re: Derelict SFML2 - structs are forward referenced

2015-12-26 Thread drug via Digitalmars-d-learn

26.12.2015 15:34, Lucien пишет:

On Saturday, 26 December 2015 at 10:39:29 UTC, Rene Zwanenburg wrote:

On Saturday, 26 December 2015 at 09:48:29 UTC, Lucien wrote:

Hello.

I want to use Derelict-SFML2 to create a simple window.
But when I compile (linked with dub and derelict-util), I have the
following error:

src/app.d(30,20): Error: variable myproject.main.window no definition
of struct sfRenderWindow
../../../.dub/packages/derelict-sfml2-3.0.1/source/derelict/sfml2/graphics.d(56,1):
Error: struct derelict.sfml2.graphics.sfRenderWindow unknown size
src/app.d(31,5): Error: struct sfRenderWindow is forward referenced
src/app.d(32,12): Error: struct sfRenderWindow is forward referenced
src/app.d(35,16): Error: struct sfRenderWindow is forward referenced
src/app.d(38,17): Error: struct sfRenderWindow is forward referenced

My code: http://pastebin.com/1svZAB22

Is it a bug in Derelict-SFML2 or want did I do false ?

Hoping that you understood me with my bad English :)


sfRenderWindow is an opaque struct, so its size is unknown. This means
you can only use pointers to them, and any operations on them will
have to be done using SFML. So in your code, change sfRenderWindow to
sfRenderWindow*.

Did you by any chance look at a C++ tutorial for SFML? Derelict binds
to the C API so it looks a bit different. To create a window
sfRenderWindow_create can be used, so lines 12 + 13 can be replaced by

auto window = sfRenderWindow_create(sfVideoMode(200, 200), "SFML works
!");

Another example: the function to check if a window is open is
sfRenderWindow_isOpen, taking a pointer to an opaque sfRenderWindow
struct as first parameter. Due to D's so called UFCS you can call this
function in two ways:

sfRenderWindow_isOpen(window); // Just like in C
window.sfRenderWindow_isOpen(); // Use member-like syntax


Thank you.

I've this code now:

--
sfRenderWindow* win = sfRenderWindow_create(sfVideoMode(200, 200), "SFML
works !", 0, null);
sfEvent* event;
while (win.sfRenderWindow_isOpen())
{
 while (win.sfRenderWindow_pollEvent(event))
 {
 if (event.type == sfEvtClosed)
 win.sfRenderWindow_close();
 }
}
-

But when compiling I got this error:

derelict.util.exception.SymbolLoadException@../../../.dub/packages/derelict-util-2.0.4/source/derelict/util/exception.d(35):
Failed to load symbol sfJoystick_getIdentification from shared library
libcsfml-window.so

Any ideas ?


You have old version of libcsfml that lacks of symbol 
sfJoystick_getIdentification. Try another version, may be build it from 
sources to have the newest one.


Re: Derelict SFML2 - structs are forward referenced

2015-12-26 Thread Lucien via Digitalmars-d-learn
On Saturday, 26 December 2015 at 10:39:29 UTC, Rene Zwanenburg 
wrote:

On Saturday, 26 December 2015 at 09:48:29 UTC, Lucien wrote:

Hello.

I want to use Derelict-SFML2 to create a simple window.
But when I compile (linked with dub and derelict-util), I have 
the following error:


src/app.d(30,20): Error: variable myproject.main.window no 
definition of struct sfRenderWindow

../../../.dub/packages/derelict-sfml2-3.0.1/source/derelict/sfml2/graphics.d(56,1):
 Error: struct derelict.sfml2.graphics.sfRenderWindow unknown size
src/app.d(31,5): Error: struct sfRenderWindow is forward 
referenced
src/app.d(32,12): Error: struct sfRenderWindow is forward 
referenced
src/app.d(35,16): Error: struct sfRenderWindow is forward 
referenced
src/app.d(38,17): Error: struct sfRenderWindow is forward 
referenced


My code: http://pastebin.com/1svZAB22

Is it a bug in Derelict-SFML2 or want did I do false ?

Hoping that you understood me with my bad English :)


sfRenderWindow is an opaque struct, so its size is unknown. 
This means you can only use pointers to them, and any 
operations on them will have to be done using SFML. So in your 
code, change sfRenderWindow to sfRenderWindow*.


Did you by any chance look at a C++ tutorial for SFML? Derelict 
binds to the C API so it looks a bit different. To create a 
window sfRenderWindow_create can be used, so lines 12 + 13 can 
be replaced by


auto window = sfRenderWindow_create(sfVideoMode(200, 200), 
"SFML works !");


Another example: the function to check if a window is open is 
sfRenderWindow_isOpen, taking a pointer to an opaque 
sfRenderWindow struct as first parameter. Due to D's so called 
UFCS you can call this function in two ways:


sfRenderWindow_isOpen(window); // Just like in C
window.sfRenderWindow_isOpen(); // Use member-like syntax


Thank you.

I've this code now:

--
sfRenderWindow* win = sfRenderWindow_create(sfVideoMode(200, 
200), "SFML works !", 0, null);

sfEvent* event;
while (win.sfRenderWindow_isOpen())
{
while (win.sfRenderWindow_pollEvent(event))
{
if (event.type == sfEvtClosed)
win.sfRenderWindow_close();
}
}
-

But when compiling I got this error:

derelict.util.exception.SymbolLoadException@../../../.dub/packages/derelict-util-2.0.4/source/derelict/util/exception.d(35):
 Failed to load symbol sfJoystick_getIdentification from shared library 
libcsfml-window.so

Any ideas ?




Re: GTKD - Get the size of the context

2015-12-26 Thread Mike Wey via Digitalmars-d-learn

On 12/25/2015 11:55 AM, TheDGuy wrote:

Hello,

i want to draw something to a GTKD context and i need the size of the
context in pixel but i don't know how i can get the pixel height and
width? Any ideas?

With best regards


You could try getting the size of the widget the context is referring to 
with getAllocation.


GtkAllocation size;
widget.getAllocation(size);

and then use size.width and size.height.

--
Mike Wey


Re: DMD -L Flag, maybe a bug?

2015-12-26 Thread Ivan Kazmenko via Digitalmars-d-learn

On Saturday, 26 December 2015 at 01:04:57 UTC, Bubbasaur wrote:

It's almost like the example in the URL you showed:

dmd test.d -LC:/gtkd/src/build/GtkD.lib


Note that -L passes flags (options) but not necessarily arguments 
or paths.  For example, I use "dmd -L/STACK:268435456" by default 
along with other options to increase the default stack size to 
256Mb.  The "/STACK:268435456" part is an OPTLINK switch, not a 
path.  Here is the list of OPTLINK switches: 
http://www.digitalmars.com/ctg/ctgLinkSwitches.html


Clearly, the forward slash (/) is reserved for switches, so the 
program will have trouble parsing paths with forward slashes.


Re: DMD -L Flag, maybe a bug?

2015-12-26 Thread anonymous via Digitalmars-d-learn

On 26.12.2015 02:04, Bubbasaur wrote:

On Friday, 25 December 2015 at 23:45:42 UTC, anonymous wrote:
It's almost like the example in the URL you showed:

dmd test.d -LC:/gtkd/src/build/GtkD.lib


Note that in the docs I linked it's `dmd hello.d -L+gtkd.lib` with a 
plus sign. I'm not sure if it's significant, but it's a difference.


Also, and this may be it, the link.exe that's distributed with dmd 
doesn't like forward slashes as path separators. You can try it with 
backslashes instead:


dmd test.d -LC:\gtkd\src\build\GtkD.lib


But if you do a search for problems like: Linking problem or Symbol
Undefined most command lines uses this: "-Lpath/to/whatever" (Without
Space). And another thing... there is other flag commonly used "-I" with
doesn't need space, so most people will assume the same for -L.


-L doesn't take a space, either. Putting a space there isn't even 
optional, it's wrong. The stuff after the space is not passed to the 
linker, it's interpreted by dmd.


Re: Derelict SFML2 - structs are forward referenced

2015-12-26 Thread Rene Zwanenburg via Digitalmars-d-learn

On Saturday, 26 December 2015 at 09:48:29 UTC, Lucien wrote:

Hello.

I want to use Derelict-SFML2 to create a simple window.
But when I compile (linked with dub and derelict-util), I have 
the following error:


src/app.d(30,20): Error: variable myproject.main.window no 
definition of struct sfRenderWindow

../../../.dub/packages/derelict-sfml2-3.0.1/source/derelict/sfml2/graphics.d(56,1):
 Error: struct derelict.sfml2.graphics.sfRenderWindow unknown size
src/app.d(31,5): Error: struct sfRenderWindow is forward 
referenced
src/app.d(32,12): Error: struct sfRenderWindow is forward 
referenced
src/app.d(35,16): Error: struct sfRenderWindow is forward 
referenced
src/app.d(38,17): Error: struct sfRenderWindow is forward 
referenced


My code: http://pastebin.com/1svZAB22

Is it a bug in Derelict-SFML2 or want did I do false ?

Hoping that you understood me with my bad English :)


sfRenderWindow is an opaque struct, so its size is unknown. This 
means you can only use pointers to them, and any operations on 
them will have to be done using SFML. So in your code, change 
sfRenderWindow to sfRenderWindow*.


Did you by any chance look at a C++ tutorial for SFML? Derelict 
binds to the C API so it looks a bit different. To create a 
window sfRenderWindow_create can be used, so lines 12 + 13 can be 
replaced by


auto window = sfRenderWindow_create(sfVideoMode(200, 200), "SFML 
works !");


Another example: the function to check if a window is open is 
sfRenderWindow_isOpen, taking a pointer to an opaque 
sfRenderWindow struct as first parameter. Due to D's so called 
UFCS you can call this function in two ways:


sfRenderWindow_isOpen(window); // Just like in C
window.sfRenderWindow_isOpen(); // Use member-like syntax


Derelict SFML2 - structs are forward referenced

2015-12-26 Thread Lucien via Digitalmars-d-learn

Hello.

I want to use Derelict-SFML2 to create a simple window.
But when I compile (linked with dub and derelict-util), I have 
the following error:


src/app.d(30,20): Error: variable myproject.main.window no 
definition of struct sfRenderWindow

../../../.dub/packages/derelict-sfml2-3.0.1/source/derelict/sfml2/graphics.d(56,1):
 Error: struct derelict.sfml2.graphics.sfRenderWindow unknown size
src/app.d(31,5): Error: struct sfRenderWindow is forward 
referenced
src/app.d(32,12): Error: struct sfRenderWindow is forward 
referenced
src/app.d(35,16): Error: struct sfRenderWindow is forward 
referenced
src/app.d(38,17): Error: struct sfRenderWindow is forward 
referenced


My code: http://pastebin.com/1svZAB22

Is it a bug in Derelict-SFML2 or want did I do false ?

Hoping that you understood me with my bad English :)