Re: Static Associative Arrays

2012-04-08 Thread Caligo
On Sat, Apr 7, 2012 at 11:01 PM, Jonathan M Davis jmdavisp...@gmx.com wrote:

 What do you mean my static associative arrays? Are you asking why you can't
 initialize a static variable which is an AA at compile time? e.g.

 - Jonathan M Davis

The same way I can create a static array:

int[4] = [1, 3, 4, 8];  // has value semantics

and dynamic arrays:

int[] = [1, 4, 2, 4];  // has reference semantics

I want an associative array that has value semantics and it's size
doesn't change, just like static arrays.

P.S.
another point.  I was always under the impression that static arrays
are allocated on the stack whereas dynamic arrays are allocated on the
heap and the GC cleans them up.  After today, I'm not so sure if this
is true.  Are static arrays allocated on the stack?  if so, that would
be another reason to want to have static associative arrays.


Re: Static Associative Arrays

2012-04-08 Thread Jonathan M Davis
On Sunday, April 08, 2012 01:24:02 Caligo wrote:
 On Sat, Apr 7, 2012 at 11:01 PM, Jonathan M Davis jmdavisp...@gmx.com 
wrote:
  What do you mean my static associative arrays? Are you asking why you
  can't
  initialize a static variable which is an AA at compile time? e.g.
  
  - Jonathan M Davis
 
 The same way I can create a static array:
 
 int[4] = [1, 3, 4, 8];  // has value semantics
 
 and dynamic arrays:
 
 int[] = [1, 4, 2, 4];  // has reference semantics
 
 I want an associative array that has value semantics and it's size
 doesn't change, just like static arrays.

Associative arrays are always on the heap. They always have reference 
semantics. It would be very expensive to have an AA with value semantics. They 
contains pointers all over the place. It would be equivalent to calling dup on 
them every time that you pass them to anything. And trying to put one on the 
stack would get very messy because all of the pointers involved. AAs are 
_completely_ different from dynamic and static arrays. Aside from the fact that 
they both have array in their name and both allow indexing of a sort, there's 
really no relation between them at all.

 P.S.
 another point.  I was always under the impression that static arrays
 are allocated on the stack whereas dynamic arrays are allocated on the
 heap and the GC cleans them up.  After today, I'm not so sure if this
 is true.  Are static arrays allocated on the stack?  if so, that would
 be another reason to want to have static associative arrays.

Yes. static arrays go on the stack and are value types, whereas dynamic arrays 
go no the heap and are reference types which are managed by the GC. If you 
want more details on how arrays work, read this:

http://dlang.org/d-array-article.html

- Jonathan M davis


Re: string concatenation

2012-04-08 Thread Andrej Mitrovic
On 4/8/12, dnewbie r...@myopera.com wrote:
 I have a wchar[] and I want to convert it to UTF8
 then append a string. This is my code.

 import std.c.windows.windows;
 import std.string;
 import std.utf;

 int main()
 {
wchar[100] v;
v[0] = 'H';
v[1] = 'e';
v[2] = 'l';
v[3] = 'l';
v[4] = 'o';
v[5] = 0;
string s = toUTF8(v) ~ , world!;
MessageBoxA(null, s.toStringz, myapp, MB_OK);
return 0;
 }

You're using a wide string, then converting it to UTF8, and then
converting that to a zero-terminated string for a function that
expects ASCII.

Just use this:
string s = Hello world!;
MessageBoxA(null, s.toStringz, myapp, MB_OK);


Re: Win GUI Single Exe - Newbie

2012-04-08 Thread Jacob Carlborg

On 2012-04-07 23:34, vmars316 wrote:

On Saturday, 7 April 2012 at 12:25:27 UTC, Jacob Carlborg wrote:

On 2012-04-06 17:37, Jesse Phillips wrote:



Building stand alone executables with DWT works great. DWT doesn't
depend on any third party libraries, only on the system libraries.


I downloaded and installed dinstaller.exe using this HowTo:
http://www.youtube.com/watch?v=kSugYSC5hrEfeature=related
What would I need to have installed to run DWT?


1. Clone this git repository: https://github.com/d-widget-toolkit/dwt
2. Pull down the submodules base and org.eclipse.swt.win32.win32.x86 
by running:


$ git submodule init
$ git submodule update

3. Build the library by running:

$ rake base swt

Ruby and rake is needed for the above command. Or the source code can be 
used directly. Both base and swt is needed.


These import libraries are also needed (for some things):


How about VisualD, is it any good?
Any recommends would be greatly appreciated.
Thanks...vmars


I've heard it's good, but I haven't used it myself.

--
/Jacob Carlborg


Re: asm stackframe question

2012-04-08 Thread Stefan

On Sunday, 8 April 2012 at 01:15:48 UTC, Timon Gehr wrote:

The D calling convention leaves stack cleanup up to the callee. 
Either mark your function as extern(C) or use


leave
ret 16

The second option might not be portable across all currently 
available compilers though.


Hi Timon,

Works fine, thanks!

I don't worry too much about compatibility - GCD uses a 
completely different ASM notation anyway.


Cheers,

Stefan


Re: asm stackframe question

2012-04-08 Thread Stefan

On Saturday, 7 April 2012 at 23:50:42 UTC, bearophile wrote:

Use the naked attribute and do it all by yourself?


Then I would also have to do the throw
a) fully by myself (with mangling, etc), or
b) at least get the stack frame in order so that the throw finds 
the stack the way it expects...


Keep also in mind that D functions that contain ASM don't get 
inlined in DMD (and probably elsewhere too).


Yes, but I don't have much of a choice here...

Cheers,
Stefan


DMD/Windows: Inspect generated ASM?

2012-04-08 Thread Stefan

