Re: Ping qznc: Re: A little of coordination for Rosettacode

2013-07-03 Thread Marco Leise
Am Sat, 22 Jun 2013 23:27:00 +0200
schrieb "bearophile" :

> Ali Çehreli:
> 
> > The code compiles under 32-bit (e.g. with the -m32 compiler 
> > switch) where size_t is an alias of uint.
> 
> Oh, I see. I compile most of the code on a 32 bit system.
> 
> I asked Walter to warn d programmers against such mistakes, and 
> Walter closed it down. Someone else has opened the ER again...

That would be me. Let's see where it goes.
 
> Bye,
> bearophile

-- 
Marco



Re: Ping qznc: Re: A little of coordination for Rosettacode

2013-06-23 Thread Brian Rogoff

On Saturday, 22 June 2013 at 21:27:01 UTC, bearophile wrote:

Ali Çehreli:

The code compiles under 32-bit (e.g. with the -m32 compiler 
switch) where size_t is an alias of uint.


Thanks, Ali! I'm always compiling on 64 bit systems; I'll add the 
32 bit switch to my diagnostic approach now.



Oh, I see. I compile most of the code on a 32 bit system.

I asked Walter to warn d programmers against such mistakes, and 
Walter closed it down. Someone else has opened the ER again...


In general, I think implicit conversions of any kind are a 
misfeature, but better error messages would be enough for me 
here. At least in Scala, you need to bring the conversion into 
scope yourself, or have it accidentally imported...


Thanks for your help.

-- Brian


Re: Ping qznc: Re: A little of coordination for Rosettacode

2013-06-22 Thread bearophile
I asked Walter to warn d programmers against such mistakes, and 
Walter closed it down. Someone else has opened the ER again...


I meant this:
http://d.puremagic.com/issues/show_bug.cgi?id=5063

In the meantime I have fixed the Rosettacode entry.

Bye,
bearophile


Re: Ping qznc: Re: A little of coordination for Rosettacode

2013-06-22 Thread bearophile

Ali Çehreli:

The code compiles under 32-bit (e.g. with the -m32 compiler 
switch) where size_t is an alias of uint.


Oh, I see. I compile most of the code on a 32 bit system.

I asked Walter to warn d programmers against such mistakes, and 
Walter closed it down. Someone else has opened the ER again...


Bye,
bearophile


Re: Ping qznc: Re: A little of coordination for Rosettacode

2013-06-22 Thread Ali Çehreli

On 06/22/2013 11:53 AM, Brian Rogoff wrote:

> The current D code for Dining philosophers does not compile with dmd
> v2.063.2, the error message being
>
> dining.d(34): Error: cannot uniquely infer foreach argument types

The code compiles under 32-bit (e.g. with the -m32 compiler switch) 
where size_t is an alias of uint.


>   4void eat(in uint i, in string name, Mutex[] forks) {

1) Replace that uint with size_t:

