Is -1 > 7 ?

2013-08-09 Thread michaelc37
forgive me if i'm doing something stupid, i'm extremely tired and 
trying to avoid drinking coffee.


void main()
{
int[] arr = [0, 1, 2, 3, 4, 5, 6];

//check 1
if (-1 > arr.length)
writefln("WTF -> %d is greater than %d ", -1, arr.length);
else
writefln("GOOD -> %d is NOT greater than %d", -1, arr.length);
}

here is my output:
WTF -> -1 is greater than 7 


Re: Is -1 > 7 ?

2013-08-09 Thread michaelc37

On Friday, 9 August 2013 at 15:18:47 UTC, Dicebot wrote:

On Friday, 9 August 2013 at 15:11:42 UTC, michaelc37 wrote:
forgive me if i'm doing something stupid, i'm extremely tired 
and trying to avoid drinking coffee.


void main()
{
int[] arr = [0, 1, 2, 3, 4, 5, 6];

//check 1
if (-1 > arr.length)
		writefln("WTF -> %d is greater than %d ", -1, 
arr.length);

else
		writefln("GOOD -> %d is NOT greater than %d", -1, 
arr.length);

}

here is my output:
WTF -> -1 is greater than 7 


And signed vs unsigned design issues pops up again! :) 
*summoning bearophile*


On topic: arr.length has type size_t which is unsigned integer. 
-1 gets silently casted to unsigned, resulting in size_t.max 
value (0xFFF..) - which is obviously bigger than actual length.


I believe it should be a compile-time error but, unfortunately, 
this is unlikely to happen.


Ahhh thanks for the explaination. if this was a compile time 
error, i would have saved precious time; I found strange behavior 
while writing some other related code, and I kept overlooking the 
condition thinking "it cant be that".


Re: Is -1 > 7 ?

2013-08-09 Thread michaelc37

http://d.puremagic.com/issues/show_bug.cgi?id=259
https://github.com/D-Programming-Language/dmd/pull/1913

Looks like there has a pending fix for 4 months.


Auto-Implemented properties

2013-01-05 Thread michaelc37

i was trying to make a D template to mimic auto-implemented
properties in c#.

I think i got it to work but when i tried to give the template a
more meaning full name like AutoImplementedProperty i get a
compile error "a.title is not an lvalue".
Is this a bug?
Is there a more suitable way of doing this?

c# e.g:
class Bar
{
public string Title { get; set; }
}

my attempt:
class Bar
{
alias autoproperty!(string, "get", "set") title
}

template autoproperty(T, args...)
{
import std.typetuple;
@property
{   
private T _name;
static if (args.length)
{
static if (staticIndexOf!("get", args) > -1)
{
public T autoproperty()
{
return _name;
}   
}

static if (staticIndexOf!("set", args) > -1)
{
public void autoproperty(T value)
{
_name = value;
}
}

}
}
}

void main(string[] args)
{
Bar a = new Bar();
a.title = "asf";  
writefln(a.title);

return;
}


Re: Auto-Implemented properties

2013-01-05 Thread michaelc37
On Saturday, 5 January 2013 at 22:53:44 UTC, Philippe Sigaud 
wrote:

Hi Michael,

your code works for me (DMD 2.061, Linux), with a semicolon 
after the alias

in class Bar.

Also, use writeln, not writefln, because writefln assumes the 
first

parameter is the formatting string.


Thanks for the tip.
Does it work for you if you rename the template to 
"AutoImplementedProperty"?


Re: Auto-Implemented properties

2013-01-05 Thread michaelc37

On Saturday, 5 January 2013 at 23:00:48 UTC, monarch_dodra wrote:
On Saturday, 5 January 2013 at 22:53:44 UTC, Philippe Sigaud 
wrote:

Hi Michael,

your code works for me (DMD 2.061, Linux), with a semicolon 
after the alias

in class Bar.

Also, use writeln, not writefln, because writefln assumes the 
first

parameter is the formatting string.


Why would you want get/set though when D offers property 
functions?


The argument of "if your public attribute becomes private, then 
code breaks" is invalid in D.


I'm not sure if i ever would use the template, but anyway I was 
having a cs vs d argument with a friend, and we ended up writing 
code samples for comparison.


This is just one of the items that came up.


Re: Auto-Implemented properties

2013-01-06 Thread michaelc37

On Sunday, 6 January 2013 at 11:32:40 UTC, Jacob Carlborg wrote:

On 2013-01-05 23:40, michaelc37 wrote:

i was trying to make a D template to mimic auto-implemented
properties in c#.

I think i got it to work but when i tried to give the template 
a

more meaning full name like AutoImplementedProperty i get a
compile error "a.title is not an lvalue".
Is this a bug?
Is there a more suitable way of doing this?

c# e.g:
class Bar
{
public string Title { get; set; }
}

my attempt:
class Bar
{
alias autoproperty!(string, "get", "set") title
}

template autoproperty(T, args...)
{
import std.typetuple;
@property
{
private T _name;
static if (args.length)
{
static if (staticIndexOf!("get", args) > -1)
{
public T autoproperty()
{
return _name;
}
}

static if (staticIndexOf!("set", args) > -1)
{
public void autoproperty(T value)
{
_name = value;
}
}

}
}
}

