Re: constructor is not callable using argument types ()

2012-12-10 Thread Suliman

Thanks!

But if I have a lot of property like^
string name
int age


it's not good to specify all of them in paranceses:
auto file = new FileName(test.txt, 21, ETC);

How can I specify them in another way?


Hide console of gui program coded by gtkD

2012-12-10 Thread December Flower

Hello.

I have a question about how to hide a console window.

http://pds23.egloos.com/pds/201212/10/80/e0088180_50c5e3b1bb789.png

This simple application is made by using gtkD and glade3. As you 
can see from picture above, console window pops up and doesn't 
disappear. When I close the console window, gui window also 
disappears. I also made a simple gui application without glade3, 
but it also showed console window. How can I hide this annoying 
console window?


Regards.


Re: Hide console of gui program coded by gtkD

2012-12-10 Thread Adam D. Ruppe
On Monday, 10 December 2012 at 13:34:51 UTC, December Flower 
wrote:

I have a question about how to hide a console window.


Make a .def file and include it on your dmd command line.

The file only needs these two lines:

EXETYPE NT
SUBSYSTEM WINDOWS


Call it foo.def, recompile with it on the dmd command line, and 
you should be in business.


Re: Hide console of gui program coded by gtkD

2012-12-10 Thread Maxim Fomin
On Monday, 10 December 2012 at 13:34:51 UTC, December Flower 
wrote:

Hello.

I have a question about how to hide a console window.

http://pds23.egloos.com/pds/201212/10/80/e0088180_50c5e3b1bb789.png

This simple application is made by using gtkD and glade3. As 
you can see from picture above, console window pops up and 
doesn't disappear. When I close the console window, gui window 
also disappears. I also made a simple gui application without 
glade3, but it also showed console window. How can I hide this 
annoying console window?


Regards.


It happens because in windows you should tell linker that 
executable should belong to windows subsystem. Normally one have 
to specify appropriate optlink options 
(http://digitalmars.com/ctg/ctgLinkSwitches.html#subsystem), but 
I used PE tools to patch the binary.


Re: constructor is not callable using argument types ()

2012-12-10 Thread bearophile

Suliman:


But if I have a lot of property like^
string name
int age


it's not good to specify all of them in paranceses:
auto file = new FileName(test.txt, 21, ETC);

How can I specify them in another way?


There are several ways to help that. A simple way is to use 
default arguments:


this(string fileName, int id=21, Foo f=ETC) {...}

An alternative is to define various constructors with different 
number of arguments.


Other solutions include the use of a little configuration struct, 
or the chaining of setters that return this:


FileName setId(int id_) { this.id = id_; return this; }

Then if you define several of such setters, you can chain only 
the ones you want in a single line.


auto f = new FileName(test.txt);
f.setId(21).setF(ETC);

Probably there are other solutions.

Bye,
bearophile


Re: Hide console of gui program coded by gtkD

2012-12-10 Thread December Flower

On Monday, 10 December 2012 at 13:42:12 UTC, Adam D. Ruppe wrote:
On Monday, 10 December 2012 at 13:34:51 UTC, December Flower 
wrote:

I have a question about how to hide a console window.


Make a .def file and include it on your dmd command line.

The file only needs these two lines:

EXETYPE NT
SUBSYSTEM WINDOWS


Call it foo.def, recompile with it on the dmd command line, and 
you should be in business.


Thanks. That should do the trick.

Anyway, I have another question.
The first programming language I learnt is C#. As you know, VS 
does all the irksome things to be considered. Apprently not 
knowing C language, there're a lot of trivial things(Actually not 
trivial) like this that is not about programming logic but about 
language minor specification(Actually not minor).


Not trivial, important, not minor, major. Anyway, what I'm trying 
to say is that is there any good start points to make experiences 
with D language to build a real-world application using GUI? I 
finished studying Programming in D by Ali Çehreli and that was 
quite good. But not for me.


Anyway, thanks for your reply. Have a nice day :)


Re: MS ODBC encoding issue

2012-12-10 Thread Regan Heath

On Fri, 07 Dec 2012 00:27:57 -, Sam Hu samhudotsa...@gmail.com wrote:


On Thursday, 6 December 2012 at 16:44:01 UTC, Regan Heath wrote:
On Thu, 06 Dec 2012 01:26:32 -, Sam Hu samhudotsa...@gmail.com  
wrote:

Known issues:

Under console reading Access table recordsets works fine ,inserting a  
new record which contains only English characters works fine as  
well,but inserting new record which contains Chinese character will  
crash;


If calling the fetchAll in a DFL gui form and try to display the  
result value in a Text control,English values works fine but the Text  
control will display nothing when any record (row/field) contains  
Chinese character.


Where do the win32.sql etc modules come from?

R


You can find it from below links:
http://www.dsource.org/projects/bindings/wiki/WindowsApi
https://github.com/AndrejMitrovic/WindowsAPI


Ahh, of course.  Now I'm having linking issues :p

I'm using VisualD and I've added odbc32.lib to the right place, but some  
symbols are still missing - specifically the W versions.  I've dumped the  
symbols in the DMC odbc32.lib and it's missing those symbols.


I am guessing I should be using converted M$ libs and I'll do this next,  
when I get a spare moment (work has been busy lately).


R

--
Using Opera's revolutionary email client: http://www.opera.com/mail/


std.algorithm Map using a external variable

2012-12-10 Thread Zardoz

I'm trying to use Map with a code like this :

...
  immutable int m = 10;
  int[] caca = [1,2,3,4];

  auto caca2 = map!( (a) {return a * m;})(caca);

  writeln(caca2);
...

I get a Segmentation fault some times:
The most interesting point it's that depends of the code around 
of it ins the same  program. for example If a use getopt at the 
begin of my program, then seg fault, etc...

 Looks that there some weird error in gdc 4.6.3

PD: Later I will put the whole code so any can see if I doing 
some weird thing that make map crazy




Re: std.algorithm Map using a external variable

2012-12-10 Thread Jacob Carlborg

On 2012-12-10 19:21, Zardoz wrote:

I'm trying to use Map with a code like this :

...
   immutable int m = 10;
   int[] caca = [1,2,3,4];

   auto caca2 = map!( (a) {return a * m;})(caca);

   writeln(caca2);
...

I get a Segmentation fault some times:
The most interesting point it's that depends of the code around of it
ins the same  program. for example If a use getopt at the begin of my
program, then seg fault, etc...
  Looks that there some weird error in gdc 4.6.3

PD: Later I will put the whole code so any can see if I doing some weird
thing that make map crazy


std.getopt uses module variables, don't know if that has anything to do 
with it.


--
/Jacob Carlborg


Re: std.algorithm Map using a external variable

2012-12-10 Thread H. S. Teoh
On Mon, Dec 10, 2012 at 07:21:47PM +0100, Zardoz wrote:
 I'm trying to use Map with a code like this :
 
 ...
   immutable int m = 10;
   int[] caca = [1,2,3,4];
 
   auto caca2 = map!( (a) {return a * m;})(caca);
 
   writeln(caca2);
 ...
 
 I get a Segmentation fault some times:
 The most interesting point it's that depends of the code around of
 it ins the same  program. for example If a use getopt at the begin
 of my program, then seg fault, etc...
[...]

Do you have a compilable sample (possibly reduced from your full
sources) that exhibits this error? It would help track down the problem.

There are some known bugs related to map in older releases of D that may
be affecting you.


T

-- 
Give me some fresh salted fish, please.


Re: std.algorithm Map using a external variable

2012-12-10 Thread Maxim Fomin

On Monday, 10 December 2012 at 18:21:48 UTC, Zardoz wrote:

I'm trying to use Map with a code like this :

...
  immutable int m = 10;
  int[] caca = [1,2,3,4];

  auto caca2 = map!( (a) {return a * m;})(caca);

  writeln(caca2);
...

I get a Segmentation fault some times:
The most interesting point it's that depends of the code around 
of it ins the same  program. for example If a use getopt at the 
begin of my program, then seg fault, etc...

 Looks that there some weird error in gdc 4.6.3

PD: Later I will put the whole code so any can see if I doing 
some weird thing that make map crazy