Hi all,

Which is the most convenient way to have a look at the ASM code 
generated by Win-dmd? Unlike gdc, dmd it has no -S option, so I 
guess I will have to disassemble .obj files.


Any good tools for this (link)? So far I only found old .obj 
tools from the 90s on the web...


Thanks,

Stefan


Re: DMD/Windows: Inspect generated ASM?

2012-04-08 Thread dennis luehring

ida 5.0 freeware

http://www.hex-rays.com/products/ida/support/download_freeware.shtml

Am 08.04.2012 14:42, schrieb Stefan:

Hi all,

Which is the most convenient way to have a look at the ASM code
generated by Win-dmd? Unlike gdc, dmd it has no -S option, so I
guess I will have to disassemble .obj files.

Any good tools for this (link)? So far I only found old .obj
tools from the 90s on the web...

Thanks,

Stefan




Re: string concatenation

2012-04-08 Thread bearophile

dnewbie:


   string s = toUTF8(v) ~ , world!;
   MessageBoxA(null, s.toStringz, myapp, MB_OK);
   return 0;
}


I suggest to compile all your code with -property plus -w (or 
-wi), unless you have some specific needs to not do it.


Bye,
bearophile


Re: DMD/Windows: Inspect generated ASM?

2012-04-08 Thread Andrej Mitrovic
On 4/8/12, Stefan ste...@schuerger.com wrote:
 Any good tools for this (link)? So far I only found old .obj
 tools from the 90s on the web...

I use objconv. http://www.agner.org/optimize/#objconv

I use this batch script to disasm an .obj file and open the .asm file:
@echo off
setlocal EnableDelayedExpansion
objconv -fnasm %~nx1 %~n1_disasm.asm  %~n1_disasm.asm

I forgot by now just how those %~ thingies work. Windows batch is a
funny language.


Re: GC-less tutorial?

2012-04-08 Thread Tove

On Saturday, 7 April 2012 at 17:31:02 UTC, Artur Skawina wrote:

On 04/07/12 17:25, Tove wrote:

Hi,

are there any good tutorials for using D totally without GC, 
detailing some common pitfalls?


One thing on my wishlist would be a way to detect accidental 
GC allocations resulting from side-effects of every-day 
operations... generating linking errors would be sufficient 
for detecting this...


One problem with this is that the runtime wants to alloc some 
things before your
code gets to run - so you can't just remove the functions from 
the build. You're
left with either modifying the runtime or somehow ignoring the 
initial allocations
(which usually won't cause any problems). If using a custom RT 
would have been an
option you wouldn't be asking these questions (as you could 
just omit the symbols),

so...

If your platform supports gdb, try creating a text file 
trapallocs containing:


b gc_malloc
b gc_qalloc
b gc_calloc
b gc_realloc
b gc_extend

then run gdb -x ./trapallocs -ex run --args ./your_app

The debugger will stop at the first allocation and you can then 
use bt
to check what's going on, then c to skip to the next alloc. 
The first few
will come from the runtime and various module ctors, but 
anything after

that will be caused by your code, directly or indirectly.

You can also trap just the array ops with eg:

b _d_arraycatT
b _d_arraycatnT
b _d_arrayappendT
b _d_arrayappendcTp
b _d_newarrayT

etc

Once the runtime becomes a shared library simpler solutions 
will be possible,
but, until then, it doesn't get much better than this. You need 
some way to
determine which allocations are legal and which are not; 
doing this w/o

a custom runtime is probably not worth the effort...

And, yes, the initial runtime allocations could (and should) me 
made to use a
different path; some of them shouldn't happen at all. For 
example std.datetime
alone causes two allocs via _d_newclass, in every D app that 
imports std.stdio...



artur


great, thanks for the hint, I didn't think of using breakpoints 
at first... but you are right, given good enough unit tests, the 
coverage would be sufficient!




Re: DMD/Windows: Inspect generated ASM?

2012-04-08 Thread bearophile

Stefan:


Unlike gdc, dmd it has no -S option,


I'd like that. This seems a nice enhancement request for you to 
add in Bugzilla.


Bye,
bearophile


Re: Operator Overloading : opOpAssign

2012-04-08 Thread Timon Gehr

On 04/08/2012 07:56 PM, Eyyub wrote:

Hai,

I would to know how to overload this operator and why I have this error
at compile-time : http://paste.pocoo.org/show/vlfSSekGLCAriCJpiZvp/

Thanks a lot.


Try

void opOpAssign(string op)(const Matrix other) if(op == +)

I think the fact that Matrix!(T,N,M) does not work is a bug. It works if 
explicitly instantiated.


Re: Operator Overloading : opOpAssign

2012-04-08 Thread Eyyub

On Sunday, 8 April 2012 at 18:05:58 UTC, Timon Gehr wrote:

On 04/08/2012 07:56 PM, Eyyub wrote:

Hai,

I would to know how to overload this operator and why I have 
this error
at compile-time : 
http://paste.pocoo.org/show/vlfSSekGLCAriCJpiZvp/


Thanks a lot.


Try

void opOpAssign(string op)(const Matrix other) if(op == +)

I think the fact that Matrix!(T,N,M) does not work is a bug. It 
works if explicitly instantiated.


Mmh, thanks for your answer but it still does not work... :/.

So, you think that is a bug ?

Thanks


Re: string concatenation

2012-04-08 Thread dnewbie

On Sunday, 8 April 2012 at 05:27:50 UTC, Jonathan M Davis wrote:

On Sunday, April 08, 2012 07:08:09 dnewbie wrote:

I have a wchar[] and I want to convert it to UTF8
then append a string. This is my code.

import std.c.windows.windows;
import std.string;
import std.utf;

