Re: mysql

2013-04-18 Thread simendsjo
On Tuesday, 16 April 2013 at 21:09:42 UTC, gedaiu wrote: On Monday, 15 April 2013 at 19:25:19 UTC, simendsjo wrote: On Monday, 15 April 2013 at 17:34:07 UTC, gedaiu wrote: Hi, Can anyone help me to connect to mysql from D? Thanks! You can use Steve Teales native library. The most

Re: Copying reference types by value

2013-04-18 Thread Joseph Rushton Wakeling
On 04/17/2013 10:29 PM, Ali Çehreli wrote: Yes but as I said I am not sure how useful or needed this whole thing is. The language handles copy, move, and assignment for structs. takeOver() seems to be a primitive operation for classes. Could you expand a bit on that? Just that I'm not

Why are fixed length arrays passed by value while variable are passed by reference?

2013-04-18 Thread ixid
I know this will not be changed, I just want to understand why it is as it is. My naive thought is that consistency is the best scheme and that everything should have been passed by value or everything by reference unless the user specifies otherwise. I have read a comment by Andrei that

Re: Why are fixed length arrays passed by value while variable are passed by reference?

2013-04-18 Thread Jacob Carlborg
On 2013-04-18 15:37, ixid wrote: I know this will not be changed, I just want to understand why it is as it is. My naive thought is that consistency is the best scheme and that everything should have been passed by value or everything by reference unless the user specifies otherwise. I have

Re: Why are fixed length arrays passed by value while variable are passed by reference?