Looks like template lambda bug 
(http://d.puremagic.com/issues/show_bug.cgi?id=8899). It might 
depend not only on surrounding code, but on importing some phobos 
module (issue 8854).


Re: Hide console of gui program coded by gtkD

2012-12-10 Thread Ali Çehreli

On 12/10/2012 06:30 AM, December Flower wrote:

 Anyway, what I'm trying to say
 is that is there any good start points to make experiences with D
 language to build a real-world application using GUI?

I think D is in need of documentation of that sort. Books like D for 
FooLang programmers would be very interesting.


 I finished
 studying Programming in D by Ali Çehreli and that was quite good. But
 not for me.

I am very happy that you've read it. :)

As has been discussed on these forums before, that book has been an 
interesting exercise in teaching programming. In the end, the book may 
end up requiring too much patience from the reader though: It is very 
strict on the principle that no D feature should be used before being 
explained in the book itself.


That decision necessarily pushed many useful D idioms to the end of the 
book. (But to be fair, the book pre-dates some of the cool features of D 
like ranges, parallelism and concurrency, UFCS, the shorthand lambda 
syntax, the new operator overloading syntax, etc.)


So yes, there must be lots of articles and books that concentrate on 
practical D programming.


Ali



Re: Template return values?

2012-12-10 Thread Jesse Phillips
On Thursday, 6 December 2012 at 00:31:53 UTC, Jonathan M Davis 
wrote:


Pretty much the only kind of situation that I remember running 
into where I
would consider Variant to be a good solution is one where you 
literally have
to return a type from a function where you can't know that type 
at compile
time, and there is no common type to use. And the only time 
that I recall
running into that recently was in writing a lexer (the values 
of literals
ended up having to be put in a variant type). There are 
obviously other use
cases besides that (database-related stuff and spreadsheets 
like you mentioned
are other possibilities), but they are extremely rare in my 
experience. In
almost all cases, you can and should know the type at compile 
time, in which

case, using Variant makes no sense.

- Jonathan M Davis


My experience with Variant has come from integration in LuaD 
(Probably like what I'd want from JSON).


My main use has been an Algebraic type of string, string[], and 
string[][string]. (Lua does not have arrays or dictionaries, it 
has a table).


In general when I request data I know which of these it is, 
however I do have some generic code to operate on any of these 
types, thus:


if(myVar.peek!(string[][string]))
... myVar.get!(string[][string])

Does get repetitive and messy to read.

On another note, it is sad I can't have that defined as 
MyType[MyType].


Type value

2012-12-10 Thread Zhenya

Hi!
In some previous post I asked about possibility of declar 
opIndex,that return type.

I thoght about it,and I understood that code like this is legal:

struct Type(T)
{
alias T m_type;
alias m_type this;
}

void main()
{
Type!int Int;
//  Int a;
}

Is it hard to implement possibility of using Int as a type?
It would allow functions,that return types:)


Why the lack of networky bits in the standard library

2012-12-10 Thread Matthew Caron
In C, if I want to parse a UDP packet, I need to build my own offsets 
into data based off constants in:

net/ethernet.h
netinet/udp.h

Things like:

#define PACKET_DATA_OFFSET_DEFAULT (
 ETHER_HDR_LEN + sizeof(struct iphdr) + \
 sizeof(struct udphdr))

That would be easy to port to D, if I had access to those structs and 
defines, but it doesn't seem like these have been ported over. Am I 
missing something obvious?


Thanks.

--
Matthew Caron, Software Build Engineer
Sixnet, a Red Lion business | www.sixnet.com
+1 (518) 877-5173 x138 office


Re: Why the lack of networky bits in the standard library

2012-12-10 Thread Alex Rønne Petersen

On 10-12-2012 21:22, Matthew Caron wrote:

In C, if I want to parse a UDP packet, I need to build my own offsets
into data based off constants in:
net/ethernet.h
netinet/udp.h

Things like:

#define PACKET_DATA_OFFSET_DEFAULT (
  ETHER_HDR_LEN + sizeof(struct iphdr) + \
  sizeof(struct udphdr))

That would be easy to port to D, if I had access to those structs and
defines, but it doesn't seem like these have been ported over. Am I
missing something obvious?

Thanks.



We haven't bound all C/POSIX headers in druntime yet. There's no 
particular reason it isn't done other than nobody having gotten around 
to it.


--
Alex Rønne Petersen
a...@lycus.org
http://lycus.org


Re: std.algorithm Map using a external variable

