Re: How to test for equality of types?

2012-05-19 Thread Philippe Sigaud
On Fri, May 18, 2012 at 11:51 PM, Simen Kjaeraas  wrote:

> Because Wrapper!(AliasStruct).Wrap does not exist. And _error_ is not
> equal to any other type.

Yes. Wrap is included in the complete template name (Wrapper!(Wrap))
and has no independent existence.
You _can_ get access to it by exposing it as an alias, as you do in AliasStruct:

struct Wrapper(Wrap)
{
alias Wrap Wrapped; // cannot call it 'Wrap'
 ...

}


(third case)
>> false
>
>
> And here I disagree. This prints true on 2.059. Regression?

AFAICT, this should print true.

And, concerning Artur questio, on 2.059 (Linux):

 pragma(msg, is(w._wrap.Alias == AliasStruct.Alias));//   -> true
 pragma(msg, typeof(w._wrap).Alias.stringof); // -> MyStruct
 pragma(msg, AliasStruct.Alias.stringof); // -> MyStruct


unsynchronized access to primitive variables

2012-05-19 Thread luka8088

Hello to all,

I would like to know if D guarantees that access to primitive variable 
is atomic ?


I was looking for any source of information that says anything about 
unsynchronized access to primitive variables. What I want to know is if 
it is possible (in any way and any OS / hardware) for the following code 
to output anything other then 1 or 2:


import std.stdio;
import core.thread;

void main () {
  int value = 1;
  (new Thread({ value = 2; })).start();
  writeln(value);
}

Thanks !


Re: moveAt vs opIndex

2012-05-19 Thread maarten van damme
so would it be wrong to make movefront simply change the index the
front is pointing at without removing a prime?

And I'm coming from a java world so it would make sense to me to
create that range as a class that implements a range but in most
examples I see everyone using structs instead. what is the "correct"
way?


Re: How to test for equality of types?

2012-05-19 Thread Matthias Walter
On 2012-05-19 09:05, Philippe Sigaud wrote:
> On Fri, May 18, 2012 at 11:51 PM, Simen Kjaeraas  
> wrote:
> 
>> Because Wrapper!(AliasStruct).Wrap does not exist. And _error_ is not
>> equal to any other type.
> 
> Yes. Wrap is included in the complete template name (Wrapper!(Wrap))
> and has no independent existence.
> You _can_ get access to it by exposing it as an alias, as you do in 
> AliasStruct:
> 
> struct Wrapper(Wrap)
> {
> alias Wrap Wrapped; // cannot call it 'Wrap'
>  ...
> 
> }

Yes, of course you are right. This was my fault - after exposing it via
an alias, it prints true.

> (third case)
>>> false
>>
>>
>> And here I disagree. This prints true on 2.059. Regression?
> 
> AFAICT, this should print true.
> 
> And, concerning Artur questio, on 2.059 (Linux):
> 
>  pragma(msg, is(w._wrap.Alias == AliasStruct.Alias));//   -> true
>  pragma(msg, typeof(w._wrap).Alias.stringof); // -> MyStruct
>  pragma(msg, AliasStruct.Alias.stringof); // -> MyStruct

I would open a bug report with the following code which is a bit smaller
than my first wrong version:

=
module main;

struct MyStruct { }

struct AliasStruct
{
  alias MyStruct Alias;
}

struct Wrapper
{
  AliasStruct aliasStruct;
}

void main()
{
  Wrapper w;

  pragma(msg, typeof(w.aliasStruct).Alias.stringof); // -> "MyStruct"
  pragma(msg, AliasStruct.Alias.stringof); // -> "MyStruct"
  static assert(is(typeof(w.aliasStruct) == AliasStruct)); // -> true
  static assert(is(typeof(w.aliasStruct).Alias == AliasStruct.Alias));
// -> false
}
=

Best regards,

Matthias


Re: using deimos.portaudio

2012-05-19 Thread Samuele Carcagno


The missing symbol is a D symbol. You probably have to compile 
in
'deimos/portaudio.di', so in your 'dmd yourprogram.d' compile 
command