int main()
{
   wchar[100] v;
   v[0] = 'H';
   v[1] = 'e';
   v[2] = 'l';
   v[3] = 'l';
   v[4] = 'o';
   v[5] = 0;
   string s = toUTF8(v) ~ , world!;
   MessageBoxA(null, s.toStringz, myapp, MB_OK);
   return 0;
}

I want Hello, world!, but the result is Hello only. Please 
help me.


D strings are not null-terminated, so v[5] = 0 doesn't do 
anything to
terminate that string. The whole point of toStringz is to put a 
null character
on the end of a string (and allocate a new string if need be) 
and return a
pointer to it. C code will then use the null character to 
indicate the end of

the string, but D won't.

What you've done with

string s = toUTF8(v) ~ , world!;

is create a string that is

['H', 'e', 'l', 'l', 'o', '\0', '\0', '\0', ...] (all of the 
characters up to

the v[99] are '\0')

and append

[',', ' ', 'w', 'o', 'r', 'l', 'd', '!']

to it. The result is a string whith is 108 characters long with 
a ton of null
characters in the middle of it. When you call toStringz on it, 
it may or may
not allocate a new string, but in the end, you have a string 
which is 109
characters long with the last character being '\0' (still with 
all of the null
characters in the middle) which you get an immutable char* 
pointing to.


So, when the C code operates on it, it naturally stops 
processing when it hits
the first null character, since that's how C determines the end 
of a string.
You can embed null characters in a string and expect C to 
operate on the whole
thing. And since D strings aren't null-terminated, you can't 
expect that
setting any of it their elements to null will do anything to 
terminate the
string in D or stop D functions from operating on the whole 
string. You have
to slice the static wchar array with the exact elements that 
you want if you

intend to terminate it before its end.

- Jonathan M Davis


OK. Thank you.


Re: Operator Overloading : opOpAssign

2012-04-08 Thread Artur Skawina
On 04/08/12 20:50, Eyyub wrote:
 On Sunday, 8 April 2012 at 18:05:58 UTC, Timon Gehr wrote:
 On 04/08/2012 07:56 PM, Eyyub wrote:
 Hai,

 I would to know how to overload this operator and why I have this error
 at compile-time : http://paste.pocoo.org/show/vlfSSekGLCAriCJpiZvp/

 Thanks a lot.

 Try

 void opOpAssign(string op)(const Matrix other) if(op == +)

 I think the fact that Matrix!(T,N,M) does not work is a bug. It works if 
 explicitly instantiated.
 
 Mmh, thanks for your answer but it still does not work... :/.

Try w/ matrices of the same size.

artur


Re: Operator Overloading : opOpAssign

2012-04-08 Thread Eyyub
Ho, if I replace a+=b; by a.opOpAssign!+(b); it works...why 
?





Re: Operator Overloading : opOpAssign

2012-04-08 Thread Eyyub

arthur: It still does not work to, I think that is a bug.



Re: Operator Overloading : opOpAssign

2012-04-08 Thread Eyyub

It works with : http://paste.pocoo.org/show/4oIhMg5eBdUoirhk5iYS/

Thanks for all, kiss !


Latest versions of Entice Designer and DFL?

2012-04-08 Thread vmars316

Win7:
Greetings,
Ok, I got the command line for dmd2 running (Hello World). :)

Now I would like to install a Visual GUI Builder.
Not knowing any better, think I'll try Entice Designer and DFL.
The most current versions I can find are for 2008.
Are there more current versions? Url please.
Is there a combined *.zip install for them?
Also, is Entice Designer and DFL a reasonable choice?
I am always oopen for a better option.

Thanks...Vernon


D and QtCreator

2012-04-08 Thread Joseph Rushton Wakeling

Hello all,

I saw a few messages in the list archives about using QtCreator as an IDE for D.

It wasn't clear from these messages to what extent the issue had been resolved. 
 I have very simple requirements -- all I'm looking for is correct syntax 
highlighting and indentation -- is there an easy way to get these set up and 
running for D in QtCreator?


Thanks and best wishes,

-- Joe


template member function confusion

2012-04-08 Thread Francois Chabot
Hello, I've been getting into the language recently, and ror the 
most part, it's going pretty smoothly.


I have finally run into the first major snag that's really making 
me scratch my head. Mind you, I can easily code around it, but 
I'd like to understand why it's not working:



Given (roughly) the following code:
class Binding
{
  ...
}

class Bar
{
  Binding[string] Bindings ;

  //cached function
  void foo( Foo target , const ref Matrix44 val ) { ... }
  void foo( Foo target , const ref Vec4 val ) { ... }
  //... more function...

  //convenience interface for non-critical code-paths
  void foo(T)( string target , const ref T val ) { foo( 
Bindings[target] , val ) ; }


}

DMD gives me the following:
Error: Bar.foo(T) conflicts with function Bar.foo at ...

Now, I can easily
A) Change the name of either one the functions (which yields a 
slightly less elegant interface)
B) Not use a template and put string versions of all the foos 
(which yields ugly code)
C) Make the binding-based interface a template and implement the 
functions through specialization (as they are unfortunately 
different enough to not be templatable). While maintaining the 
interface and conciseness, it feels like a hack to me.


I just can't wrap my head around why my current implementation 
cannot work. Any insight?


Re: template member function confusion

