Re: gc
gc1thread1 thread2 thread3 gc2thread4 thread5 when the gc1 cycles it does not block the gc2 threads. Would that be of any use? Or possible. And only use communication like between two processes, some interprocess communication message passing thing. I mean the entire pure thing makes heavy use of the garbage collector, maybe isolating them is a solution, just let it cycle independent from the rest. But on the other hand you could just make two processes. Reflection-->Serialization->Remoting 1) Reflection @transient [NonSerialized] 2) Serialization Some form of reflection would be handy to simplify the serialization. Also the use of the notion "Property" comes in handy, as to which fields are selected. 3) Remoting There are serialization libraries outside of phobos like in tango but they must be put into phobos itself and the Exception needs to be serializable too in order for the "remoting" thing to work. When communicating between "Application Domains" like in C# when inheriting from exceptions, you need to make sure that the exception class is serializable. class Exception:ISerializable { } I can't find the Exception class anywhere, where is that defined? in core.exception there is some Error stuff. Is it defined in the compiler then?
Re: generic + numeric + literals = abomination
With one exception yes, i want all 3 test pass with your fix to implicit cast. You know, we are trying to write generic code. Thanks! On Sat, 27 Mar 2010 22:21:46 +0200, bearophile wrote: Are you trying to do this? import std.stdio: writeln; struct Vector(T) { this(T m) { mm = m; } Vector opBinary(string op:"*", T2)(T2 m) if(is(T2 == T)) { return Vector(mm * m); } T mm; } void test(T)() { Vector!T v = Vector!T(0.5); Vector!T u = v * 0.3; writeln("u: ", u.mm); } void main() { //test!float(); test!double(); //test!real(); } Bye, bearophile -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
gc
Is it possible to have multiple gc
Re: generic + numeric + literals = abomination
so: > With this in mind, just one thing bugs me. > > > import std.stdio; > > struct vector(T) { > this(T m) { mm = m; } > vector!T opBinary(string s)(T m) if(s=="*") { > return vector!T(mm * m); > } > T mm; > } > > void test(T)() { > vector!T v = vector!T(0.5); > vector!T u = v * 0.3; > writeln("u: ", u.mm); > } > > void main() { > test!float(); > test!double(); > test!real(); > } > - > > This program compiles and runs just fine, but i feel dirty, you see I > explicitly stated that opBinary takes a variable of type T, > but it accepted 0.3 on all 3 tests, implicitly casted double to T. In C++ > world this brings tons of trouble, especially performance problems, > but here i am not sure what DMD does that there :) Are you trying to do this? import std.stdio: writeln; struct Vector(T) { this(T m) { mm = m; } Vector opBinary(string op:"*", T2)(T2 m) if(is(T2 == T)) { return Vector(mm * m); } T mm; } void test(T)() { Vector!T v = Vector!T(0.5); Vector!T u = v * 0.3; writeln("u: ", u.mm); } void main() { //test!float(); test!double(); //test!real(); } Bye, bearophile
Re: generic + numeric + literals = abomination
Le 27/03/10 18:18, so a écrit : With this in mind, just one thing bugs me. import std.stdio; struct vector(T) { this(T m) { mm = m; } vector!T opBinary(string s)(T m) if(s=="*") { return vector!T(mm * m); } T mm; } void test(T)() { vector!T v = vector!T(0.5); vector!T u = v * 0.3; writeln("u: ", u.mm); } void main() { test!float(); test!double(); test!real(); } - This program compiles and runs just fine, but i feel dirty, you see I explicitly stated that opBinary takes a variable of type T, but it accepted 0.3 on all 3 tests, implicitly casted double to T. In C++ world this brings tons of trouble, especially performance problems, In this case, when is(T==real), you could have a precision problem more than a performance problem. You lose less precision if you always use literals of the most precise type (eg 0.3L). Performance problems could occur in C++ when your template type is 'long double' (?). But then if 'double' is the most efficient type and if you want performance, use it explictly everywhere.
Re: DMD on x86_64
tried the your approach it worked but compile cpp applications fails. [Sanity Checks - fails] i found my way arround it by installing cross32-gcc and adding CC=/usr/bin/i686-unknown-linux-gnu-gcc to the dmd.conf file I have added the procedure to Wiki4D http://www.prowiki.org/wiki4d/wiki.cgi?D__Tutorial/StartingWithD/ Compiler/DMD#ArchLinuxASaferSolutionD
Re: generic + numeric + literals = abomination
Oh... wait a second. In http://www.digitalmars.com/d/2.0/float.html : "Regardless of the type of the operands, floating point constant folding is done in real or greater precision. It is always done following IEEE 754 rules and round-to-nearest is used. Floating point constants are internally represented in the implementation in at least real precision, regardless of the constant's type. The extra precision is available for constant folding. Committing to the precision of the result is done as late as possible in the compilation process" Wow! DMD already doing it, with or without literal! With this in mind, just one thing bugs me. import std.stdio; struct vector(T) { this(T m) { mm = m; } vector!T opBinary(string s)(T m) if(s=="*") { return vector!T(mm * m); } T mm; } void test(T)() { vector!T v = vector!T(0.5); vector!T u = v * 0.3; writeln("u: ", u.mm); } void main() { test!float(); test!double(); test!real(); } - This program compiles and runs just fine, but i feel dirty, you see I explicitly stated that opBinary takes a variable of type T, but it accepted 0.3 on all 3 tests, implicitly casted double to T. In C++ world this brings tons of trouble, especially performance problems, but here i am not sure what DMD does that there :) Thanks. On Sat, 27 Mar 2010 16:44:32 +0200, bearophile wrote: so: When i have the code : scalar m = 0.5fp; I want compiler to implicitly cast it to typeof(scalar). so when the scalar is float, m will be 0.5f. I am starting to understand, sorry if I am a dumb bear :-) Programming in C++/D is usually much less hard than understanding humans. I think you mean an universal FP literal that's automatically cast-able to any other floating point type, in template arguments too. Are you able to write a 10 lines long D program that shows a compile-time error that you don't want to happen? I am willing to fix your code until it shows what you want to show me (assuming it's a real problem in D). Bye, bearophile -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Re: generic + numeric + literals = abomination
I think you would end up creating a scalar class/struct with operator overloading to get the behavior you are looking for. I realize that is more overhead than what you would want but I don't see another way. so wrote: > In C++! > > I have a type defined in the core library like.. > typedef float scalar; > //typedef double scalar; // <-- whole framework is now double precision > > Next i instantiate vectors, matrices etc... from templates. > typedef vector_t vector; > typedef matrix_t matrix; > > Until now everything cool, here pain comes... > > const scalar a = scalar(0.2) * math::consts::pi; // can't drop > cast, since 0.2 is double > const scalar b = a * scalar(0.9) + scalar(5); // " " > const vector v = vector(8.0) * scalar(3.0); // can't drop cast, error > ... > > Since D is superb, i like to know how you do it in D. > If you got a better idea in C++, i would like to hear that too! > > Thanks! >
non halting regex
Is this program expected to terminate? D 2.042 module test; import std.regex; import std.stdio; void main(){ foreach(m; match("hello world",`.*`)){ writefln("%s[%s]%s",m.pre,m.hit,m.post); } }
Re: generic + numeric + literals = abomination
so: > When i have the code : > scalar m = 0.5fp; > > I want compiler to implicitly cast it to typeof(scalar). > so when the scalar is float, m will be 0.5f. I am starting to understand, sorry if I am a dumb bear :-) Programming in C++/D is usually much less hard than understanding humans. I think you mean an universal FP literal that's automatically cast-able to any other floating point type, in template arguments too. Are you able to write a 10 lines long D program that shows a compile-time error that you don't want to happen? I am willing to fix your code until it shows what you want to show me (assuming it's a real problem in D). Bye, bearophile
Re: generic + numeric + literals = abomination
On Sat, 27 Mar 2010 15:54:19 +0200, Bill Baxter wrote: Note that 'real' is a built in type in D. It's an 80-bit float on x86 procs and 64-bit elsewhere. So .5L is like cast(real).5. Not the solution you were looking for. --bb That "r for real!" was joke. What i mean is a literal/template/placeholder/younameit, explicitly states that number is a floating point. Lets name it "fp". When i have the code : scalar m = 0.5fp; I want compiler to implicitly cast it to typeof(scalar). so when the scalar is float, m will be 0.5f. Another example : Again, lets try pi. const scalar pi = 3.14{longest you can find}fp Now whenever i switch precision, by changing the type of scalar, i got the pi in that precision. Thanks! :) -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Re: Never called destructor
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Don wrote: > div0 wrote: >> -BEGIN PGP SIGNED MESSAGE- >> Hash: SHA1 > > Same as bug 3285 / bug 3516? No, they are for structs, not classes. I had a bit more of a play, and it seems that the scope object is on the stack, so it's memory is reclaimed, but the destructor is called for the y object instead. It would be much simpler just to disallow reassignment of the scope var and probably it should not be allowed to assign the ref of a scope object to another reference either to stop you accidentally escaping the ref. Also 3566 is a related bug. So delete of a scope var needs to go as well. - -- My enormous talent is exceeded only by my outrageous laziness. http://www.ssTk.co.uk -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.7 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iD4DBQFLrhFkT9LetA9XoXwRAnP/AJj5ncrtZI8rY623FYeZTlsVzbWzAJ41+ehQ P51WDDNU4Hdo2SOoZqOLxw== =kAfC -END PGP SIGNATURE-
Re: initializing immutable structs
On Fri, 26 Mar 2010 06:35:29 +0100, Paul D. Anderson wrote: I want to initialize an immutable struct but I'm encountering two difficulties and I can't find the answer in the documentation. (Wouldn't it be nice if someone wrote a book?) You mean like this? http://www.amazon.com/dp/0321635361 The primary difficulty is that I can't use a static initializer but need to use a constructor instead. But the constructor isn't allowed as it's non-constant expression. How do I declare the struct variable and initialize it separately? If your constructor is not CTFE-able, you're basically out of luck. The following kinda works, but will probably not survive optimizations, and is a horrible hack to break the type system: struct S { int n; this( int n ) { this.n = n; } } immutable S s = S( 4 ); void main( ) { void* v = cast( void* )&s; ( *cast( S* )v ) = S( 4 ); } The second difficulty is that when I declare it immutable I get a "can't implicitly convert an expression of type X to to immutable X" error. I tried an explicit cast and that didn't work. This is indeed correct. D has a three-part const system, with both mutable and immutable implicitly castable to const, but nothing castable to immutable or mutable. Immutable basically means 'will never change'. Hence, assigning something that can change (mutable) or something that might change (const) to an immutable variable will not work. If you have created a mutable or const struct and want to convert it to immutable, make sure there are no references to it, and use std.contract's AssumeUnique http://www.digitalmars.com/d/2.0/phobos/std_contracts.html#assumeUnique Conversion of POD structs (no pointer or class members) to immutable should be painless, as they are pure value types and can be safely copied. I'm reasonably certain that this is a common idiom. I'm just trying to declare some constants to use later. What am I missing? Thanks, Paul 1st Difficulty -- I can't -- Simen
Re: generic + numeric + literals = abomination
On Sat, 27 Mar 2010 12:20:38 +0200, so wrote: I haven't seen a single C++ library able to do this properly. (I would just copy it!) This is one of the reasons why something like std::numeric_limits::function() exists. Which makes a generic and *clean* numeric code in C++ nonexistent. Don! Please enlighten us! (especially me...) *begs* -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Re: generic + numeric + literals = abomination
Note that 'real' is a built in type in D. It's an 80-bit float on x86 procs and 64-bit elsewhere. So .5L is like cast(real).5. Not the solution you were looking for. --bb 2010/3/27 so : > On Sat, 27 Mar 2010 15:28:22 +0200, bearophile > wrote: > >> so: >>> >>> One thing i can think of now is adding another float literal, maybe 'r', >>> for "real"!, >> >> See here, Unfortunately it's called "L" not "r": >> http://www.digitalmars.com/d/2.0/lex.html >> >> FloatSuffix: >> f >> F >> >> RealSuffix: >> L >> >> bearophile > > Yes, it says : > "Floating literals with no suffix are of type double. Floats can be followed > by one f, F, or L suffix. The f or F suffix means it is a float, and L means > it is a real." > > Problem remains, i think you either lost me or just didn't read what i > wrote, > or well.. most probably i am still not clear enough. > > -- > Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ >
Re: generic + numeric + literals = abomination
On Sat, 27 Mar 2010 15:28:22 +0200, bearophile wrote: so: One thing i can think of now is adding another float literal, maybe 'r', for "real"!, See here, Unfortunately it's called "L" not "r": http://www.digitalmars.com/d/2.0/lex.html FloatSuffix: f F RealSuffix: L bearophile Yes, it says : "Floating literals with no suffix are of type double. Floats can be followed by one f, F, or L suffix. The f or F suffix means it is a float, and L means it is a real." Problem remains, i think you either lost me or just didn't read what i wrote, or well.. most probably i am still not clear enough. -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Re: generic + numeric + literals = abomination
so: > One thing i can think of now is adding another float literal, maybe 'r', > for "real"!, See here, Unfortunately it's called "L" not "r": http://www.digitalmars.com/d/2.0/lex.html FloatSuffix: f F RealSuffix: L bearophile
Re: generic + numeric + literals = abomination
On Sat, 27 Mar 2010 13:52:28 +0200, bearophile wrote: Can you explain better what the problem is and what kind of solution you would like? Bye, bearophile One thing i can think of now is adding another float literal, maybe 'r', for "real"!, Which means you are free to cast this to any floating point suitable. Some kind of template, i don't know! So when i have something like this : scalar m = 0.99r; when scalar is f32 : scalar m = 0.99f; when scalar is f64 : scalar m = 0.99; ... And it is easy to detect for the compiler i guess. scalar m = 0.2r; // just cast it to scalar, user wants to assign to a scalar scalar n = m * 4.5r; // again just cast it to scalar, user wants to multiply by a scalar. ... Thanks :) -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Re: generic + numeric + literals = abomination
On Sat, 27 Mar 2010 13:32:24 +0200, Robert Clipsham wrote: On 27/03/10 10:20, so wrote: In C++! I have a type defined in the core library like.. typedef float scalar; //typedef double scalar; // <-- whole framework is now double precision alias float scalar; //alias double scalar; Next i instantiate vectors, matrices etc... from templates. typedef vector_t vector; typedef matrix_t matrix; alias Vector!(scalar, 3) vector; // Presuming you have defined // the Vector!() template somewhere alias Matrix!(scalar, 3, 3) matrix; // Presuming Matrix!() is defined Until now everything cool, here pain comes... const scalar a = scalar(0.2) * math::consts::pi; // can't drop cast, since 0.2 is double const scalar a = 0.2 * PI; // PI is defined in std.math const scalar b = a * scalar(0.9) + scalar(5); // " " const scalar b = a * 0.9 * 5.0; const vector v = vector(8.0) * scalar(3.0); // can't drop cast, error const vector v = vector(8.0) * 3.0; ... Since D is superb, i like to know how you do it in D. If you got a better idea in C++, i would like to hear that too! Thanks! There are a few vector implementations for D out there, or you can roll your own. I'm pretty sure there's matrices out there too, I haven't checked though (I'm pretty sure D's built in arrays will do the trick, I'm not an expert though). Even the example looks/sounds simple, i am not that new in C++/D programming :) If one comes to D from C++, he is most likely pushing limits of the C++ templates/numerics. PI was just an example, i could find another constant, but then you would point me to a SI unit implementation. :) For : const scalar a = 0.2 * PI; // both double implicit cast to scalar, when it is float, this must produce a warning? const scalar b = a * 0.9 * 5.0; // same const vector v = vector(8.0) * 3.0; // 3.0 is a double, when scalar is float, this line must not compile I think you should try it first, DMD should also give warnings/errors here. Thanks! -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Re: generic + numeric + literals = abomination
On Sat, 27 Mar 2010 13:52:28 +0200, bearophile wrote: so: Since D is superb, i like to know how you do it in D. If you got a better idea in C++, i would like to hear that too! You know there are float literal too, in C++/D, like: 5.5f I don't think D can help you more than C++ here. Can you explain better what the problem is and what kind of solution you would like? Bye, bearophile You are right, i guess i wasn't clear enough. In 5.5f, f is the float literal, i am trying to write generic code. Say i changed the type to f64(double), or f128 by just changing a line. typedef f128 scalar; // or in D alias f128 scalar; So each cast above will be like f128(5.5f)... What have i gained by increasing precision to 64 or 128 bit here? Clear enough? :) Thanks! -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Re: generic + numeric + literals = abomination
so: > Since D is superb, i like to know how you do it in D. > If you got a better idea in C++, i would like to hear that too! You know there are float literal too, in C++/D, like: 5.5f I don't think D can help you more than C++ here. Can you explain better what the problem is and what kind of solution you would like? Bye, bearophile
Re: generic + numeric + literals = abomination
On 27/03/10 10:20, so wrote: In C++! I have a type defined in the core library like.. typedef float scalar; //typedef double scalar; // <-- whole framework is now double precision alias float scalar; //alias double scalar; Next i instantiate vectors, matrices etc... from templates. typedef vector_t vector; typedef matrix_t matrix; alias Vector!(scalar, 3) vector; // Presuming you have defined // the Vector!() template somewhere alias Matrix!(scalar, 3, 3) matrix; // Presuming Matrix!() is defined Until now everything cool, here pain comes... const scalar a = scalar(0.2) * math::consts::pi; // can't drop cast, since 0.2 is double const scalar a = 0.2 * PI; // PI is defined in std.math const scalar b = a * scalar(0.9) + scalar(5); // " " const scalar b = a * 0.9 * 5.0; const vector v = vector(8.0) * scalar(3.0); // can't drop cast, error const vector v = vector(8.0) * 3.0; ... Since D is superb, i like to know how you do it in D. If you got a better idea in C++, i would like to hear that too! Thanks! There are a few vector implementations for D out there, or you can roll your own. I'm pretty sure there's matrices out there too, I haven't checked though (I'm pretty sure D's built in arrays will do the trick, I'm not an expert though).
generic + numeric + literals = abomination
In C++! I have a type defined in the core library like.. typedef float scalar; //typedef double scalar; // <-- whole framework is now double precision Next i instantiate vectors, matrices etc... from templates. typedef vector_t vector; typedef matrix_t matrix; Until now everything cool, here pain comes... const scalar a = scalar(0.2) * math::consts::pi; // can't drop cast, since 0.2 is double const scalar b = a * scalar(0.9) + scalar(5); // " " const vector v = vector(8.0) * scalar(3.0); // can't drop cast, error ... Since D is superb, i like to know how you do it in D. If you got a better idea in C++, i would like to hear that too! Thanks! -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/