2012-12-10 Thread Zardoz

Well. I just try it again and I noticed this things :
-Changind the lambda function from :
  auto caca2 = map!((a) {return a * iDeltaT;})(caca);
 to :
  auto caca2 = map!((a) {return a + iDeltaT;})(caca);
 Avoid the segmentation fault
-Using dmd 2.60 avoid the segmentation fault.

The source code is in 
http://dl.dropbox.com/u/2716434/CodeThatCrash.tgz
The makefile only builds againts gdc, so to test it with dmd, I 
manually compiled the faulty code of serie2Sim.d with :

  dmd serie2Sim.d entity.d vector.d -ofserie2Sim
And I launch it with ./serie2Sim --rand 10 --seed 123
With dmd works, but with gdc not.


On Monday, 10 December 2012 at 18:59:31 UTC, H. S. Teoh wrote:

On Mon, Dec 10, 2012 at 07:21:47PM +0100, Zardoz wrote:

I'm trying to use Map with a code like this :

...
  immutable int m = 10;
  int[] caca = [1,2,3,4];

  auto caca2 = map!( (a) {return a * m;})(caca);

  writeln(caca2);
...

I get a Segmentation fault some times:
The most interesting point it's that depends of the code 
around of
it ins the same  program. for example If a use getopt at the 
begin

of my program, then seg fault, etc...

[...]

Do you have a compilable sample (possibly reduced from your full
sources) that exhibits this error? It would help track down the 
problem.


There are some known bugs related to map in older releases of D 
that may

be affecting you.


T




Re: static code generation

2012-12-10 Thread js.mdnq
On Monday, 10 December 2012 at 20:17:41 UTC, Philippe Sigaud 
wrote:
If I'm not mistaken isn't the code I'm trying to generate 
still in a

string?



Well, yes, but not when you mix it in. It's a string mixin in 
this case,

not a template mixin.



My whole point is not to use strings to insert code but to use 
code to insert code. (essentially I want to avoid having to wrap 
the code with   as it disables highlighting and possibly other 
features(intellisense, etc...))


We went off on a tangent before as it doesn't really solve my 
problem. I want to generate a partial struct and global functions 
and have the user supply the rest of the struct.





Re: alias this private?

2012-12-10 Thread js.mdnq

On Monday, 10 December 2012 at 07:48:37 UTC, Ali Çehreli wrote:

On 12/09/2012 10:43 PM, js.mdnq wrote:

 I thought `alias this` essentially treats the object as the
alias.

 struct A {
 alias value this;
 int value;
 void func();
 }

 A a;

 then a is essentially the same as a.value?

No. 'alias value this' means when this object is used in a 
context where the type of 'value' is expected, then use the 
'value' member instead.


In your example above, it means when A is used in place of 
int, use 'value' instead. It is basically for automatic type 
conversion.


(A reminder: Although the language spec allows multiple alias 
this declarations, current dmd supports only one.)


 a.func() would be
 a.value.func() which makes no sense?

a.func() would still call A.func on object 'a' because 'a' is 
an A. Only when 'a' is used as an int, 'value' is considered.


 At least that is how I thought
 alias this worked? (it's obviously more complex than what I
thought)

Perhaps it is simpler than what you thought. :)

 (I'm new to D so you'll have to forgive all the stupid
questions ;)

Your questions make all of us learn more. :)

 D seems quite powerful and many useful ways to do things but
I still
 haven't wrapped my head around all the intricacies)

Indeed... There are a lot of features.

Ali


Yeah, basically it's close to what I was thinking but I guess the 
opGet, which I'm still not familiar with, behaves a bit different 
when aliased. Possibly because we are aliasing a operator(or 
method?) which is different than aliasing a type?


e.g., `alias opAssign this;` makes no sense to me ;/

Thanks for the help...


Re: static code generation

2012-12-10 Thread Ali Çehreli

On 12/10/2012 01:52 PM, js.mdnq wrote:

 I want to avoid having to wrap the code with 
  as it disables highlighting and possibly other features(intellisense,
 etc...))

The q{} syntax is supposed to help with that issue. Emacs manages syntax 
highlighting correctly for the q{} strings:


import std.stdio;

void main()
{
enum s = q{
writeln(hello world);
};

mixin (s);  // -- s is a string
}