2012-04-08 Thread Jonathan M Davis
On Sunday, April 08, 2012 22:51:51 Francois Chabot wrote:
 Hello, I've been getting into the language recently, and ror the
 most part, it's going pretty smoothly.
 
 I have finally run into the first major snag that's really making
 me scratch my head. Mind you, I can easily code around it, but
 I'd like to understand why it's not working:
 
 
 Given (roughly) the following code:
 class Binding
 {
...
 }
 
 class Bar
 {
Binding[string] Bindings ;
 
//cached function
void foo( Foo target , const ref Matrix44 val ) { ... }
void foo( Foo target , const ref Vec4 val ) { ... }
//... more function...
 
//convenience interface for non-critical code-paths
void foo(T)( string target , const ref T val ) { foo(
 Bindings[target] , val ) ; }
 
 }
 
 DMD gives me the following:
 Error: Bar.foo(T) conflicts with function Bar.foo at ...
 
 Now, I can easily
 A) Change the name of either one the functions (which yields a
 slightly less elegant interface)
 B) Not use a template and put string versions of all the foos
 (which yields ugly code)
 C) Make the binding-based interface a template and implement the
 functions through specialization (as they are unfortunately
 different enough to not be templatable). While maintaining the
 interface and conciseness, it feels like a hack to me.
 
 I just can't wrap my head around why my current implementation
 cannot work. Any insight?

Two issues here.

1. You cannot currently overload a templated function with a non-templated 
function or vice versa: http://d.puremagic.com/issues/show_bug.cgi?id=1528 
This is a bug which should work and should work at some point. The workaround 
is to templatize the non-templated functions with empty parens. e.g.

void foo()(Foo target, const ref Matrix44 val)

2. Template functions are non-virtual and will _never_ be virtual. This 
probably isn't causing you any compilation issues, but it does mean that you 
must be careful with using templated functions in classes. It means that 
templatizing all of the foos will mean that none of them are virtual (though 
that's arguably better than making some of them virtual and some not, since 
that has its own set of issues). Regardless, if you have an API which relies 
on having a templated function be virtual, you're going to have to find a way 
to work around it, because templated functions _can't_ be virtual.

- Jonathan M Davis


Re: Latest versions of Entice Designer and DFL?

2012-04-08 Thread Kevin Cox
On Apr 8, 2012 4:49 PM, vmars316 vmars...@live.com wrote:

 Win7:
 Greetings,
 Ok, I got the command line for dmd2 running (Hello World). :)

 Now I would like to install a Visual GUI Builder.
 Not knowing any better, think I'll try Entice Designer and DFL.
 The most current versions I can find are for 2008.
 Are there more current versions? Url please.
 Is there a combined *.zip install for them?
 Also, is Entice Designer and DFL a reasonable choice?
 I am always oopen for a better option.

 Thanks...Vernon

If you want to use QtD you can use QtDesigner and I think QtD has a moc for
D.  Worst case you can dynamically load the forum from the xml file
QtDesigner spits out.


Re: template member function confusion

2012-04-08 Thread Francois Chabot

Two issues here.

1. You cannot currently overload a templated function with a 
non-templated
function or vice versa: 
http://d.puremagic.com/issues/show_bug.cgi?id=1528

This is a bug which should work and should work at some point.


Thank you very much for the confirmation that I'm not crazy here.


The workaround
is to templatize the non-templated functions with empty parens. 
e.g.


void foo()(Foo target, const ref Matrix44 val)


I could see this working, but I'll steer clear of this in this 
particular case. Dirtying the preferred interface just for the 
sake of a convenience function is not exactly... nice...


2. Template functions are non-virtual and will _never_ be 
virtual. This probably isn't causing you any compilation 
issues, but it does mean that you must be careful with using 
templated functions in classes. It means that templatizing all 
of the foos will mean that none of them are virtual (though 
that's arguably better than making some of them virtual and 
some not, since that has its own set of issues). Regardless, if 
you have an API which relies on having a templated function be 
virtual, you're going to have to find a way to work around it, 
because templated functions _can't_ be virtual.


I was already  aware of the non-virtualness of templates, and to 
tell the truth, I much prefer it this way. Maybe it's my C++ 
background showing here, but is this something people have been 
asking for? It sounds crazy to me.


Once again, thanks for the help!


Re: template member function confusion

2012-04-08 Thread Jonathan M Davis
On Sunday, April 08, 2012 23:59:01 Francois Chabot wrote:
 I was already  aware of the non-virtualness of templates, and to
 tell the truth, I much prefer it this way. Maybe it's my C++
 background showing here, but is this something people have been
 asking for? It sounds crazy to me.

Of course, it's something that people have been asking for. It would be 
fantastic to be able to have templated functions which are virtual. And if you 
don't really understand how templates work or don't think it through enough, 
it seems crazy that they _wouldn't_ be virtual. But there are very practical 
reasons why doing so is more or less infeasible (it's certainly infeasible 
with how things currently work in D), and once it's explained how templates 
don't interact with virtual tables very well and all that, it becomes pretty 
obvious that there's no way that templates can be virtual.

There's no question that there are people who want it though. And the fact 
that some stuff in D really needs to be templated (e.g. a lot of range-based 
stuff really only works well if it's templated, and you can't support multiple 
string types very well without templates) makes it so that the lack of virtual 
templates in classes can be frustrating at times.

- Jonathan M Davis


Re: asm stackframe question

2012-04-08 Thread Stefan

On Saturday, 7 April 2012 at 23:50:42 UTC, bearophile wrote:
Keep also in mind that D functions that contain ASM don't get 
inlined in DMD (and probably elsewhere too).


BTW: The GCC backend has a pretty powerful ASM support where 
inlining IS possible and you can simply say things like 'give me 
a free register which supports the XYZ operation' and the backend 
optimizer does the register juggling (such as saving any used 
registers on the stack first or choosing a free one) for you - 
which is essential for sensible inlining.


OK, that's not of much use on an architecture with a feeble 
register set such as i386, but it's a pretty powerful feature 
with architectures with lots of general registers such as m68k or 
SPARC.