add the full path to the di file:
'dmd yourprogram.d ../path/to/deimos/portaudio.di'


Thanks, that was in fact the problem!


Re: ProjectEuler problem 35

2012-05-19 Thread Stewart Gordon

On 16/05/2012 10:46, Dmitry Olshansky wrote:


Don't ever do that. I mean allocating memory in tight cycle.
Instead use circular buffer. (just use the same array and wrap indexes)



You might as well not use a string representation at all.  At the beginning of the loop, 
calculate the number of digits in n, then pow10 = 10 ^^ (digits - 1).  Then cycle with


n = n / 10 + (n % 10) * pow10;

Stewart.


Re: How to test for equality of types?

2012-05-19 Thread Philippe Sigaud
On Sat, May 19, 2012 at 12:23 PM, Matthias Walter
 wrote:

> I would open a bug report with the following code which is a bit smaller
> than my first wrong version:
>
> =
(...)
>  pragma(msg, typeof(w.aliasStruct).Alias.stringof); // -> "MyStruct"
>  pragma(msg, AliasStruct.Alias.stringof); // -> "MyStruct"
>  static assert(is(typeof(w.aliasStruct) == AliasStruct)); // -> true
>  static assert(is(typeof(w.aliasStruct).Alias == AliasStruct.Alias));
> // -> false
> }

Seems like a pb concerning whether Alias is a type or a symbol. See
A,B,C,D below:

void main()
{
 Wrapper w;

 pragma(msg, typeof(w.aliasStruct).Alias.stringof); // -> "MyStruct"
 pragma(msg, AliasStruct.Alias.stringof); // -> "MyStruct"
 static assert(is(typeof(w.aliasStruct) == AliasStruct)); // -> true
 static assert(is(w.aliasStruct.Alias == AliasStruct.Alias)); // -> true

 alias typeof(w.aliasStruct) A; // -> OK
 //alias typeof(w.aliasStruct).Alias B; // -> NOK
 //alias A.Alias C; // -> NOK
 alias w.aliasStruct.Alias D; // -> OK

 static assert(is(A.Alias == AliasStruct.Alias)); // -> true
 //static assert(is(B == AliasStruct.Alias));
 //static assert(is(C == AliasStruct.Alias));
 static assert(is(D == AliasStruct.Alias)); // -> true
}

I think A is enough for your need, but I don't get why B and C are not
accepted (DMD 2.059, Linux)


std.concurrency.send

2012-05-19 Thread japplegame

Multithreading in D confuses me more and more.

import std.concurrency;
import std.stdio;
shared Tid tid;
void main() {
  send(cast(Tid)tid, "Hello, World");
}
void worker() {
   writeln(receiveOnly!string);
}
shared static this() {
  tid = cast(shared)spawn(&worker);
}

I hate these explicit casts. It is impossible sharing anything 
between threads without these ugly casts from/to shared. Seems 
like something wrong in program design when I'm forced to use 
explicit casts. But I don't understand what is it exactly.


For example. I need create mutable object in one thread and send 
to another. I don't need to share this object, just create, send 
and forget. But I have no idea how make this without using shared 
attribute and casting to/from it.


Re: ProjectEuler problem 35

2012-05-19 Thread maarten van damme
A huge optimization could be made by storing and int array of already
found primes and test all primes smaller then half the to-test number.
this will speed up a lot.
Another huge improvement could be made with hardcoding everything up
to the prime 3 and then iterate with intervals of 2 instead of 1.


Re: moveAt vs opIndex

2012-05-19 Thread maarten van damme
and something partially unrelated, how do you copy a class by value?


Re: ProjectEuler problem 35

2012-05-19 Thread Jay Norwood

On Wednesday, 16 May 2012 at 09:26:45 UTC, Tiberiu Gal wrote:

hi

many claim their code solves the problem in order of ms ( 
c/pascal/haskell code)





I used the blockwise parallel sieve described here, and measured 
nice speed-ups as described in his blog.  It completes 
calculations within an L1 cache block before moving on.  Perhaps 
you can redesign you code to do the same...