Ali



Re: alias this private?

2012-12-10 Thread Ali Çehreli

On 12/10/2012 01:56 PM, js.mdnq wrote:

 I guess the opGet,
 which I'm still not familiar with, behaves a bit different when aliased.
 Possibly because we are aliasing a operator(or method?)

I may have been too subtle before but opGet() is not an operator 
function. Although its name starts with op, it is still a member function.


 which is
 different than aliasing a type?

The way I understand it, the compiler looks at the return type of that 
function and uses that function when the object is used instead of that 
type. If 'int foo()' is used in alias this, because foo() returns int, 
the object is eligible to be used in place of an int. foo() gets called 
to produce that int value.


Ali



overlapping structs

2012-12-10 Thread js.mdnq
This gets back to my question about nested structs(since I'm 
trying to find a way to make it work). Take the following working 
example:


class A {

struct B {
A* a;
}

B b1;
B b2;
}

Wastes a lot of space as we store a ptr to A for each field we 
use. If there were 100 B types in A then it would bloat the class 
by 100*size_t. In theory it is possible to avoid this.


If we could pass an offset to a struct relative to another AND 
create a virtual variable at another offset then we could 
remove the overhead issue in the above case:



class A {
A* a;
struct B(Ofs) {
virtual!(-Ofs) A* a;// Our goal is to have this a be 
the a in A::a

}

B!(ofs a:$) b1;
B!(ofs a:$) b2;
}

This might not make sense BUT it's pretty simple. ($ = here)

When b1 is created, we pass the distance from it to A::a. (in 
this case size_t). virtual!(-Ofs) creates a at this location... 
which just overlaps with A::a, which is the whole point. B::a 
does not take up any space inside the struct and essentially uses 
A::a.


When b2 is created, we pass it a slightly different 
offset(B.sizeof + size_t) but, it too will make b2.a overlap with 
A::a.


(there are two structs here, one for b1 and one for b2. They 
differ in their offset value)


The big difference between the two cases is, again, that the 2nd 
requires only one additional storage ptr while the first requires 
n ptr's.


Also, we could simplify it further since we don't technically 
need to use ptr's but that would require much more from the 
compiler. Hopefully there is some way to implement what I'm 
talking about in D using this method than the other(which is 
talked about more in the other post).


To prevent weird stuff from happening we prevent the structs from 
being directly copied so that their a's won't be garbage(since 
it's actually before the struct). So no default constructor for 
these types can be used ;/


(the easy way to fix it is to have methods inside the struct get 
passed the this and the cthis ptr(cthis is the pointer to the 
object containing in the struct))








Re: Type value

2012-12-10 Thread js.mdnq

On Monday, 10 December 2012 at 19:54:51 UTC, Zhenya wrote:

Hi!
In some previous post I asked about possibility of declar 
opIndex,that return type.

I thoght about it,and I understood that code like this is legal:

struct Type(T)
{
alias T m_type;
alias m_type this;
}

void main()
{
Type!int Int;
//  Int a;
}

Is it hard to implement possibility of using Int as a type?
It would allow functions,that return types:)


Type's are compile time concepts that are only used to partition 
data into logical units. Computer memory is just a bunch of 0's 
and 1's and have no logical interpretation.


By creating a type you are taking a group of bits and telling the 
compiler(a static construct) how you want to interpret them. You 
do not tell the cpu this as it does not have any idea of 
types(well, except for basic things like ptr's, bytes, words, 
etc...).


So, when you say return a type it means nothing because a type 
is not addressable. How would you return an int as a type? (not a 
group of bits but an actual int type specification)


To help bridge the gap between compile time static type 
constructs and a rather typeless run-time system modern languages 
seem to create a type that wraps Type information into an actual 
object which then you can pass around like normal objects.


Remember, compilers simply make it easier to program in binary, 
but ultimately that is all we are doing. To make things more 
logical we use higher level types, the cpu does not understand 
arbitrary types(but we use the types it does understand as basic 
building blocks). In some sense, it doesn't even understand 
types at all... it just has some instructions that make dealing 
with different length of binary numbers easier/more efficient.


As far as I know, D does allow you to wrap compile time type info 
into an object to be used at run-time for various things(but it 
will exist as an addressable object).