But I'm drifting off...

Cheers,
Stefan


Re: template member function confusion

2012-04-08 Thread Stefan

On Sunday, 8 April 2012 at 20:51:52 UTC, Francois Chabot wrote:

class Bar
{
  Binding[string] Bindings ;

  //cached function
  void foo( Foo target , const ref Matrix44 val ) { ... }
  void foo( Foo target , const ref Vec4 val ) { ... }
  //... more function...

  //convenience interface for non-critical code-paths
  void foo(T)( string target , const ref T val ) { foo( 
Bindings[target] , val ) ; }


}

DMD gives me the following:
Error: Bar.foo(T) conflicts with function Bar.foo at ...

Now, I can easily
A) Change the name of either one the functions (which yields a 
slightly less elegant interface)
B) Not use a template and put string versions of all the foos 
(which yields ugly code)
C) Make the binding-based interface a template and implement 
the functions through specialization (as they are unfortunately 
different enough to not be templatable). While maintaining the 
interface and conciseness, it feels like a hack to me.


If you ask me, choose C - that's the most consistent solution. 
It's perfectly OK to have specialized templates. That's not a 
hack, it's a feature ;-)


Regarding the virtualization discussion: You could still use 
method dispatcher pairs, such as


// Specialization
void foo(T: Matrix44)( Foo target , const ref Matrix44 val ) { 
myfoo(target , val); }
void myfoo( Foo target , const ref Matrix44 val ) { /* real 
functionality here */ }

// general swiss knife
void foo(T)( string target , const ref T val ) { myfoo(target , 
val); }
void myfoo( Foo target , const ref Variant val ) { /* real 
functionality here */ }


Then the myfoo methods would be overloadable. If you want the 
total hack, you could wrap the specialization pairs into 
mixins. This way, only the foo wrappers are visible to the human 
user, but the compiler also sees the overloadable, ordinary 
methods.


Cheers,
Stefan



Re: DMD/Windows: Inspect generated ASM?

2012-04-08 Thread Stefan

On Sunday, 8 April 2012 at 15:43:23 UTC, bearophile wrote:
I'd like that. This seems a nice enhancement request for you to 
add in Bugzilla.


Yup, sometimes you want to look under the hood of the compiler 
to tweak things a little. Or just to understand how a 64bit 
multiplication works on a IA32 machine :-)


I wonder, though, if the dmd backend has a real ASM stage, or 
if some intermediate code is directly translated into an opcode 
stream (like the RTL stuff in the GCC backend).


Cheers,
Stefan


Re: DMD/Windows: Inspect generated ASM?

2012-04-08 Thread Stefan

On Sunday, 8 April 2012 at 13:56:30 UTC, Andrej Mitrovic wrote:

I forgot by now just how those %~ thingies work. Windows batch 
is a

funny language.


That's why I love cygwin, no funny percent stuff there ;-)

Cheers,
Stefan


Re: Operator Overloading : opOpAssign

2012-04-08 Thread Timon Gehr

On 04/08/2012 10:06 PM, Eyyub wrote:

It works with : http://paste.pocoo.org/show/4oIhMg5eBdUoirhk5iYS/

Thanks for all, kiss !


You don't need/want the 'ref's there.


Re: Latest versions of Entice Designer and DFL?

2012-04-08 Thread vmars316

On Sunday, 8 April 2012 at 21:54:22 UTC, Kevin Cox wrote:


If you want to use QtD you can use QtDesigner and I think QtD 
has a moc for
D.  Worst case you can dynamically load the forum from the 
xml file

QtDesigner spits out.


Thanks.
I can't find where it is actually working yet.
Or what else needs to be installed for it to work.
There is a download for it though: 
http://code.google.com/p/qtd/downloads/list

But yes I would surely be interested if it works well.

...Vernon


Re: string concatenation

2012-04-08 Thread Stefan

On Sunday, 8 April 2012 at 05:08:15 UTC, dnewbie wrote:

   wchar[100] v;
   v[0] = 'H';
   v[1] = 'e';
   v[2] = 'l';
   v[3] = 'l';
   v[4] = 'o';
   v[5] = 0;
   string s = toUTF8(v) ~ , world!;
   MessageBoxA(null, s.toStringz, myapp, MB_OK);


Hint: You normally don't use fixed-length arrays in D - unless 
there is a model world restriction, such as in


class Car{
Tire[4] tires;
...
}

