Re: Is it reasonable to learn D

2011-06-14 Thread Lloyd Dupont

Too late! :P
I have been inspired by the simplicity of D and DGui.
Never happened before with earlier C++ experiments... my loss!

Jose Armando Garcia  wrote in message 
news:mailman.906.1308016642.14074.digitalmars-d-le...@puremagic.com...


On Mon, Jun 13, 2011 at 6:33 AM, Lloyd Dupont ld-rem...@galador.net wrote:

Let's learn together then! :P
http://galador.net/codeblog/?tag=/D

While my blog post are only about setting up the environment so far.. I 
have

delved in the code for 2 weeks now! (Although I had some day off (work and
programing) in Darwin) I'm right into it now, should have a new blog post
soon! About programing this time!

My verdict: it's frustrating yes. But D has a couple of advantages and 2
that you might like:
- D has event / delegate, just like C# (and unlike C++, or maybe C++ has
them, (it has method pointer, right!?) but it's not taken advantage of!)
- the above point is probably what makes the C++ GUI so... difficult.
Whereas I found a GUI API for D just like WinForm! (DGui!)



Boost, GTK+ and QT have signals. E.g.
http://www.boost.org/doc/libs/1_46_1/doc/html/signals.html 



need some template help!

2011-06-14 Thread Lloyd Dupont
I'm writing some manual reflection (a bit more automatism will come later, 
thanks to __traits and mixin)(hopefully)

There are a few problems with my implementation so far...

- First the implementation:

 system.reflection.member.d =
module system.reflection.member;

public:

public enum MemberType
{
   Bool,
   Int,
   Object = 100,
}

class MemberDesc
{
   MemberType mtype;
   string name;

   union
   {
   bool delegate() getbool;
   byte delegate() getyte;
   int delegate() getint;
   Object delegate() getobject;
   }

   this(string name, bool delegate() getbool)
   {
   this.name = name;
   this.mtype = MemberType.Bool;
   this.getbool = getbool;
   }

   this(string name, int delegate() getint)
   {
   this.name = name;
   this.mtype = MemberType.Int;
   this.getint = getint;
   }

   this(string name, Object delegate() getobject)
   {
   this.name = name;
   this.mtype = MemberType.Object;
   this.getobject = getobject;
   }
}
= test.d =
module test;

import system.reflection.property;

class Foo
{
   private int _abc;
   @property public int ABC() { return _abc; }
   @property public void ABC(int value) { _abc = value; }

   private Foo _foo;
   @property public Foo FOO() { return _foo; }
   @property public void FOO(Foo value) { _foo = value; }

   MemberDesc[string] getmembers;

   this()
   {
   getmembers[ABC] = new MemberDesc(ABC, ABC);
   getmembers[FOO] = new MemberDesc(FOO, delegate Object() { return 
FOO(); });

   }

   override string toString()
   {
   return format(Foo(%s, %s), ABC, FOO);
   }
}


- now the problems:

1./ getmembers is an instance variable (i.e. not static) because.. it 
contains delegate!
ideally it should be static! how could I have this working with a static 
getmembers?


2./ the very different syntax for the constructor of MemberDesc for ABC and 
FOO
(ABC, and delegate Object() { return FOO(); }) how could I automate 
that (with mixin, __traits and foreach)


3./ I'd like the getmembers declaration and / or initialization being in a 
(mixin?) template. is that possible? how?


Thanks for any tip(S)! :) 



strange compiler (linker) error

2011-06-14 Thread Lloyd Dupont

I have DMD2.053, on Windows.
I just moved my folder around.

I compile with the following command line:
==
dmd -lib -g -unittest -debug -w -wi -X -XfDebug\dinstall.json -ofDebug\dinstall.lib 
-deps=Debug\dinstall.dep -map Debug\dinstall.map -L/NOMAP 
@Debug\dinstall.build.rsp

==


I got the following error, what the heck that could mean?
==
Error: multiple definition of format_b8_a15: _D10format.18412__ModuleInfoZ 
and format: _D10format.18412__ModuleInfoZ

Building Debug\dinstall.lib failed!
== 



Re: introspection experiment

2011-06-14 Thread Adam D. Ruppe
While my code is ugly as sin, it might be useful to look at the
prepareReflection function in my web.d

http://arsdnet.net/dcode/web.d


It uses the derived members trait to loop through them all, and
create a runtime delegate that converts a string hash into it's
arguments and it's return value into a variety of formats.

End result is you can do:

reflection.objects[Foo].functions[ABC].dispatcher(...);

to call the function. It's got some assumptions in there to work
with web urls and returns things wrapped in json values, but the
bulk of it might be useful to you.


Re: Undefined function, even though imported

2011-06-14 Thread Trass3r

Am 14.06.2011, 02:43 Uhr, schrieb Loopback elliott.darf...@gmail.com:


Thanks for all the answers! Seems like rdmd did the trick.
I don't see why this isn't built in to dmd though


No one does ;)


I've also stumbled upon an additional error with the win32 DirectX
bindings, but this seems D related actually. When I compile any code
at all (with rdmd) which imports win32.directx.d3d9 and uses the
function Direct3DCreate9, the linker issues this warning:

Error 42: Symbol Undefined _Direct3DCreate9@4


So the other functions in d3d9 work but only this one doesn't?



Both of these links says that the problem is solved by adding
_Direct3DCreate9 to imports. I've tried to do this by linking to a
.def file with this content (without success, same error is still
issued).

EXETYPE NT
SUBSYSTEM WINDOWS

IMPORTS
_Direct3DCreate9@4=d3d9.Direct3DCreate9