void eat(in size_t i, in string name, Mutex[] forks) {

>  34  foreach (uint i, philo; taskPool.parallel(philosophers)) {

2) Remove that uint:

  foreach (i, philo; taskPool.parallel(philosophers)) {

Ali



Re: Ping qznc: Re: A little of coordination for Rosettacode

2013-06-22 Thread bearophile

Brian Rogoff:

The current D code for Dining philosophers does not compile 
with dmd v2.063.2, the error message being


dining.d(34): Error: cannot uniquely infer foreach argument 
types


I try to keep the D entries on Rosettacode updated, but every dmd 
release breaks tons of code, and Rosettacode has almost one 
thousand D programs (many tasks have two or more D entries, to 
show different solutions or different coding style, or to show 
code with different tradeoffs, etc), so you find some broken 
programs.


I don't know what's changed in taskPool.parallel, I will 
investigate later. Or you can investigate yourself if you want.



BTW, I like the coding style being used in the rosetta examples 
and TDPL much better than the library style.


I try to keep the D code on Rosettacode with a quite uniform 
style. It follows the dstyle, the main difference is the opening 
brace that's in Egyptian style, but such brace style is required 
only in Phobos, while the dstyle does not require the Phobos 
style for all D code, it's in "Additional Requirements for 
Phobos":

http://dlang.org/dstyle.html

Later,
bearophile


Re: Ping qznc: Re: A little of coordination for Rosettacode

2013-06-22 Thread Brian Rogoff

On Saturday, 16 February 2013 at 11:30:00 UTC, Jos van Uden wrote:

On 16-2-2013 8:58, qznc wrote:

On Saturday, 16 February 2013 at 06:58:01 UTC, qznc wrote:
On Saturday, 16 February 2013 at 02:23:42 UTC, Jos van Uden 
wrote:

On 5-2-2013 20:45, Jos van Uden wrote:

By the way, I think 'Qznc' may want to have a look at 'The 
dining

philosophers':

http://rosettacode.org/wiki/Dining_philosophers


I should find the time to solve it this weekend.


Wow, my kid let me do some hacking right now and it was 
simpler than expected.

Posted a solution already.


Wow, that was quick. Thanks!


The current D code for Dining philosophers does not compile with 
dmd v2.063.2, the error message being


dining.d(34): Error: cannot uniquely infer foreach argument types

The code looks OK to me (but I'm a D newbie) so I wonder if 
someone could explain the inference issue. Where should an 
annotation be added to allow this to compile?



 1	import std.stdio, std.algorithm, std.string, 
std.parallelism,

 2core.sync.mutex;
 3  
 4  void eat(in uint i, in string name, Mutex[] forks) {
 5writeln(name, " is hungry.");
 6  
 7immutable j = (i + 1) % forks.length;
 8  
 9	  // Take forks i and j. The lower one first to prevent 
deadlock.

10auto fork1 = forks[min(i, j)];
11auto fork2 = forks[max(i, j)];
12  
13fork1.lock();
14scope(exit) fork1.unlock();
15  
16fork2.lock();
17scope(exit) fork2.unlock();
18  
19writeln(name, " is eating.");
20writeln(name, " is full.");
21  }
22  
23  void think(in string name) {
24writeln(name, " is thinking.");
25  }
26  
27  void main() {
28	  const philosophers = "Aristotle Kant Spinoza Marx 
Russell".split();

29Mutex[philosophers.length] forks;
30foreach (ref fork; forks)
31  fork = new Mutex();
32  
33defaultPoolThreads = forks.length;
34	  foreach (uint i, philo; taskPool.parallel(philosophers)) 
{

35  foreach (_; 0 .. 100) {
36eat(i, philo, forks);
37think(philo);
38  }
39}
40  }

BTW, I like the coding style being used in the rosetta examples 
and TDPL much better than the library style.


-- Brian





Re: Ping qznc: Re: A little of coordination for Rosettacode

2013-02-16 Thread Jos van Uden

On 16-2-2013 8:58, qznc wrote:

On Saturday, 16 February 2013 at 06:58:01 UTC, qznc wrote:

On Saturday, 16 February 2013 at 02:23:42 UTC, Jos van Uden wrote:

On 5-2-2013 20:45, Jos van Uden wrote:


By the way, I think 'Qznc' may want to have a look at 'The dining
philosophers':

http://rosettacode.org/wiki/Dining_philosophers


I should find the time to solve it this weekend.


Wow, my kid let me do some hacking right now and it was simpler than expected.
Posted a solution already.


Wow, that was quick. Thanks!


Re: Ping qznc: Re: A little of coordination for Rosettacode

2013-02-16 Thread bearophile

monarch_dodra:

I'm reporting it instead of correcting it directly, so as to 
better explain how and why.


Thank you, some bugs are interesting. I will change the code.

Bye,
bearophile


Re: Ping qznc: Re: A little of coordination for Rosettacode

2013-02-16 Thread monarch_dodra

On Saturday, 16 February 2013 at 07:58:56 UTC, qznc wrote:

On Saturday, 16 February 2013 at 06:58:01 UTC, qznc wrote:
On Saturday, 16 February 2013 at 02:23:42 UTC, Jos van Uden 
wrote:

On 5-2-2013 20:45, Jos van Uden wrote:

By the way, I think 'Qznc' may want to have a look at 'The 
dining

philosophers':

http://rosettacode.org/wiki/Dining_philosophers


I should find the time to solve it this weekend.


Wow, my kid let me do some hacking right now and it was simpler 
than expected.

Posted a solution already.


Hum...

//
Mutex[5] forks = new Mutex();
//

This will allocate a single Mutex, and place the same reference 
in all five entries of forks.


In a word: There is actually only one fork. The philosophers can 
still dine, because a single thread is allowed to lock the same 
resource twice, making the problem trivial. Basically, they are 
dual wielding the fork ;)


The correct line of code should be:
//
Mutex[5] forks;
foreach(ref fork; forks) fork = new Mutex();
//

Or some variation thereof of course. The code still works with 
this change.


I'm reporting it instead of correcting it directly, so as to 
better explain how and why.


Re: Ping qznc: Re: A little of coordination for Rosettacode

2013-02-16 Thread qznc

On Saturday, 16 February 2013 at 06:58:01 UTC, qznc wrote:
On Saturday, 16 February 2013 at 02:23:42 UTC, Jos van Uden 
wrote:

On 5-2-2013 20:45, Jos van Uden wrote:

By the way, I think 'Qznc' may want to have a look at 'The 
dining

philosophers':

http://rosettacode.org/wiki/Dining_philosophers


I should find the time to solve it this weekend.


Wow, my kid let me do some hacking right now and it was simpler 
than expected.

Posted a solution already.


Re: Ping qznc: Re: A little of coordination for Rosettacode

2013-02-15 Thread qznc

On Saturday, 16 February 2013 at 02:23:42 UTC, Jos van Uden wrote:

On 5-2-2013 20:45, Jos van Uden wrote:

By the way, I think 'Qznc' may want to have a look at 'The 
dining

philosophers':

http://rosettacode.org/wiki/Dining_philosophers


Am I the new rosetta concurency guy? :)

I should find the time to solve it this weekend.