void main(string[] args)
{
Bar a = new Bar();
a.title = "asf";
writefln(a.title);

return;
}


This won't work like you think it will. All instances of "Bar" 
will share the same "_name" variable.


You need to use a mixin. This pass:

void main ()
{
Bar a = new Bar();
a.title = "asf";

Bar b = new Bar;
assert(b.title == a.title);
}


Yea i realized that later, but the only fix i could come up with 
required me passing the property name in the template parameters, 
so the declaration has changed a bit.


second attempt;

class Bar
{
public mixin autoproperty!(string, "title", "get", "set");
public mixin autoproperty!(string, "description", "get", "set");
}

mixin template autoproperty(T, alias propertyName, args...)
{
import std.typetuple;

mixin("private T _" ~ propertyName ~ ";");

@property
{   
static if (args.length)
{
static if (staticIndexOf!("get", args) > -1)
{
mixin("
T " ~ propertyName ~ "()
{
return _" ~ propertyName ~ ";   
  
}");
}

static if (staticIndexOf!("set", args) > -1)
{
mixin("
void " ~ propertyName ~ "(T value)
{
_" ~ propertyName ~ " = value;
}");
}   
}
}   
}




Re: monodevelop mono-d versions

2014-08-01 Thread michaelc37 via Digitalmars-d-learn

On Friday, 1 August 2014 at 09:12:49 UTC, sclytrack wrote:
I'm on Ubuntu 14.04 LTS and it has version 4.0.12 of 
MonoDevelop. Has anybody else got this to work with this 
version?




I have had no problems using this ppa ppa:ermshiperete/monodevelop
it has packages for versions 4 and 5:
monodevelop-4.0
monodevelop-5





Re: Invoking MAGO debugger

2015-02-26 Thread michaelc37 via Digitalmars-d-learn
On Thursday, 26 February 2015 at 10:20:31 UTC, Vadim Lopatin 
wrote:

Hello!

I'm trying to integrate MAGO into DlangIDE.

I can easy create instance of MAGO DebugEngine, but having 
problems with obtaining of IDebugPort which is needed for 
invoking of LaunchSuspended.
It looks like to get IDebugPort, I need IDebugCoreServer2 
instance.

Does anybody know how to do it?
Normally, it's being created by VisualStudio AFAIK.


Best regards,
Vadim


I once remember pulling out my hair trying todo the same in order 
to get it to work with a monodevelop win32 debugger addon.


It resulted in a writing new clr wrapper with a different exposed 
interface

https://github.com/aBothe/MagoWrapper

e.g. of how the debugee was was launched here:
https://github.com/aBothe/MagoWrapper/blob/master/DebugEngine/MagoWrapper/NativeDebugger.cpp


Re: Debugging D in MonoDevelop, finding multiple gdb processes?

2015-06-10 Thread michaelc37 via Digitalmars-d-learn

i am assuming you are using the built in gdb debugger.

a) you can try using this addin Gdb.D instead 
-https://github.com/llucenic/MonoDevelop.Debugger.Gdb.D

it might be also be in the monodevelop beta repos.

b) you can "fix"/work around the issue by replacing 
"Syscall.kill" in the source 
(https://github.com/mono/monodevelop/blob/master/main/src/addins/MonoDevelop.Debugger.Gdb/GdbSession.cs)

with "proc.Kill()"
similarly as what was done in the Gdb.D source 
(https://github.com/llucenic/MonoDevelop.Debugger.Gdb.D/blob/master/Gdb/GdbSession.cs)

then recompile and use.

On Wednesday, 10 June 2015 at 20:46:11 UTC, Rodger Beats wrote:
I'm new to the language and new to using MonoDevelop and I've 
got this persistent problem that I haven't been able to solve 
with Google searching. I frequently test out my code as I write 
it and every time I start it up a new gdb process will start 
running but not terminate at the end of the program. Even a 
nothing program like the following will start up a new gdb 
process that won't terminate:


int main( string[] args ){
return 0;
}

After testing out an application a few times I have to open my 
process manager and clear out one gdb for every time I ran the 
program. I'm using Linux Mint 17 x64.


Does anyone know how I can configure gdb to exit when a program 
has exited successfully?




Re: Load Qt UI XML File as GUI

2015-09-17 Thread michaelc37 via Digitalmars-d-learn

On Wednesday, 16 September 2015 at 04:03:46 UTC, Mike McKee wrote:
Unfortunately, the http://dsource.org/forums/ doesn't appear to 
be active -- I can't login after I registered. This is where 
the QtD project has their forum. So, I'm asking this here.


Is it possible with D and QtD to draw my GUI using QtCreator, 
and then take its UI XML file and load it somehow via QtD and 
D? That way, I don't need to do everything by hand and can 
utilize the power of a WYSIWYG form tool (like Glade), and then 
just manipulate the rest by code after that?


As an alternative, you could try qml bindings from 
https://github.com/filcuc/dqml