2013-04-18 Thread ixid
An array is represent using a struct with a pointer to the array data and the length, like this: struct Array { void* ptr; size_t length; } The struct is passed by value, but since it contains a pointer to the data it will be passed by reference. Note that if you do: void foo (int[]

Re: Why are fixed length arrays passed by value while variable are passed by reference?

2013-04-18 Thread Simen Kjaeraas
On 2013-04-18, 16:20, ixid wrote: An array is represent using a struct with a pointer to the array data and the length, like this: struct Array { void* ptr; size_t length; } The struct is passed by value, but since it contains a pointer to the data it will be passed by reference.

Re: Why are fixed length arrays passed by value while variable are passed by reference?

2013-04-18 Thread Maxim Fomin
On Thursday, 18 April 2013 at 13:37:45 UTC, ixid wrote: I know this will not be changed, I just want to understand why it is as it is. My naive thought is that consistency is the best scheme and that everything should have been passed by value or everything by reference unless the user

Re: Why are fixed length arrays passed by value while variable are passed by reference?

2013-04-18 Thread Ali Çehreli
On 04/18/2013 07:20 AM, ixid wrote: Jacob Carlborg said: An array is represent using a struct with a pointer to the array data and the length, like this: struct Array { void* ptr; size_t length; } The terms array and slice are commonly interchanged but I think it adds to the

Re: Why are fixed length arrays passed by value while variable are passed by reference?

2013-04-18 Thread Steven Schveighoffer
On Thu, 18 Apr 2013 11:26:22 -0400, Maxim Fomin ma...@maxim-fomin.ru wrote: On Thursday, 18 April 2013 at 13:37:45 UTC, ixid wrote: I know this will not be changed, I just want to understand why it is as it is. My naive thought is that consistency is the best scheme and that everything

Re: Why are fixed length arrays passed by value while variable are passed by reference?

2013-04-18 Thread ixid
I don't consider curent situation with static arrays as incosistent. When correctly understood is isn't as inconsistent, thank you for explaining, this was the knowledge I was after.

writeln an object

2013-04-18 Thread gedaiu
Hi, how i can control what writeln outputs when I pass an object parameter? Thanks, Bogdan

Re: writeln an object

2013-04-18 Thread JN
On Thursday, 18 April 2013 at 17:36:10 UTC, gedaiu wrote: Hi, how i can control what writeln outputs when I pass an object parameter? Thanks, Bogdan You can override the toString() method, like this http://dpaste.dzfl.pl/db7dbe28

Re: writeln an object

2013-04-18 Thread gedaiu
On Thursday, 18 April 2013 at 17:42:53 UTC, JN wrote: On Thursday, 18 April 2013 at 17:36:10 UTC, gedaiu wrote: Hi, how i can control what writeln outputs when I pass an object parameter? Thanks, Bogdan You can override the toString() method, like this http://dpaste.dzfl.pl/db7dbe28

Re: writeln an object

2013-04-18 Thread Andrej Mitrovic
On 4/18/13, gedaiu szabobog...@yahoo.com wrote: i've done that but i get this error: Error: function base.Value.Value.toString cannot override a non-virtual function Error: function base.Value.Value.toString override only applies to class member functions If it's a struct then don't put

Re: writeln an object

2013-04-18 Thread John Colvin
On Thursday, 18 April 2013 at 18:04:03 UTC, Andrej Mitrovic wrote: On 4/18/13, gedaiu szabobog...@yahoo.com wrote: i've done that but i get this error: Error: function base.Value.Value.toString cannot override a non-virtual function Error: function base.Value.Value.toString override only

Re: writeln an object

2013-04-18 Thread gedaiu
On Thursday, 18 April 2013 at 18:25:21 UTC, John Colvin wrote: On Thursday, 18 April 2013 at 18:04:03 UTC, Andrej Mitrovic wrote: On 4/18/13, gedaiu szabobog...@yahoo.com wrote: i've done that but i get this error: Error: function base.Value.Value.toString cannot override a non-virtual

Re: writeln an object

2013-04-18 Thread David
Just drop the override: struct Value { string strVal; this(string val) { strVal = val; } override string toString() { return strVal; } } struct Value { string strVal; this(string val) { strVal = val; } string

Re: writeln an object

2013-04-18 Thread John Colvin
On Thursday, 18 April 2013 at 18:46:09 UTC, gedaiu wrote: i have a struct not an object. There's a slight nomenclature clash here: Object is the base class in D. Therefore one could say that an object is an instatiation of Object and therefore a class. However, by a wider definition of the

Re: writeln an object

2013-04-18 Thread Ali Çehreli
On 04/18/2013 12:37 PM, John Colvin wrote: However, by a wider definition of the word, a struct could also be said to be an object. You are missing some words there. :) Not a struct itself, but instances of it are said to be objects. Ali

Assigning a static array

2013-04-18 Thread Brad Anderson
Is this supposed to be allowed: ubyte[] a; ubyte[16] b; a = b; assert(a.ptr == b.ptr); Because if so that makes it terribly easy to do a bug like this (as I just saw in IRC): struct A { ubyte[] a; this(ubyte c) { ubyte[16] b; b[] = c; this.a = b; // a now

Re: Assigning a static array

2013-04-18 Thread Brad Anderson
For reference, here was what user soos on IRC was doing that caused him to hit this http://dpaste.dzfl.pl/08ee7b76#: import std.digest.md; import std.stdio; struct Hash { ubyte[] hash1; ubyte[] hash2; this (string str) { auto md5 = new MD5Digest(); this.hash1 = md5.digest(str);

Re: Assigning a static array

2013-04-18 Thread Jonathan M Davis
On Thursday, April 18, 2013 23:06:32 Brad Anderson wrote: Is this supposed to be allowed: ubyte[] a; ubyte[16] b; a = b; assert(a.ptr == b.ptr); Because if so that makes it terribly easy to do a bug like this (as I just saw in IRC): struct A { ubyte[] a; this(ubyte c) {

Re: Assigning a static array

2013-04-18 Thread Ali Çehreli
On 04/18/2013 02:06 PM, Brad Anderson wrote: Is this supposed to be allowed: ubyte[] a; ubyte[16] b; a = b; assert(a.ptr == b.ptr); Because if so that makes it terribly easy to do a bug like this (as I just saw in IRC): struct A { ubyte[] a; this(ubyte c) { ubyte[16]

Re: Assigning a static array

2013-04-18 Thread bearophile
Brad Anderson: Is this supposed to be allowed: ubyte[] a; ubyte[16] b; a = b; assert(a.ptr == b.ptr); Yes, this is supposed to be allowed with the current design of D. But with the latest dmd 2.063alpha that code doesn't work, see below. The Rust language removes this source of bugs

Re: Assigning a static array

2013-04-18 Thread bearophile
Jonathan M Davis: I could see an argument that it should have to be a = b[]; so that the slicing is explicit instead of just a = b; where it's implicit, but AFAIK, that's not currently required. It's currently a warning, and it will be required. -- Ali Çehreli:

Re: Assigning a static array

2013-04-18 Thread Brad Anderson
On Thursday, 18 April 2013 at 21:45:56 UTC, bearophile wrote: Yes, this is supposed to be allowed with the current design of D. But with the latest dmd 2.063alpha that code doesn't work, see below. [snip] Now that code gives a warning: temp.d(11): Warning: explicit slice assignment

Re: Assigning a static array

2013-04-18 Thread Steven Schveighoffer
There is a similar problem with the automatically generated array arguments. The following constructor takes any number of ints that come in array form: import std.stdio; struct S { int[] a; this(int[] args...) { a = args; } void foo() {

Re: Assigning a static array

2013-04-18 Thread bearophile
Steven Schveighoffer: There is no guarantee that the incoming array from a variadic function is heap-based. But an interesting way to deal with it is that you can overload with an explicit slice parameter, and the variadic version will ONLY bind to a variadic call. For example, in

Re: Assigning a static array

2013-04-18 Thread Ali Çehreli
On 04/18/2013 02:54 PM, Steven Schveighoffer wrote: The program prints the following because the temporary arrays that are generated when calling the constructors are long gone: [1, 1, 1] [1, 1, 1] The programmer *may have* ;) expected the following output: [1, 1, 1] [2, 2, 2] There

Re: Assigning a static array

2013-04-18 Thread H. S. Teoh
On Thu, Apr 18, 2013 at 02:43:54PM -0700, Ali Çehreli wrote: On 04/18/2013 02:06 PM, Brad Anderson wrote: Is this supposed to be allowed: ubyte[] a; ubyte[16] b; a = b; assert(a.ptr == b.ptr); Because if so that makes it terribly easy to do a bug like this (as I just saw in IRC):

Re: refuses to open file

2013-04-18 Thread rbtwms
Let's start over it has nothing to due with the file. It's the file name thats the problem. I wote a short test program to demenstrate the problem. It shows that if the file name has a path it causes the exception. i.e: (prompt)dir Volume in drive C is OS Volume Serial Number is E221-AB60

Re: A little of coordination for Rosettacode

2013-04-18 Thread bearophile
Maybe there is a way to translate this Haskell version to D with bigints: http://rosettacode.org/wiki/Find_largest_left_truncatable_prime_in_a_given_base#Haskell Unrelated: now I have a kind of efficient longest common subsequence algorithm with O(n) memory usage. Maybe there is some

Re: refuses to open file

2013-04-18 Thread Ali Çehreli
On 04/18/2013 04:25 PM, rbt...@digitalpath.net wrote: Let's start over it has nothing to due with the file. It's the file name thats the problem. Let's start with the obvious. :) Directory of c:\d\projects\equipment std.exception.ErrnoException@std\stdio.d(289): Cannot open file

Re: Copying reference types by value

2013-04-18 Thread Ali Çehreli
On 04/18/2013 06:22 AM, Joseph Rushton Wakeling wrote: On 04/17/2013 10:29 PM, Ali Çehreli wrote: Yes but as I said I am not sure how useful or needed this whole thing is. The language handles copy, move, and assignment for structs. takeOver() seems to be a primitive operation for