Re: Threading errors.

2010-07-27 Thread Rory Mcguire
Philippe Sigaud wrote:

> On Mon, Jul 26, 2010 at 19:11, dcoder  wrote:
> 
>> == Quote from Rory Mcguire (rjmcgu...@gm_no_ail.com)'s article
>> > Dmitry Olshansky wrote:
>>
> 
> 
> std.typecons.Tuple fields cannot be indexed like arrays, Andrei made a
> mistake. To access field  #n, use ._n or .field[n]. There is no difference
> between the two.
> 
> void writer() {
>  for( ;; ) {
>auto msg = receiveOnly!(Tid, int)(); // msg is a Tuple!(Tid, int),
>msg._0
> is a Tid, msg._1 is an int.
>writeln( "Secondary thread: ", msg._1);
>msg._0.send(thisTid);
>  }
> }
> 
> Also, in my case, the return; in writer must be commented out, or DMD
> complains it cannot be reached.
> 
> 
> Philippe


Interesting, I didn't have to comment out return; using dmd 2.047 on linux


Re: Threading errors.

2010-07-27 Thread Philippe Sigaud
On Tue, Jul 27, 2010 at 11:25, Rory Mcguire  wrote:

>
> > Also, in my case, the return; in writer must be commented out, or DMD
> > complains it cannot be reached.
>


>
> Interesting, I didn't have to comment out return; using dmd 2.047 on linux
>

I think I have -w (warnings treated as errors?) always checked. That's my
Code::Blocks default configuration for DMD.
I was on Windows for this test. I never cheked if there was any difference
between OSes for this :-)


Re: Threading errors.

2010-07-27 Thread Rory Mcguire
Philippe Sigaud wrote:

> On Tue, Jul 27, 2010 at 11:25, Rory Mcguire 
> wrote:
> 
>>
>> > Also, in my case, the return; in writer must be commented out, or DMD
>> > complains it cannot be reached.
>>
> 
> 
>>
>> Interesting, I didn't have to comment out return; using dmd 2.047 on
>> linux
>>
> 
> I think I have -w (warnings treated as errors?) always checked. That's my
> Code::Blocks default configuration for DMD.
> I was on Windows for this test. I never cheked if there was any difference
> between OSes for this :-)

:) thanks Philippe


D and cygwin io.

2010-07-27 Thread dcoder
Hello.  Here's a short program that works in a dos window:

import std.stdio;

void main() {

  writef( "What is your name?");

  string name = readln();
  writefln( "Hello " ~ name);
}

The program prints a prompt without a newline and the user enters a name and a
greeting is printed.

The same program does not seem to work when at a cygwin prompt.  The program
seems to pause.  It is actually waiting for input.  So, if I type in a name
and hit return, the prompt and the greeting appears as expected but on one line.

I can change writef to writefln and it will work on the cygwin prompt and on
the dos prompt, but now a newline will be added after the prompt message.

I'm wondering how can I fix this?  I am using bash shell on cygwin.


thanks.



Re: Threading errors.

2010-07-27 Thread dcoder
== Quote from Rory Mcguire (rjmcgu...@gm_no_ail.com)'s article
> Philippe Sigaud wrote:
> >> > Also, in my case, the return; in writer must be commented out, or DMD
> >> > complains it cannot be reached.
> >>
> >
> >
> >>
> >> Interesting, I didn't have to comment out return; using dmd 2.047 on
> >> linux
> >>
> >
> > I think I have -w (warnings treated as errors?) always checked. That's my
> > Code::Blocks default configuration for DMD.
> > I was on Windows for this test. I never cheked if there was any difference
> > between OSes for this :-)
> :) thanks Philippe


Actually, after making the changes that you suggest, Philippe my program works.
Thanks.

However, I did not have to comment out the return statement.  But when I did
compile using the -w flag, I do get the compiler error that you describe.

Anyways, thanks for the coding suggestion.


Re: D and cygwin io.

2010-07-27 Thread Rory Mcguire
dcoder wrote:

> Hello.  Here's a short program that works in a dos window:
> 
> import std.stdio;
> 
> void main() {
> 
>   writef( "What is your name?");
> 
>   string name = readln();
>   writefln( "Hello " ~ name);
> }
> 
> The program prints a prompt without a newline and the user enters a name
> and a greeting is printed.
> 
> The same program does not seem to work when at a cygwin prompt.  The
> program
> seems to pause.  It is actually waiting for input.  So, if I type in a
> name and hit return, the prompt and the greeting appears as expected but
> on one line.
> 
> I can change writef to writefln and it will work on the cygwin prompt and
> on the dos prompt, but now a newline will be added after the prompt
> message.
> 
> I'm wondering how can I fix this?  I am using bash shell on cygwin.
> 
> 
> thanks.