^^ This can't work cause the linker knows nothing about D modules.
You'd have to use the correct D mangled name.


It's dsss live ?

2011-06-14 Thread Zardoz
I'm learning D2, and  puxxled when I see that something usefull like dsss, 
looks that not have any updte for too long time. In his SVN, show that not have 
any update in
years!!! (or I'm blind).

It's dsss dead ??



Re: It's dsss live ?

2011-06-14 Thread Robert Clipsham

On 14/06/2011 18:30, Zardoz wrote:

I'm learning D2, and  puxxled when I see that something usefull like dsss, 
looks that not have any updte for too long time. In his SVN, show that not have 
any update in
years!!! (or I'm blind).

It's dsss dead ??



dsss hasn't been updated in years, you are correct - best not to use it. 
There is a lot of interest in a D build tool/package manager, one 
doesn't exist currently though.


--
Robert
http://octarineparrot.com/


Re: Is there any convenient CopyMemory function in Phobos?

2011-06-14 Thread Andrej Mitrovic
On 6/14/11, Johannes Pfau s...@example.com wrote:
 The druntime C bindings follow the names of the C
 header files. memcpy is in 'string.h' in C -- 'core.stdc.string' in D.

I assume the reason for this was because C requires strcpy and memcpy
all the time when copying strings?


Shared/const/immutable does not propagate to hash keys

2011-06-14 Thread Andrej Mitrovic
shared int[int] AA;
shared int[] arr;

void main()
{
arr = AA.keys;
}

Error: cannot implicitly convert expression (AA.keys()) of type int[]
to shared(int[])

Workaround:

shared int[shared(int)] AA;
shared int[] arr;

void main()
{
arr = AA.keys;
}

Shouldn't shared propagate to the entire type?
The same thing seems to happen with const and immutable:

const int[const(int)] CONST = [1:1];
auto arr1 = CONST.keys;
writeln(typeid(arr1));  // const(int)[]

const int[int] NOTCONST = [1:1];
auto arr2 = NOTCONST.keys;
writeln(typeid(arr2));  // int[]

But .values doesn't suffer from the issue:

import std.stdio;
shared (int[int]) AA;

void main()
{
auto arr1 = AA.keys;
auto arr2 = AA.values;
writeln(typeid(arr1));  // writes int[]
writeln(typeid(arr2));  // writes shared(int)[]
}


Re: Undefined function, even though imported

2011-06-14 Thread Loopback

Well, I solved the linker error by specifying imports in the
.def file. The pathetic thing was that the def file was invalid
just because I had a newline, or at least it worked without it.

So my final .def file looks like this:

EXETYPE NT
SUBSYSTEM WINDOWS
IMPORTS
_Direct3DCreate9@4 = d3d9.Direct3DCreate9

Thanks for all help!


Re: It's dsss live ?

2011-06-14 Thread Nick Sabalausky
Zardoz luis.panad...@gmail.com wrote in message 
news:it8g8k$1kbo$1...@digitalmars.com...
 And bud, rebuild and others Any recomendation or what are live actualy 
 and works with D2 ?

rdmd

It's included with DMD, but I'd highly recommend grabbing the latest version 
off of GitHub, which has all the major problems fixed: 
https://github.com/D-Programming-Language/tools

Go to that link, download the rdmd.d file, compile it with DMD 2.053 like 
this:

dmd rdmd.d

And then, you can build your entire program like this:

rdmd --build-only -ofmain [any other build flags you want here] main.d




Re: Shared/const/immutable does not propagate to hash keys

2011-06-14 Thread Jonathan M Davis
On 2011-06-14 13:11, Andrej Mitrovic wrote:
 shared int[int] AA;
 shared int[] arr;
 
 void main()
 {
 arr = AA.keys;
 }
 
 Error: cannot implicitly convert expression (AA.keys()) of type int[]
 to shared(int[])
 
 Workaround:
 
 shared int[shared(int)] AA;
 shared int[] arr;
 
 void main()
 {
 arr = AA.keys;
 }
 
 Shouldn't shared propagate to the entire type?
 The same thing seems to happen with const and immutable:
 
 const int[const(int)] CONST = [1:1];
 auto arr1 = CONST.keys;
 writeln(typeid(arr1)); // const(int)[]
 
 const int[int] NOTCONST = [1:1];
 auto arr2 = NOTCONST.keys;
 writeln(typeid(arr2)); // int[]
 
 But .values doesn't suffer from the issue:
 
 import std.stdio;
 shared (int[int]) AA;
 
 void main()
 {
 auto arr1 = AA.keys;
 auto arr2 = AA.values;
 writeln(typeid(arr1)); // writes int[]
 writeln(typeid(arr2)); // writes shared(int)[]
 }

The thing is that the keys for an AA _must_ be immutable, even if you don't 
mark it as such. So, const means nothing for them. And I don't think that 
shared does either, because immutable variables are implicitly shared. So, I'm 
not sure that what you're trying to do even makes sense. As far as the keys 
and values properties go, I believe that they're generated from the AA and are 
copies of the values - not the originals (though obviously in the case of 
references or pointers, the stuff which is referred to or pointed to isn't 
copied - just the reference or pointer). So, why would the result be shared? 
It might work with the values but certainly not with the keys which have to be 
immutable.

- Jonathan M Davis


Re: Shared/const/immutable does not propagate to hash keys

2011-06-14 Thread Andrej Mitrovic
Right, right, I forgot all about that keys are immutable by default
(or should be). This makes perfect sense now, thanks for the reality
slap. :p