Re: Mac OS crash, details inside...

2013-06-14 Thread Jacob Carlborg

On 2013-06-13 19:42, Gary Willoughby wrote:

I get a program crash each time running the following code on MacOS 10.8
(Lion). It seems to run ok on Ubuntu 12.04:

import core.sys.posix.sys.stat;
import core.sys.posix.unistd;
import std.c.stdio;
import std.c.stdlib;
import std.process;
import std.stdio;
import std.string;
import std.file;

int main(string[] args)
{
 pid_t pid, sid;

 pid = fork();
 if (pid  0)
 {
 exit(EXIT_FAILURE);
 }

 if (pid  0)
 {
 exit(EXIT_SUCCESS);
 }

 umask(0);

 sid = setsid();
 if (sid  0)
 {
 exit(EXIT_FAILURE);
 }

 if ((core.sys.posix.unistd.chdir(/))  0)
 {
 exit(EXIT_FAILURE);
 }

 close(STDIN_FILENO);
 close(STDOUT_FILENO);
 close(STDERR_FILENO);

 auto logFile = File(/home/gary/Desktop/test.log, a);
 logFile.writeln(Reading file);

 string command = format(logger -t %s %s, hello, This is a test);
 executeShell(command);

 logFile.writeln(Done);

 return 0;
}


You do know that you usually don't have a /home/ directory on Mac OS X? 
On Mac OS X it's called /Users/.


BTW, running that on Mac OS X 10.6.3 does not cause a crash. Although it 
doesn't seem to print or write anything.


--
/Jacob Carlborg


Re: Unqual fails with pointer?

2013-06-14 Thread Namespace

Thank you.


Re: Mac OS crash, details inside...

2013-06-14 Thread Gary Willoughby
You do know that you usually don't have a /home/ directory on 
Mac OS X? On Mac OS X it's called /Users/.


Yeah, that was me running the same code on Ubuntu.

BTW, running that on Mac OS X 10.6.3 does not cause a crash. 
Although it doesn't seem to print or write anything.


That's the problem i can't pin down. It writes the above log file 
to /var/log/system.log. other than that there is no feedback at 
all, the program just ends without writing to the open file.


It seems to be related to the daemon code as it doesn't happen 
when that code is commented out.


Re: Mac OS crash, details inside...

2013-06-14 Thread Gary Willoughby
In fact i have the same problem reading files too. It only reads 
files up to a certain amount of bytes then crashes in the same 
manner explained above. Again this only happens when the program 
runs as a daemon.




Re: List all enum in a class

2013-06-14 Thread Bruno Deligny

On Thursday, 13 June 2013 at 17:13:26 UTC, Adam D. Ruppe wrote:

On Thursday, 13 June 2013 at 17:05:43 UTC, Bruno Deligny wrote:

i tried your test and it doesn't print test.


Maybe we have different versions of the compiler (I think this 
behavior recently changed).


Try running dmd without arguments and see what the first line 
says. Mine is:


DMD32 D Compiler v2.063


2.062

I will try with the 2.063


Re: List all enum in a class

2013-06-14 Thread Bruno Deligny

On Friday, 14 June 2013 at 11:44:45 UTC, Bruno Deligny wrote:

On Thursday, 13 June 2013 at 17:13:26 UTC, Adam D. Ruppe wrote:

On Thursday, 13 June 2013 at 17:05:43 UTC, Bruno Deligny wrote:

i tried your test and it doesn't print test.


Maybe we have different versions of the compiler (I think this 
behavior recently changed).


Try running dmd without arguments and see what the first line 
says. Mine is:


DMD32 D Compiler v2.063


2.062

I will try with the 2.063


I doesn't work with 2.063


[Doubt] Variadic arguments as reference (Possible?)

2013-06-14 Thread MattCoder

Hi,

I want to know if there is a way to pass variadic arguments as 
reference? DMD says no!


I wrote the snippet code below, but what I want to do in fact is 
assign the sum back to respective variables to use somewhere else.


http://dpaste.dzfl.pl/515edfb8

or

import std.stdio;
import std.conv;

void sum(double value, in double[] numbers ...){
foreach(num; numbers)
writeln(num+value);
}

void main(){
auto a = 1, b = 2, c = 3;
sum(10, a, b, c);

writeln(a = ~to!string(a),
\nb = ~to!string(b),
\nc = ~to!string(c));
}

Thanks,

Matheus.


Re: [Doubt] Variadic arguments as reference (Possible?)

2013-06-14 Thread Regan Heath