So if you really want to have UTF16 conversion and back (which I 
guess you don't), your code would be:


wchar[] v = Hellow;
string s = toUTF8(v) ~ , world!;
MessageBoxA(null, s.toStringz, myapp, MB_OK);

What you probably want is

string v = Hello;
string s = v ~ , world!;
MessageBoxA(null, s.toStringz, myapp, MB_OK);

Cheers,
Stefan


Re: Operator Overloading with class template

2012-04-08 Thread Francois Chabot

On Sunday, 8 April 2012 at 23:14:33 UTC, Eyyub wrote:

Hello,

How can I rewrite the exemple 2 (http://pastebin.com/q50903Zh) 
in D lang. ?

This source code doesn't work...why ?
http://paste.pocoo.org/show/wy1kDIpqTi2ApRuOxRRb/

Thx. :)


As far as I know, there is nothing special about themplate 
classes with regards to operator overloading, so you can follow 
the examples in there: http://dlang.org/operatoroverloading.html


which in your example would yield:

Matrix opOpAssign(string op)( Matrix rhs )
{   
  for( size_t i =0 ; i  M ; ++i )
  {
for( size_t j =0 ; j  N ; ++j )
{
  mixin(array_[i*N+j] ~ op ~  rhs.array_[i*N+j] ;) ;
}
  }
}

Bonus! all ...= operators implemented at once!


Re: Operator Overloading with class template

2012-04-08 Thread Francois Chabot

On Sunday, 8 April 2012 at 23:41:51 UTC, Francois Chabot wrote:

On Sunday, 8 April 2012 at 23:14:33 UTC, Eyyub wrote:

Hello,

How can I rewrite the exemple 2 (http://pastebin.com/q50903Zh) 
in D lang. ?

This source code doesn't work...why ?
http://paste.pocoo.org/show/wy1kDIpqTi2ApRuOxRRb/

Thx. :)


As far as I know, there is nothing special about themplate 
classes with regards to operator overloading, so you can follow 
the examples in there: http://dlang.org/operatoroverloading.html


which in your example would yield:

Matrix opOpAssign(string op)( Matrix rhs )
{   
  for( size_t i =0 ; i  M ; ++i )
  {
for( size_t j =0 ; j  N ; ++j )
{
  mixin(array_[i*N+j] ~ op ~  rhs.array_[i*N+j] ;) ;
}
  }
}

Bonus! all ...= operators implemented at once!


Nevermind, read your message too quickly... I thought it was 
about the matrix class...




Re: Operator Overloading with class template

2012-04-08 Thread Eyyub

On Sunday, 8 April 2012 at 23:44:12 UTC, Francois Chabot wrote:

On Sunday, 8 April 2012 at 23:41:51 UTC, Francois Chabot wrote:

On Sunday, 8 April 2012 at 23:14:33 UTC, Eyyub wrote:

Hello,

How can I rewrite the exemple 2 
(http://pastebin.com/q50903Zh) in D lang. ?

This source code doesn't work...why ?
http://paste.pocoo.org/show/wy1kDIpqTi2ApRuOxRRb/

Thx. :)


As far as I know, there is nothing special about themplate 
classes with regards to operator overloading, so you can 
follow the examples in there: 
http://dlang.org/operatoroverloading.html


which in your example would yield:

Matrix opOpAssign(string op)( Matrix rhs )
{   
 for( size_t i =0 ; i  M ; ++i )
 {
   for( size_t j =0 ; j  N ; ++j )
   {
 mixin(array_[i*N+j] ~ op ~  rhs.array_[i*N+j] ;) ;
   }
 }
}

Bonus! all ...= operators implemented at once!


Nevermind, read your message too quickly... I thought it was 
about the matrix class...


Np :D, you don't know how can I do for the example 2 ?


Re: Operator Overloading with class template

2012-04-08 Thread Andrej Mitrovic
On 4/9/12, Eyyub eyyub.pangeara...@gmail.com wrote:
 Np :D, you don't know how can I do for the example 2 ?

Well for one thing, there are no global operators in D. Others might
help out with writing a proper opBinary that's defined in Value
itself.


Re: Operator Overloading with class template

2012-04-08 Thread Eyyub

On Monday, 9 April 2012 at 00:04:50 UTC, Andrej Mitrovic wrote:

On 4/9/12, Eyyub eyyub.pangeara...@gmail.com wrote:

Np :D, you don't know how can I do for the example 2 ?


Well for one thing, there are no global operators in D. Others 
might

help out with writing a proper opBinary that's defined in Value
itself.


Like this : http://paste.pocoo.org/show/VupvqFTLqZxvZajw71MA/ ? I 
have the same errors :s


Thanks


A problem with mutable toString

2012-04-08 Thread bearophile

Currently this code compiles and runs with no errors:

class Foo {
  override string toString() const {
  return Foo;
  }
}
void main() {
  import std.stdio;
  const Foo[] foos = [new Foo];
  writeln(foos);
}


Output, DMD 2.059beta2:

[Foo]



While this gives errors:


class Foo {
  override string toString() /*const*/ {
  return Foo;
  }
}
void main() {
  import std.stdio;
  const Foo[] foos = [new Foo];
  writeln(foos);
}


Output, DMD 2.059beta2:

...\dmd2\src\phobos\std\format.d(2158): Error: template instance
formatObject!(LockingTextWriter,const(Foo),char)
formatObject!(LockingTextWriter,const(Foo),char) does not match
template declaration formatObject(Writer,T,Char) if
(hasToString!(T,Char))
...\dmd2\src\phobos\std\format.d(2158): Error: function expected
before (), not formatObject!(LockingTextWriter,const(Foo),char)
of type void
...\dmd2\src\phobos\std\format.d(1840): Error: template instance
std.format.formatValue!(LockingTextWriter,const(Foo),char) error
instantiating
...\dmd2\src\phobos\std\format.d(1579):instantiated from
here: formatRange!(LockingTextWriter,const(Foo)[],char)
...\dmd2\src\phobos\std\format.d(2559):instantiated from
here: formatValue!(LockingTextWriter,const(Foo)[],char)
...\dmd2\src\phobos\std\format.d(398):instantiated from
here: formatGeneric!(LockingTextWriter,const(Foo[]),char)
...\dmd2\src\phobos\std\stdio.d(687):... (1
instantiations, -v to show) ...
...\dmd2\src\phobos\std\stdio.d(1574):instantiated from
here: write!(const(Foo[]),char)
test.d(9):instantiated from here: writeln!(const(Foo[]))
...\dmd2\src\phobos\std\format.d(1579): Error: template instance
std.format.formatRange!(LockingTextWriter,const(Foo)[],char)
error instantiating
...\dmd2\src\phobos\std\format.d(2559):instantiated from
here: formatValue!(LockingTextWriter,const(Foo)[],char)
...\dmd2\src\phobos\std\format.d(398):instantiated from
here: formatGeneric!(LockingTextWriter,const(Foo[]),char)
...\dmd2\src\phobos\std\stdio.d(687):instantiated from
here: formattedWrite!(LockingTextWriter,char,const(Foo[]))
...\dmd2\src\phobos\std\stdio.d(1574):instantiated from
here: write!(const(Foo[]),char)
test.d(9):instantiated from here: writeln!(const(Foo[]))
...\dmd2\src\phobos\std\format.d(2559): Error: template instance
std.format.formatValue!(LockingTextWriter,const(Foo)[],char)
error instantiating
...\dmd2\src\phobos\std\format.d(398):instantiated from
here: formatGeneric!(LockingTextWriter,const(Foo[]),char)
...\dmd2\src\phobos\std\stdio.d(687):instantiated from
here: formattedWrite!(LockingTextWriter,char,const(Foo[]))
...\dmd2\src\phobos\std\stdio.d(1574):instantiated from
here: write!(const(Foo[]),char)
test.d(9):instantiated from here: writeln!(const(Foo[]))
...\dmd2\src\phobos\std\format.d(398): Error: template instance
std.format.formatGeneric!(LockingTextWriter,const(Foo[]),char)
error instantiating
...\dmd2\src\phobos\std\stdio.d(687):instantiated from
here: formattedWrite!(LockingTextWriter,char,const(Foo[]))
...\dmd2\src\phobos\std\stdio.d(1574):instantiated from
here: write!(const(Foo[]),char)
test.d(9):instantiated from here: writeln!(const(Foo[]))
...\dmd2\src\phobos\std\stdio.d(687): Error: template instance
std.format.formattedWrite!(LockingTextWriter,char,const(Foo[]))
error instantiating
...\dmd2\src\phobos\std\stdio.d(1574):instantiated from
here: write!(const(Foo[]),char)
test.d(9):instantiated from here: writeln!(const(Foo[]))
...\dmd2\src\phobos\std\stdio.d(1574): Error: template instance
std.stdio.File.write!(const(Foo[]),char) error instantiating
test.d(9):instantiated from here: writeln!(const(Foo[]))
test.d(9): Error: template instance
std.stdio.writeln!(const(Foo[])) error instantiating



Is this good/expected?

Bye,
bearophile


Re: A problem with mutable toString

2012-04-08 Thread H. S. Teoh
On Mon, Apr 09, 2012 at 02:25:56AM +0200, bearophile wrote:
[...]
 While this gives errors:
 
 class Foo {
   override string toString() /*const*/ {
   return Foo;
   }
 }
 void main() {
   import std.stdio;
   const Foo[] foos = [new Foo];
   writeln(foos);
 }
 
 
 Output, DMD 2.059beta2:
 
 ...\dmd2\src\phobos\std\format.d(2158): Error: template instance
 formatObject!(LockingTextWriter,const(Foo),char)
 formatObject!(LockingTextWriter,const(Foo),char) does not match
 template declaration formatObject(Writer,T,Char) if
 (hasToString!(T,Char))
[...]
 Is this good/expected?
[...]

IMO this is correct. The error message could be improved, but basically
the compiler is complaining that it can't find a suitable toString()
method to use. This is probably because Walter recently changed it so
that toString() must be const, which I think makes sense. Non-const
toString causes a lot of grief in druntime code (and probably elsewhere
too).


T

-- 
If you compete with slaves, you become a slave. -- Norbert Wiener


Re: Latest versions of Entice Designer and DFL?

2012-04-08 Thread Jesse Phillips

On Sunday, 8 April 2012 at 20:45:12 UTC, vmars316 wrote:

Win7:
Greetings,
Ok, I got the command line for dmd2 running (Hello World). :)