try flushing the output after the write: stdout.flush();


Re: Threading errors.

2010-07-27 Thread Sean Kelly
The next release, 2.048, should bring things in line with TDPL.  I had meant to 
do this for 2.047, but was too busy with other work to finish in time.


Re: struct opCall error messages

2010-07-27 Thread Jacob Carlborg

On 2010-07-26 14:27, Rory Mcguire wrote:

Hi,

I'm not sure this is in bugzilla, I tried finding something mentioning it
but coudn't.

Compiling the below code results in the dmd compiler printing:
struct_bad_error.d(8): Error: 'this' is only defined in non-static member
functions, not inner


struct S {
S opCall() {S s; return s;}
}
void main() {
S s;
//s = S(); // decent error message: "struct_bad_error.d(6):
// Error: need 'this' to access member opCall"
void inner() {
s = S();
}
}
=

What to do? Also found that having an empty () after the struct name is not
the best error message: "struct_bad_error.d(5): Error: struct
struct_bad_error.S() is used as a type"

Surely it could tell me I need to put an Identifier in the ()

-Rory


Perhaps you want a static opCall ?

S foo;
foo(); // calls opCall
S(); // calls static opCall

--
/Jacob Carlborg


D2 map trouble

2010-07-27 Thread Nick Sabalausky
Trying to convert some D1 code to D2:

On 2.047, I'm trying to do this:

import std.string;
void foo(string str)
{
str =
  std.algorithm.map!(
   (char a) { return inPattern(a, [digits, letters])? a : '_'; }
  )(str);
}

And I'm getting:

delegate std.algorithm.__dgliteral1 cannot access frame of function 
__dgliteral1

What's going on? How do I do it right? I figure I probably have some sort of 
problem with strings being immutable(char)[] instead of char[], but it 
doesn't look like that's the issue it's complaining about. Also, in this 
particular case, I'm not concerned about multi-unit UTF-8 characters.




Re: D2 map trouble

2010-07-27 Thread Nick Sabalausky
"Nick Sabalausky"  wrote in message 
news:i2no7g$eu...@digitalmars.com...
> Trying to convert some D1 code to D2:
>
> On 2.047, I'm trying to do this:
>
> import std.string;
> void foo(string str)
> {
> str =
>  std.algorithm.map!(
>   (char a) { return inPattern(a, [digits, letters])? a : '_'; }
>  )(str);
> }
>
> And I'm getting:
>
> delegate std.algorithm.__dgliteral1 cannot access frame of function 
> __dgliteral1
>
> What's going on? How do I do it right? I figure I probably have some sort 
> of problem with strings being immutable(char)[] instead of char[], but it 
> doesn't look like that's the issue it's complaining about. Also, in this 
> particular case, I'm not concerned about multi-unit UTF-8 characters.
>
>

In my particular case, I've just switched to regex:

import std.regex;
str = replace(str, regex("[^a-zA-Z0-9]"), "_");

But I am still curious to hear what exactly was going on with map.




Re: D2 map trouble

2010-07-27 Thread Dmitry Olshansky

On 28.07.2010 3:06, Nick Sabalausky wrote:

"Nick Sabalausky"  wrote in message
news:i2no7g$eu...@digitalmars.com...
   

Trying to convert some D1 code to D2:

On 2.047, I'm trying to do this:

import std.string;
void foo(string str)
{
str =
  std.algorithm.map!(
   (char a) { return inPattern(a, [digits, letters])? a : '_'; }
  )(str);
}

And I'm getting:

delegate std.algorithm.__dgliteral1 cannot access frame of function
__dgliteral1

What's going on? How do I do it right? I figure I probably have some sort
of problem with strings being immutable(char)[] instead of char[], but it
doesn't look like that's the issue it's complaining about. Also, in this
particular case, I'm not concerned about multi-unit UTF-8 characters.


 

In my particular case, I've just switched to regex:

import std.regex;
str = replace(str, regex("[^a-zA-Z0-9]"), "_");

But I am still curious to hear what exactly was going on with map.


   
AFAIK weird compiler bug. See also thread about std.find which involves 
the problem with map 
http://www.digitalmars.com/d/archives/digitalmars/D/Improving_std.algorithm.find_113545.html#N113558



--
Dmitry Olshansky



D1->D2 member call syntax regression?

2010-07-27 Thread Nick Sabalausky
In converting some D1 code to D2, I noticed this doesn't seem to work 
anymore:

module mymodule;
class Foo()
{
void bar(string s) {...}

void foo()
{
string str = "hello";
str.bar();
}
}