http://create.stephan-brumme.com/eratosthenes/



vibe.d how build it / intall it?

2012-05-19 Thread bioinfornatics
Dear,
i do not found on vibe.d repository (github) how do a manual install.

Since i am a  linux user (Fedora) they are any documentation to explain
how install it?

after take a look from source tree i think
bin/vibe go to /usr/bin
bin/views to /usr/share/vibe.d/
source/vibe to /usr/include/d/

i think source file into source/vibe should be compiled and linked
together to do a lib, isn't it?

thanks in advance for help (how to do a manual install?)



Re: How to test for equality of types?

2012-05-19 Thread Matthias Walter
On 2012-05-19 15:28, Philippe Sigaud wrote:
> On Sat, May 19, 2012 at 12:23 PM, Matthias Walter
>  wrote:
> 
>> I would open a bug report with the following code which is a bit smaller
>> than my first wrong version:
>>
>> =
> (...)
>>  pragma(msg, typeof(w.aliasStruct).Alias.stringof); // -> "MyStruct"
>>  pragma(msg, AliasStruct.Alias.stringof); // -> "MyStruct"
>>  static assert(is(typeof(w.aliasStruct) == AliasStruct)); // -> true
>>  static assert(is(typeof(w.aliasStruct).Alias == AliasStruct.Alias));
>> // -> false
>> }
> 
> Seems like a pb concerning whether Alias is a type or a symbol. See
> A,B,C,D below:
> 
> void main()
> {
>  Wrapper w;
> 
>  pragma(msg, typeof(w.aliasStruct).Alias.stringof); // -> "MyStruct"
>  pragma(msg, AliasStruct.Alias.stringof); // -> "MyStruct"
>  static assert(is(typeof(w.aliasStruct) == AliasStruct)); // -> true
>  static assert(is(w.aliasStruct.Alias == AliasStruct.Alias)); // -> true
> 
>  alias typeof(w.aliasStruct) A; // -> OK
>  //alias typeof(w.aliasStruct).Alias B; // -> NOK
>  //alias A.Alias C; // -> NOK
>  alias w.aliasStruct.Alias D; // -> OK
> 
>  static assert(is(A.Alias == AliasStruct.Alias)); // -> true
>  //static assert(is(B == AliasStruct.Alias));
>  //static assert(is(C == AliasStruct.Alias));
>  static assert(is(D == AliasStruct.Alias)); // -> true
> }
> 
> I think A is enough for your need, but I don't get why B and C are not
> accepted (DMD 2.059, Linux)
> 

Using the current git version of dmd I realized that C works! Hence, as
a workaround it can be used by creating a local alias A and subsequently
using A.Alias in the is-expressions. But it seems odd that

"alias typeof(X).A B;" does not work but
"alias typeof(X) Y; alias Y.A B;" does.

Is this considered as a bug?

Best regards,

Matthias


Re: ProjectEuler problem 35

2012-05-19 Thread Era Scarecrow

On Saturday, 19 May 2012 at 16:43:03 UTC, Jay Norwood wrote:

On Wednesday, 16 May 2012 at 09:26:45 UTC, Tiberiu Gal wrote:

hi

many claim their code solves the problem in order of ms ( 
c/pascal/haskell code)




I used the blockwise parallel sieve described here, and 
measured nice speed-ups as described in his blog.  It completes 
calculations within an L1 cache block before moving on.  
Perhaps you can redesign you code to do the same...


http://create.stephan-brumme.com/eratosthenes/


 Curiously I've done most of these (Although not exactly as 
written). The blockwise makes sense; I've seen a prime checker JS 
somewhere that uses those exact primes and if a number wasn't 
divisible by them it was 'probably prime'.


 All of this is good material to glance over and review though :)


Re: vibe.d how build it / intall it?

2012-05-19 Thread David Nadlinger

On Saturday, 19 May 2012 at 17:28:36 UTC, bioinfornatics wrote:

Dear,
i do not found on vibe.d repository (github) how do a manual 
install.