Now I would like to install a Visual GUI Builder.
Not knowing any better, think I'll try Entice Designer and 
DFL.

The most current versions I can find are for 2008.
Are there more current versions? Url please.
Is there a combined *.zip install for them?
Also, is Entice Designer and DFL a reasonable choice?
I am always oopen for a better option.

Thanks...Vernon


You can find the latest code for DFL here:

https://github.com/Rayerd/dfl

Entice designer won't be as friendly as other GUI Builders you 
might have used, but it is nice. I don't know of any updates to 
the code.


I'd say the choice is reasonable, but maybe not what you'd 
expect, there isn't a whole lot of choice on this front.


Re: D slower ~1s from C ?!

2012-04-08 Thread Marco Leise
Am Thu, 05 Apr 2012 19:22:37 +0200
schrieb Minas minas_mina1...@hotmail.co.uk:

 Many of you should know the website projecteuler.net, where 
 there are mathematical problems to solve with computers.
 
 I am doing those in D, and after I finished one today, I decided 
 to compile it in C as well to compare the results.

The first rule or PE: You don't talk about PE in the public. You accidentally 
posted a solution to a problem in the public. Now people can solve the task, 
using a search engine. And after solving the problem, get access to other 
language implementations. Some employers even use problems from there to assess 
new programmers. And believe me, you wouldn't want a co-worker that cheated on 
PE to get the job ;).

Anyway like others suggested, I use GDC to get the most out of D and I actually 
like the challenge of staying under 50ms for every problem I solve. (My Friend 
Key is 58749952297599_fa95cc8e61e8df1206f1144436ac050f)
Admittedly my first solutions aren't always fast. Often I just solve the 
problem and then look into the forum for how to make it _fast_. After a while I 
think, I should have a nice library of very fast helper functions.

My personal favorite is a small struct that can be used to iterate along rows 
or diagonals of Pascal's triangle:

-

alias size_t ℕ;

/**
 * The ultimate tool to move around in Pascal's triangle. Pascal(0, 0) is the
 * top of the triangle with the value of 1.
 */