In D1 that works fine, but in D2 (2.047) it complains that it can't find 
"mymodule.bar". That's a bit dissapointing, as I keep hoping member call 
syntax will eventually get expanded, not reduced. Is this a bug, or is there 
some reason for it?




Re: D1->D2 member call syntax regression?

2010-07-27 Thread Jonathan M Davis
On Tuesday, July 27, 2010 16:25:28 Nick Sabalausky wrote:
> In converting some D1 code to D2, I noticed this doesn't seem to work
> anymore:
> 
> module mymodule;
> class Foo()
> {
> void bar(string s) {...}
> 
> void foo()
> {
> string str = "hello";
> str.bar();
> }
> }
> 
> In D1 that works fine, but in D2 (2.047) it complains that it can't find
> "mymodule.bar". That's a bit dissapointing, as I keep hoping member call
> syntax will eventually get expanded, not reduced. Is this a bug, or is
> there some reason for it?

It looks more like a bug fix to me given that the first parameter to bar() is 
the 
invisible this rather than a string, but since I've never used D1, I certainly 
can't compare what it does to D2.

- Jonathan M Davis


Re: D1->D2 member call syntax regression?

2010-07-27 Thread bearophile
It seems to work, on 2.042, and on dmd 2.047:
http://ideone.com/dcsK3

Bye,
bearophile


How do I get an array from filter's result?

2010-07-27 Thread Nick Sabalausky
On 2.047, this:

import std.algorithm;
import std.array;
void main()
{
string[] result =
array(
filter!( (string a) { return a != "b"; } )
(["a", "b", "c"])
);
}

Gives me this:

testfilter.d(6): Error: template std.array.array(Range) if 
(isForwardRange!(Range)) does not match any function template declaration
testfilter.d(6): Error: template std.array.array(Range) if 
(isForwardRange!(Range)) cannot deduce template function from argument types 
!()(Filter!(__dgliteral1,string[])) 




Re: How do I get an array from filter's result?

2010-07-27 Thread Jonathan M Davis
On Tuesday, July 27, 2010 17:24:27 Nick Sabalausky wrote:
> On 2.047, this:
> 
> import std.algorithm;
> import std.array;
> void main()
> {
> string[] result =
> array(
> filter!( (string a) { return a != "b"; } )
> (["a", "b", "c"])
> );
> }
> 
> Gives me this:
> 
> testfilter.d(6): Error: template std.array.array(Range) if
> (isForwardRange!(Range)) does not match any function template declaration
> testfilter.d(6): Error: template std.array.array(Range) if
> (isForwardRange!(Range)) cannot deduce template function from argument
> types !()(Filter!(__dgliteral1,string[]))

The forward range stuff is broken in 2.047. save() was added to the definition 
for 
isForwardRange(), but a bunch of forward ranges didn't get it added. It's been 
fixed in svn.

- Jonathan M Davis


Re: D1->D2 member call syntax regression?

2010-07-27 Thread Nick Sabalausky
"bearophile"  wrote in message 
news:i2nqs5$js...@digitalmars.com...
> It seems to work, on 2.042, and on dmd 2.047:
> http://ideone.com/dcsK3
>
> Bye,
> bearophile

That's because my original example accidentally made Foo an uninstantiated 
class template, so the compiler never bothered to check the semantics...

The following fails on 2.046 and 2.042, but works fine on 1.062:

class Foo {
void bar(string s) {}
void foo() {
string str = "hello";
str.bar();
}
}
void main() {} 




Re: D1->D2 member call syntax regression?

2010-07-27 Thread Nick Sabalausky
"Nick Sabalausky"  wrote in message 
news:i2o9ev$1e4...@digitalmars.com...
> "bearophile"  wrote in message 
> news:i2nqs5$js...@digitalmars.com...
>> It seems to work, on 2.042, and on dmd 2.047:
>> http://ideone.com/dcsK3
>>
>> Bye,
>> bearophile
>
> That's because my original example accidentally made Foo an uninstantiated 
> class template, so the compiler never bothered to check the semantics...
>
> The following fails on 2.046 and 2.042, but works fine on 1.062:
>
> class Foo {
>void bar(string s) {}
>void foo() {
>string str = "hello";
>str.bar();
>}
> }
> void main() {}

The above also fails on 2.047 




Re: Threading errors.

2010-07-27 Thread Philippe Sigaud
On Tue, Jul 27, 2010 at 19:03, Sean Kelly  wrote:

> The next release, 2.048, should bring things in line with TDPL.  I had
> meant to do this for 2.047, but was too busy with other work to finish in
> time.
>

Do you mean, indexing tuples directly by a CT value as in msg[1]? Because
that was the only error here, I think.