Since i am a  linux user (Fedora) they are any documentation to 
explain

how install it?


Did you notice the »Linux« section in the readme? Except for 
installing the dependencies, it's not Debian/Ubuntu-specific…


David



Re: std.concurrency.send

2012-05-19 Thread Nathan M. Swan

On Saturday, 19 May 2012 at 13:26:20 UTC, japplegame wrote:

Multithreading in D confuses me more and more.

import std.concurrency;
import std.stdio;
shared Tid tid;
void main() {
  send(cast(Tid)tid, "Hello, World");
}
void worker() {
   writeln(receiveOnly!string);
}
shared static this() {
  tid = cast(shared)spawn(&worker);
}

I hate these explicit casts. It is impossible sharing anything 
between threads without these ugly casts from/to shared. Seems 
like something wrong in program design when I'm forced to use 
explicit casts. But I don't understand what is it exactly.


You don't need to mark Tids as shared.

For example. I need create mutable object in one thread and 
send to another. I don't need to share this object, just 
create, send and forget. But I have no idea how make this 
without using shared attribute and casting to/from it.


If you originally create it as shared, you don't need to do the 
casting.


Re: Simplified socket creation and handling

2012-05-19 Thread Nathan M. Swan

On Friday, 18 May 2012 at 06:35:59 UTC, Jarl André wrote:
I am a Java developer who is tired of java.nio and similar 
complex socket libraries.


In Java you got QuickServer, the ultimate protocol creation 
centered socket library. You don't have to write any channels 
and readers and what not. You just instantiate a server, 
configures the handlers (fill in classes that extends a handler 
interface) and there you go.


Shouldn't there exist a similar library in any programming 
language? Not doing so is assuming that developers always need 
control of the lower layers. Its not true. I care about 
protocol. Not sockets.


Is there any abstraction layers in phobos? Or is everything 
just as complex as before?


Check out arsd:
https://github.com/adamdruppe/misc-stuff-including-D-programming-language-web-stuff

I used cgi.d to make my own server easily (compile with 
-version=embedded_httpd). If you want more lower-level control, 
try a ListeningConnectionManager. To see how it's used, look at 
the code starting on line #1926.


It has some pitfalls (e.g. I can't find a good way to stop the 
server), but it is very nice in _easily_ starting up, with _zero_ 
config.


NMS


Re: directory wildcard

2012-05-19 Thread Arne

On Saturday, 19 May 2012 at 03:46:32 UTC, Jay Norwood wrote:
Here is a link to some code for the wildArgv single level 
search that I'm using.

https://github.com/jnorwood/file_utils


This is roughly how I was using it, related to your example

string[] argv;
argv ~= r"c:\partial*";
foreach( dirn; wildArgvs(argv[0..$])){
string[] argv2 = null;
argv2 ~= dirn ~ r"\path\*.d";
foreach( filen; wildArgvs(argv2[0..$])){
   do something with filen
}
}


Thanks for your help :)


Re: std.concurrency.send

2012-05-19 Thread japplegame

You don't need to mark Tids as shared.

Okay. I'm writting logger. Logger is global object and it is
running in its own separate thread (for example, writting logs to
remote database).
My application has several threads and all of them want to log
something. How to share this global logger between threads? I
think the simplest way is to share logger's thread tid and other
thread can send logs via this shared tid.
If you originally create it as shared, you don't need to do the 
casting.

Yes. I don't need to cast to shared, but inside thread I get
shared object and can't store/call/pass it without casting away
that shared attribute. Or I should make shared everyting that
have deal with shared object.
I'am trying to follow Safe D concept, but it forbids casting away
shared.


Limit number of compiler error messages

2012-05-19 Thread cal
Is there a way to limit the dmd compiler to outputting just the 
first few errors it comes across?


Re: vibe.d how build it / intall it?