for example, you can't really do something like this

type return_type(int x) { if x == 1 return int; return fruitType; 
}


c = readkey();
return_type(c) y;
// How do we use y? we don't even know what type it is at this 
point! We are going to have to assume it is one or the other and 
code for both! But then we essentially just have the same as the 
following


alternatively:

c = readkey();
if c == 1 { int y; do whatever; } else { fruitType y; do 
whatever; }


because y is not known at compile time(it is not a static 
construct). y, essentially is a polymorphic type but is too 
arbitrary to be useful. Remember, the compiler ultimately has to 
make an address and a set of bits for y in computer member for 
the cpu to be able to understand it. How, though, can it do this 
for y if the type is not known at compile time?


The 2nd case is completely defined at compile time. The first is 
not and essentially is open ended(the compiler can't figure out 
all the possibilities that y can be, while in the second case it 
is fixed).


So, you can't pass types around in a run-time fashion. D is nice 
in that it allows you do easily do this sort of stuff at compile 
time. You can pass around type info objects dynamically and even 
create types from such objects at run-time. Doing so, though, 
requires a more difficult approach because, ultimately, the 
compiler still has to be told everything that is being done(it 
can't guess) and it still has to translate the program into 0's 
and 1's.


The variant type is a way to sort of get around the problem for 
some cases as it allows a type to be polymorphic to a degree(but 
not arbitrarily).


If cpu's stored data in logical units then such a system would be 
much easier to do. Instead of storing bytes one would store 
records which would contain a type field which would tell the 
cpu information about it(which you have to setup). Unfortunately 
this would bloat the code tremendously(every int would have to 
have a type field). It would be sort of the same though as modern 
compilers and their typing systems but would be more transparent. 
(probably equivalent of just implementing the compiler on the cpu)







Re: static code generation

2012-12-10 Thread js.mdnq

On Monday, 10 December 2012 at 22:01:37 UTC, Ali Çehreli wrote:

On 12/10/2012 01:52 PM, js.mdnq wrote:

 I want to avoid having to wrap the code with 
  as it disables highlighting and possibly other
features(intellisense,
 etc...))

The q{} syntax is supposed to help with that issue. Emacs 
manages syntax highlighting correctly for the q{} strings:


import std.stdio;

void main()
{
enum s = q{
writeln(hello world);
};

mixin (s);  // -- s is a string
}

Ali


Thanks, this is definitely a step up. In Visual D, highlighting 
and intellisense does not work correctly but it does seem to make 
it easier than using a string directly. (I imagine it is the 
fault of Visual D for treating the argument of q as different 
than code)


It should, though, let me do what I want easier than the other 
methods.


Thanks again!


Re: Type value

2012-12-10 Thread Zhenya

I'm sorry for my english.
I know that D != Python and my example don't need
any RTTI.

D has alias this feature.My example shows that we can use alias 
this with types.

And I just want use this:

struct Type(T)
{
   alias T m_type;
   alias m_type this;
}

int main()
{
   Type!int Int;
   Int i;//should compile by definition of alias this
}


Re: Type value

2012-12-10 Thread js.mdnq

On Tuesday, 11 December 2012 at 07:15:38 UTC, Zhenya wrote:

I'm sorry for my english.
I know that D != Python and my example don't need
any RTTI.

D has alias this feature.My example shows that we can use alias 
this with types.

And I just want use this:

struct Type(T)
{
   alias T m_type;
   alias m_type this;
}

int main()
{
   Type!int Int;
   Int i;//should compile by definition of alias this
}


My I ask, why not just use int directly?

I'm not proficient enough with D yet but it seems to me that the 
example does not make sense.


alias T m_type;
alias m_type this;

should be equivalent to

alias T this;

which, in some sense makes struct Type(T) equal to T... which is 
what you are thinking, I think.


But! I also believe that structs are meant as value types and are 
addressable.


So when you do

Int i; you are essentially doing something like

int x;
x i;

which makes no sense.

If you do this instead,

alias Type!int Int;
Int i;

then it will compile, of course.

But your way, when you do Int x; you are specifically trying to 
create a instance of an object. Yet you are not wanting it to be 
an object and I'm not sure what you are wanting x to be. (another 
type? a type of a type?)