struct Pascal
{
this(ℕ n, ℕ k) {
// internally we offset these by +1, to simplify the math
++n; ++k;
_n = n;
if (k  n / 2) {
_k = _n;
left(_n - k);
} else {
right(k - 1);
}
}

ℕ left(ℕ amount) {
while (amount--) {
_value *= --_k;
_value /= _n - _k;
}
return _value;
}

ℕ right(ℕ amount) {
while (amount--) {
_value *= _n - _k;
_value /= _k++;
}
return _value;
}

ℕ rightDown(ℕ amount) {
while (amount--) {
_value *= _n++;
_value /= _k++;
}
return _value;
}

ℕ leftDown(ℕ amount) {
while (amount--) {
_value *= _n++;
_value /= _n - _k;
}
return _value;
}

ℕ leftUp(ℕ amount) {
while (amount--) {
_value *= --_k;
_value /= --_n;
}
return _value;
}

ℕ rightUp(ℕ amount) {
while (amount--) {
_value *= _n - _k;
_value /= --_n;
}
return _value;
}

@property
ℕ value() { return _value; }

alias value this;

private:

ℕ _n = 1, _k = 1;
ℕ _value = 1;
}

-

I use it like this for combinatorics calculations (n over k), where a naive 
approach would recalculate that Pascal's triangle value at the required 
position over and over again:

ℕ[] permut_per_variation = new ℕ[variations];
Pascal pascal = Pascal(_2 + _3, _3);
foreach (v; 0..variations)
{
permut += permut_per_variation[v] = pascal;
pascal.leftDown(1);
pascal.left(2);
}

Still some functional programmers keep mocking me for my lines of code count. 
And I tend to agree now and then (some FP solutions are _really_ short). With 
these fun tasks it is more a matter of personality though. I prefer fast over 
concise code. Some participants even use ASM... maybe they like it really close 
to the metal. In any case it is good to know how C/D code maps to machine code, 
e.g. what is efficient and what not, so you don't misuse real instead of int.

Looking at your code I noticed the following:

*)  writeln() is ok, but doesn't flush (e.g. missing output when a program 
is halted in a debugger or crashes)
You can use stdout.writeln() when you need the output on the screen as 
soon as the line is executed

*)  n = abs(n); // - don't need this, you already declared n as unsigned

*)  if( n % 2 ...)
Just in case someone wonders, GCC/GDC replaces the modulo with faster   
code. There is no need to write n  1, which is a bit more cryptic.

*)  for(ulong i = 2; i = cast (ulong)sqrt(cast(double)n+1); ++i)
can be written as:
foreach (i; 2 .. cast(ulong)sqrt(n)+1)

Foreach only computes start and end once and 'i' will be ulong thanks 
to 

Re: Latest versions of Entice Designer and DFL?

2012-04-08 Thread vmars316

Greets,
I will set up a new thread for How to set up QTD?.

What i would like to continue with here is
to Get DFL and Entice up and running.

I set things up like this:

C:\D\dmd2\Entice
C:\D\dmd2\windows\bin\DFL

Is this correct?

I found some docs that said:

Example commands:
   dfl -gui helloworld.d
   dmd helloworld.d dfl_debug.lib -debug -L/exet:nt/su:windows:4.0

Does that mean I need to make a .bat for each .d file I want to 
compile with?

And that I need to fire up DFL first, then dmd

Also, I don't see any docs for Entice.
Please, aim me where I need to go.

Thanks...Vernon



How to set up QTD?.

2012-04-08 Thread vmars316

Greetings,
I would also like to try out QTD.

So far, I have set things up this:
C:\D\dmd2\QT

I made a .batch file for both drcc.exe and duic.exe .
duic.exe gave no feedback.

drcc.exe gave the following feedback:

C:\D\dmd2\QT\binECHO ON

C:\D\dmd2\QT\bindrcc.exe
Qt resource compiler
Usage: drcc.exe  [options] inputs

Options:
  -o filewrite output to file rather than stdout
  -name name create an external initialization 
function with name

  -threshold level   threshold to consider compressing files
  -compress levelcompress input files by level
  -root path prefix resource access path with root 
path

  -no-compress   disable all compression
  -no-static-initialize  disable automatic initialization of 
resources with prog

ram start
  -binaryoutput a binary file for use as a 
dynamic resource

  -namespace turn off namespace macros
  -project   Output a resource file containing all
 files from the current directory
  -version   display version
  -help  display this information

C:\D\dmd2\QT\binREM C:\D\dmd2\windows\bin\dmd.exe

C:\D\dmd2\QT\binpause
Press any key to continue . . .

Pls, do I need to re-do file/Folder placement?
Also, do I need to create .bat files for every .d I want to 
compile?

Can someone show me how to get qtd running?

Thanks...Vernon




Re: Latest versions of Entice Designer and DFL?

2012-04-08 Thread Jesse Phillips

On Monday, 9 April 2012 at 02:42:27 UTC, vmars316 wrote:

Greets,
I will set up a new thread for How to set up QTD?.

What i would like to continue with here is
to Get DFL and Entice up and running.

I set things up like this:

C:\D\dmd2\Entice
C:\D\dmd2\windows\bin\DFL


The zip file from the main website
http://www.dprogramming.com/dfl.php

is structured such that, I believe you just extract in into dmd2, 
or dmd2/windows don't what it looks like.



Is this correct?

I found some docs that said:

Example commands:
   dfl -gui helloworld.d
   dmd helloworld.d dfl_debug.lib -debug 
-L/exet:nt/su:windows:4.0


Those are 2 separate examples, you can either use dfl.exe (found 
in the zip), or you can call dmd directly as shown.



Also, I don't see any docs for Entice.
Please, aim me where I need to go.


The main page is
http://www.dprogramming.com/entice.php

and I think that is all you will find.