2012-05-19 Thread bioinfornatics
Le samedi 19 mai 2012 à 21:40 +0200, David Nadlinger a écrit :
> On Saturday, 19 May 2012 at 17:28:36 UTC, bioinfornatics wrote:
> > Dear,
> > i do not found on vibe.d repository (github) how do a manual 
> > install.
> >
> > Since i am a  linux user (Fedora) they are any documentation to 
> > explain
> > how install it?
> 
> Did you notice the »Linux« section in the readme? Except for 
> installing the dependencies, it's not Debian/Ubuntu-specific…
> 
> David
> 

oh ok they are one line in this section very important and to use for
any distro

thanks



Re: vibe.d how build it / intall it?

2012-05-19 Thread bioinfornatics
Le dimanche 20 mai 2012 à 01:02 +0200, bioinfornatics a écrit :
> Le samedi 19 mai 2012 à 21:40 +0200, David Nadlinger a écrit :
> > On Saturday, 19 May 2012 at 17:28:36 UTC, bioinfornatics wrote:
> > > Dear,
> > > i do not found on vibe.d repository (github) how do a manual 
> > > install.
> > >
> > > Since i am a  linux user (Fedora) they are any documentation to 
> > > explain
> > > how install it?
> > 
> > Did you notice the »Linux« section in the readme? Except for 
> > installing the dependencies, it's not Debian/Ubuntu-specific…
> > 
> > David
> > 
> 
> oh ok they are one line in this section very important and to use for
> any distro
> 
> thanks
> 

In fact vibe.d is not a lib but a third part to add to build with your
code isn'it?



Re: std.concurrency.send

2012-05-19 Thread Nathan M. Swan

On Saturday, 19 May 2012 at 21:13:14 UTC, japplegame wrote:

You don't need to mark Tids as shared.

Okay. I'm writting logger. Logger is global object and it is
running in its own separate thread (for example, writting logs 
to

remote database).
My application has several threads and all of them want to log
something. How to share this global logger between threads? I
think the simplest way is to share logger's thread tid and other
thread can send logs via this shared tid.


public:
void startLogger(LogConstructorArgs args) {
loggerTid = spawn(&loggerThread, args);
}

void log(string msg, OtherOptions oo) {
loggerTid.send(LogMsg(msg, oo));
}

void stopLogger() {
loggerTid.send(QuitMsg());
}

private:
Tid loggerTid;

struct LogMsg {
string msg;
OtherOptions oo;
}

struct QuitMsg {}

void loggerThread(LogConstructorArgs args) {
Logger lg = new Logger(args);
bool cont = true;
while(cont) {
receive((LogMsg lm) { lg.log(lm.msg, lm.oo); },
(QuitMsg qm) { cont = false; });
}
}

If you originally create it as shared, you don't need to do 
the casting.

Yes. I don't need to cast to shared, but inside thread I get
shared object and can't store/call/pass it without casting away
that shared attribute. Or I should make shared everyting that
have deal with shared object.
I'am trying to follow Safe D concept, but it forbids casting 
away

shared.


If you are passing objects between threads, make it shared. This 
might seem annoying, but in general you should try to shift your 
thinking into having thread-local objects and communicating via 
structs.


But when you use global/singleton objects (any case where there's 
one instance of the class), convert it into a thread, FROM


class  {
this() {

}

void () {
// ...
}

int () {
int result;
// ...
return result;
}

 // you encapsulate and have no public 
fields, right?

}

TO

void Thread() {


bool cont = true;
while(cont) {
receive(
(Msg) {
// ...
},
(Tid r, Msg) {
int result;
// ...
r.send(ReturnMsg(result));
}
(QuitMsg qm) {cont = false;});
}
}



Re: std.concurrency.send

2012-05-19 Thread japplegame

public:
void startLogger(LogConstructorArgs args) {
loggerTid = spawn(&loggerThread, args);
}

void log(string msg, OtherOptions oo) {
loggerTid.send(LogMsg(msg, oo));
}

void stopLogger() {
loggerTid.send(QuitMsg());
}

private:
Tid loggerTid;

struct LogMsg {
string msg;
OtherOptions oo;
}

struct QuitMsg {}