On Fri, 14 Jun 2013 13:55:29 +0100, MattCoder mattco...@gmail.com wrote:
I want to know if there is a way to pass variadic arguments as  
reference? DMD says no!


import std.stdio;
import std.conv;

void sum(double value, double*[] numbers ...){
foreach(ref num; numbers)
*num = *num + value;
}

void main(){
double a = 1, b = 2, c = 3;
sum(10, a, b, c);

writeln(a = ~to!string(a),
\nb = ~to!string(b),
\nc = ~to!string(c));
}

R
--
Using Opera's revolutionary email client: http://www.opera.com/mail/


Re: [Doubt] Variadic arguments as reference (Possible?)

2013-06-14 Thread MattCoder

On Friday, 14 June 2013 at 13:20:26 UTC, Regan Heath wrote:

import std.stdio;
import std.conv;

void sum(double value, double*[] numbers ...){
foreach(ref num; numbers)
*num = *num + value;
}

void main(){
double a = 1, b = 2, c = 3;
sum(10, a, b, c);

writeln(a = ~to!string(a),
\nb = ~to!string(b),
\nc = ~to!string(c));
}

R


Hi Regan,

My fault, I thought that those variadics only works with in 
after I assume wrong from 
(http://ddili.org/ders/d.en/parameter_flexibility.html), but your 
code works well.


Thanks,

Matheus.


Re: [Doubt] Variadic arguments as reference (Possible?)

2013-06-14 Thread MattCodrr

On Friday, 14 June 2013 at 13:24:18 UTC, bearophile wrote:

One way to do it, but beware of template bloat:

import std.stdio;

void sum(TArgs...)(double value, ref TArgs numbers) {
foreach (ref num; numbers) // Note: this is a static 
foreach.

num += value;
}

void main() {
auto a = 1, b = 2, c = 3;

writeln(a,  , b,  , c);
sum(10, a, b, c);
writeln(a,  , b,  , c);
}




Hi bearophile,

I know that I don't specified on my first post, but since I need
a generic type parameter on my real problem, your ref TArgs seems
to fit nicely.

Thanks.


Re: Strange seg fault

2013-06-14 Thread Ali Çehreli

On 06/13/2013 09:11 AM, Ali Çehreli wrote:

On 06/12/2013 11:56 PM, gedaiu wrote:

  How should i submit this bug?

You can reduce it to a minimal program first and then submit at

   http://d.puremagic.com/issues/


Thank you for submitting it:

  http://d.puremagic.com/issues/show_bug.cgi?id=10356

Ali



Re: Error: cannot uniquely infer foreach argument types

2013-06-14 Thread Agustin

On Friday, 14 June 2013 at 17:17:46 UTC, bearophile wrote:

Agustin:

Hello, i'm trying to create a library with utilities classes 
like containers using Java API.


The problem with this is that most Phobos works with ranges...



Could anyone help me?


Maybe your code has multiple problems. If you want a precise 
answer, then give a complete little program. But a possible 
problem is in the opApply:


int opApply(int delegate(ref E) delegation);

If you want to use:

foreach (i, e; it) {

Then you need to put both in the opApply (or add a second 
opApply overload), something like:


int opApply(int delegate(ref int, ref E) delegation);

Bye,
bearophile


int opApply(int delegate(ref int, ref E) delegation);

Works!, thanks.


Re: A little of coordination for Rosettacode

2013-06-14 Thread bearophile

There is also one D entry in need to be fixed (with Phobos):

http://rosettacode.org/wiki/Distributed_programming#D

Bye,
bearophile


Re: A little of coordination for Rosettacode

2013-06-14 Thread Adam D. Ruppe

On Friday, 14 June 2013 at 22:17:16 UTC, bearophile wrote:

http://rosettacode.org/wiki/Distributed_programming#D


It kinda sounds like the description calls for something like 
what web.d does:


server:

import arsd.web;
class Foo : ApiProvider {
export string hello(string name) { return hello,  ~ name; }
export int add(int a, int b) { return a + b; }
}
mixin FancyMain!Foo;

client:

import arsd.curl;
import std.stdio;
void main() {
writeln(curl(http://example.com/server/hello?name=me;));
}

or javascript client:

Foo.hello(me).get(alert); // will pop up hello, me

or php client:

$api = new Foo(http://example.com/server/;);
echo $api-add(10, 20)-getSync(); // prints 30

(the code for this is generated automatically by web.d. I also 
wrote a bash [!] script to call arbitrary web.d functions 
remotely but have not actually done the same for D itself yet! 
The reason is for all my use cases, I can just call the D 
function without going through the http middle man because all 
the D is part of the same executable program. Interestingly, the 
D one would probably use a code generator like javascript rather 
than opDispatch like the bash and php examples do because the 
code generator could give more type safety.)




This is a generic protocol, can handle many things at once, and 
uses pretty natural data structures. (The returned values can be 
almost anything, but the arguments must be all types that can be 
converted from strings or arrays of strings.)



This actual example here uses several thousand lines of library 
code but if you think it would fit the description, I'm sure I 
can do a basic demo in far fewer lines using nothing but phobos.


Re: A little of coordination for Rosettacode

2013-06-14 Thread bearophile

Adam D. Ruppe:

This actual example here uses several thousand lines of library 
code but if you think it would fit the description, I'm sure I 
can do a basic demo in far fewer lines using nothing but phobos.


I think Rosettacode accepts code that uses libraries that are 
free. Take a look at the many Python entries for this task. So if 
you think this task can be implemented quickly using web.d, then 
use it :-) In some tasks I have appreciated solving the problems 
from the ground up, but in this task I think it's better to be 
lazy.


Bye,
bearophile


Clash between functions that shouldn't be in the same partial ordering set

2013-06-14 Thread TommiT
I'm pretty sure the following is a compiler bug, right? (using 
DMD 2.063)


-
module a;

void foo(char)
{
}

-
module b;

enum MyEnum : int { _ }

void foo(MyEnum)
{
}

-
module main;

import a;
import b;

void main()
{
foo(char.init);
foo(MyEnum.init); // [1]
}

// 1) Error: b.foo at b.d(5) conflicts with a.foo at a.d(3)

There shouldn't be a problem with this cross-module overloading, 
because MyEnum isn't implicitly convertible to char and vice 
versa, and thus the partial ordering of functions should consider 
a.foo and b.foo unordered.


[Sharing]Tuple to variables (My Function)

2013-06-14 Thread MattCoder

Hi,

Sooner I asked about this ([Doubt] Variadic arguments as 
reference (Possible?) - - 
http://forum.dlang.org/thread/jwujjhjizkovvmbeg...@forum.dlang.org).


In fact my intend was to recreate a feature that I like in 
Python, where you can assign variables from a tuple, e.g.:


pos = (10, 20)
x,y = Pos

or

RGB = (255,255,255)
r,g,b = RGB

Thanks to the fellows who help me early morning, I wrote the 
workable version below:


import std.stdio;
import std.typecons;
import std.variant;

void tupleToVar(A, T...)(A inTuple, ref T listParams){
  foreach(i, ref p; listParams){
if(!(iinTuple.length))
  break;

p = inTuple[i];
  }
}

void main()
{
auto myTuple = tuple(1,2,3,Test);
Variant a, b, c, d;
tupleToVar(myTuple, a, b, c, d);
writeln(a);
writeln(b);
writeln(c);
writeln(d);
}

dpaste: http://dpaste.dzfl.pl/6f3f25d0

It would be nice if it could appear more like python, but I think 
this would be a internal dev.


Matheus.


Re: A little of coordination for Rosettacode

2013-06-14 Thread Adam D. Ruppe

On Friday, 14 June 2013 at 22:44:40 UTC, bearophile wrote:

So if you think this task can be implemented quickly using
web.d, then use it :-)


I just think it is really cool that D can do that kind of thing, 
so a brief implementation might be good to show people how it is 
done.


I'll see about slapping something together over the weekend and 
posting it here.


Re: A little of coordination for Rosettacode

2013-06-14 Thread bearophile

Adam D. Ruppe:

I'll see about slapping something together over the weekend and 
posting it here.


If you use a library, please also give the link to the library, 
so I can create a nearly empty page on Rosettacode about it. It's 
kind of needed.


Bye,
bearophile


Re: [Sharing]Tuple to variables (My Function)

2013-06-14 Thread bearophile

MattCoder:


void tupleToVar(A, T...)(A inTuple, ref T listParams){


I think in the C++11 STL a similar function is named tie.



if(!(iinTuple.length))
  break;


You have to verify in the function constraint that the lengths 
match.



It would be nice if it could appear more like python, but I 
think this would be a internal dev.


There is a DIP about it, but it's currently stalled:
http://wiki.dlang.org/DIP32

Bye,
bearophile


Re: [Sharing]Tuple to variables (My Function)

2013-06-14 Thread MattCoder

On Saturday, 15 June 2013 at 00:47:01 UTC, bearophile wrote:
You have to verify in the function constraint that the lengths 
match.


In fact that was intentional, because sometimes I just want few 
items from a tuple not all.


For example:

auto RGB = tuple(255, 125, 50);
Variant r,g;
tupleToVar(RGB, r, g); // I just want the red and green values 
from a tuple


Matheus.


Re: Error: cannot uniquely infer foreach argument types

2013-06-14 Thread Ali Çehreli

On 06/14/2013 10:25 AM, Agustin wrote:

 int opApply(int delegate(ref int, ref E) delegation);

 Works!, thanks.

I have just completed the translation of the foreach with Structs and 
Classes chapter:


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

Ali



Automatic Equation and Inequation evaluation.

2013-06-14 Thread Carlos
I'm interested in this kind of functionalities does D have 
something on this ?


I thought about something like a eval function that would use 
specified algorithms.

something likes this

import std.stdio, std.math, atd.eval;

eval(Real a+b+c^^x=56){
algor.brute;
writeln(Real,  , Positive value(;
}


Re: Automatic Equation and Inequation evaluation.

2013-06-14 Thread Carlos

On Saturday, 15 June 2013 at 01:31:23 UTC, Carlos wrote:
I'm interested in this kind of functionalities does D have 
something on this ?


I thought about something like a eval function that would use 
specified algorithms.

something likes this

import std.stdio, std.math, atd.eval;

eval(Real a+b+c^^x=56){
algor.brute;
writeln(Real,  , Positive value(;
}


import std.stdio, std.math, std.eval;

void main()
{
eval(Real; a+b^^x+c=56){
algor.brute(result);
   }
writeln(Positive value is : , result);
}


Re: Clash between functions that shouldn't be in the same partial ordering set

2013-06-14 Thread Jonathan M Davis
On Saturday, June 15, 2013 01:09:28 TommiT wrote:
 I'm pretty sure the following is a compiler bug, right? (using
 DMD 2.063)
 
 -
 module a;
 
 void foo(char)
 {
 }
 
 -
 module b;
 
 enum MyEnum : int { _ }
 
 void foo(MyEnum)
 {
 }
 
 -
 module main;
 
 import a;
 import b;
 
 void main()
 {
 foo(char.init);
 foo(MyEnum.init); // [1]
 }
 
 // 1) Error: b.foo at b.d(5) conflicts with a.foo at a.d(3)
 
 There shouldn't be a problem with this cross-module overloading,
 because MyEnum isn't implicitly convertible to char and vice
 versa, and thus the partial ordering of functions should consider
 a.foo and b.foo unordered.

It certainly looks like a bug to me.

- Jonathan M Davis


how should I implement this list?

2013-06-14 Thread Bedros
I'm converting some  code into D while learning D and need some 
help to implement this



I have a node of struct { ulong mask; ulong value};

now I need to create a list and insert that node; but first I 
don't need duplicates, so, I first check if node already exists 
in list.


I also need to traverse the list, and remove a node

currently I'm using dynamic array in D, but it's not efficient; 
is there a better way to do the following


insert with no duplicates
remove
traverse
find

I read about containers in D, but the documentation is confusing; 
and not sure if container implementation is mature.


BTW, my code will generate 100s of millions of nodes, and each 
node on average is used once or twice then removed


I'll appreciate it if someone points me to some examples or 
documentation of a feature in D.


Thanks in advance

Bedros


Re: Clash between functions that shouldn't be in the same partial ordering set

2013-06-14 Thread TommiT

On Saturday, 15 June 2013 at 02:39:31 UTC, Jonathan M Davis wrote:

On Saturday, June 15, 2013 01:09:28 TommiT wrote:

I'm pretty sure the following is a compiler bug, right? (using
DMD 2.063)

-
module a;

void foo(char)
{
}

-
module b;

enum MyEnum : int { _ }

void foo(MyEnum)
{
}

-
module main;

import a;
import b;

void main()
{
foo(char.init);
foo(MyEnum.init); // [1]
}

// 1) Error: b.foo at b.d(5) conflicts with a.foo at a.d(3)

There shouldn't be a problem with this cross-module 
overloading,

because MyEnum isn't implicitly convertible to char and vice
versa, and thus the partial ordering of functions should 
consider

a.foo and b.foo unordered.


It certainly looks like a bug to me.

- Jonathan M Davis


Bug report there:
http://d.puremagic.com/issues/show_bug.cgi?id=10361