void loggerThread(LogConstructorArgs args) {
Logger lg = new Logger(args);
bool cont = true;
while(cont) {
receive((LogMsg lm) { lg.log(lm.msg, lm.oo); },
(QuitMsg qm) { cont = false; });
}
}
I don't understand. In this way I should call 
startLogger/stopLogger in every application thread because 
loggerTid is thread related and every application thread has its 
own instanse of loggerTid. Instead N+1 threads (N application and 
1 logger) we will get 2*N threads (N application and N loggers). 
Also we should synchronize Logger class because many instances of 
them will run concurrently. This is terrible.
If you are passing objects between threads, make it shared. 
This might seem annoying, but in general you should try to 
shift your thinking into having thread-local objects and 
communicating via structs.


But when you use global/singleton objects (any case where 
there's one instance of the class), convert it into a thread, 
FROM


class  {
this() {

}

void () {
// ...
}

int () {
int result;
// ...
return result;
}

 // you encapsulate and have no public 
fields, right?

}

TO

void Thread() {


bool cont = true;
while(cont) {
receive(
(Msg) {
// ...
},
(Tid r, Msg) {
int result;
// ...
r.send(ReturnMsg(result));
}
(QuitMsg qm) {cont = false;});
}
}

Intresting idea. I will try it. Thanks.



Re: How to test for equality of types?

2012-05-19 Thread Philippe Sigaud
> Using the current git version of dmd I realized that C works! Hence, as
> a workaround it can be used by creating a local alias A and subsequently
> using A.Alias in the is-expressions. But it seems odd that
>
> "alias typeof(X).A B;" does not work but
> "alias typeof(X) Y; alias Y.A B;" does.
>
> Is this considered as a bug?

I should say so: it's surprising, and limiting for the user.


Re: How to test for equality of types?

2012-05-19 Thread Kenji Hara

On Saturday, 19 May 2012 at 18:17:16 UTC, Matthias Walter wrote:

On 2012-05-19 15:28, Philippe Sigaud wrote:

On Sat, May 19, 2012 at 12:23 PM, Matthias Walter
 wrote:

I would open a bug report with the following code which is a 
bit smaller

than my first wrong version:

=

(...)
 pragma(msg, typeof(w.aliasStruct).Alias.stringof); // -> 
"MyStruct"

 pragma(msg, AliasStruct.Alias.stringof); // -> "MyStruct"
 static assert(is(typeof(w.aliasStruct) == AliasStruct)); // 
-> true
 static assert(is(typeof(w.aliasStruct).Alias == 
AliasStruct.Alias));

// -> false
}


Seems like a pb concerning whether Alias is a type or a 
symbol. See

A,B,C,D below:

void main()
{
 Wrapper w;

 pragma(msg, typeof(w.aliasStruct).Alias.stringof); // -> 
"MyStruct"

 pragma(msg, AliasStruct.Alias.stringof); // -> "MyStruct"
 static assert(is(typeof(w.aliasStruct) == AliasStruct)); // 
-> true
 static assert(is(w.aliasStruct.Alias == AliasStruct.Alias)); 
// -> true


 alias typeof(w.aliasStruct) A; // -> OK
 //alias typeof(w.aliasStruct).Alias B; // -> NOK
 //alias A.Alias C; // -> NOK
 alias w.aliasStruct.Alias D; // -> OK

 static assert(is(A.Alias == AliasStruct.Alias)); // -> true
 //static assert(is(B == AliasStruct.Alias));
 //static assert(is(C == AliasStruct.Alias));
 static assert(is(D == AliasStruct.Alias)); // -> true
}

I think A is enough for your need, but I don't get why B and C 
are not

accepted (DMD 2.059, Linux)



Using the current git version of dmd I realized that C works! 
Hence, as
a workaround it can be used by creating a local alias A and 
subsequently

using A.Alias in the is-expressions. But it seems odd that

"alias typeof(X).A B;" does not work but
"alias typeof(X) Y; alias Y.A B;" does.

Is this considered as a bug?

Best regards,

Matthias


It seems to me that is a regression by fixing bug 6475.
Now I'm trying to fix them.