Re: Frontend and backend communication

2011-08-10 Thread Pelle
On Wed, 10 Aug 2011 10:35:46 +0200, Dainius (GreatEmerald) past...@gmail.com wrote: I seem to have run into a problem with the function pointer method here. I have this code: arco.d: struct FrontendFunctions { void function(SoundTypes) Sound_Play; void function()

Re: More than one invariant per struct/class

2011-08-08 Thread Pelle
On Sat, 06 Aug 2011 22:53:31 +0200, Jonathan M Davis jmdavisp...@gmx.com wrote: Feel free to create a feature request on it. It may even get the language changed. However, having more than one invariant complicates things a bit, since right now, it's easy for the runtime to just call the

Re: Multi-file byte comparison tool. What would you have done differently?

2011-08-08 Thread Pelle
On Fri, 05 Aug 2011 18:43:27 +0200, Kai Meyer k...@unixlords.com wrote: On 08/05/2011 03:02 AM, Pelle wrote: Don't declare variables until you need them, just leave bytes_read and bytes_max here. Is there a performance consideration? Or is it purely a style or D-Factor suggestion? Just

Re: Multi-file byte comparison tool. What would you have done differently?

2011-08-05 Thread Pelle
On Fri, 05 Aug 2011 00:25:38 +0200, Kai Meyer k...@unixlords.com wrote: I have a need for detecting incorrect byte sequences in multiple files (2) at a time (as a part of our porting effort to new platforms.) Ideally the files should be identical for all but a handful of byte sequences (in

Re: NaCl stable ABI

2011-08-05 Thread Pelle
On Thu, 04 Aug 2011 21:56:16 +0200, Nick Sabalausky a@a.a wrote: OT: Who the hell uses MSN? Almost everyone below 60 in Sweden, at least a few years ago.

Re: More than one invariant per struct/class

2011-08-04 Thread Pelle
On Thu, 04 Aug 2011 11:32:03 +0200, simendsjo simend...@gmail.com wrote: I would like to use a template mixin to add some fields to a struct, but I'd also like the template to add additional invariant checks without having to remember to add this for all struct/classes that mixes in this

Re: More than one invariant per struct/class

2011-08-04 Thread Pelle
On Thu, 04 Aug 2011 12:40:48 +0200, simendsjo simend...@gmail.com wrote: On 04.08.2011 12:30, Pelle wrote: What happens if you replace assert(_c) with assert(_c !is null)? The problem is that you cannot include more than one invariant() in a struct or class. IIRC assert(obj) gets

Re: Convert string to wchar.

2011-08-03 Thread Pelle
On Wed, 03 Aug 2011 08:29:09 +0200, Jacob Carlborg d...@me.com wrote: Yes, convert the first code point to a wchar and then throw if there's more the one character in the string. Not tested, and I might be wrong, but 'to!' should work between dchar and wchar, no? wchar to_wchar(string

Re: Generate array of random values

2011-08-02 Thread Pelle
On Mon, 01 Aug 2011 21:43:13 +0200, Andrej Mitrovic andrej.mitrov...@gmail.com wrote: Actually I don't really need *uniform* distribution, it's just that when porting C code to D I didn't find any obvious random()/rnd() functions, and uniform seemed to be the closest thing without having to

Re: Empy program running time

2011-07-29 Thread Pelle
On Fri, 29 Jul 2011 15:37:36 +0200, bearophile bearophileh...@lycos.com wrote: On an oldish Windows PC an empty C program generated by GCC takes about 0.03 seconds to run. An empty D2 program runs in about 0.11 seconds. Is this expected/good/acceptable/fixable? Bye, bearophile That's a

Re: Frontend and backend communication

2011-07-28 Thread Pelle
On Wed, 27 Jul 2011 19:41:37 +0200, Dainius (GreatEmerald) past...@gmail.com wrote: I have one program design problem and I wonder if anyone here could give any suggestions about it. The situation is like this: I am splitting a game into a frontend (a library) and a backend (an executable).

Re: Importing D libraries

2011-07-26 Thread Pelle
On Tue, 26 Jul 2011 13:06:56 +0200, Dainius (GreatEmerald) past...@gmail.com wrote: I updated the DMD and tried RDMD, but still no luck. Linker errors galore. You can see all of them here: http://pastebin.com/C6cRVGKt You need to link the library as well, try adding -L-llua (I think) to the

Re: Calling anonymous delegate recursively ?

2011-01-08 Thread Pelle
On 01/08/2011 04:45 PM, tsukikage wrote: eg. to return a fibonacci delegate: return (ulong m) { if(m 2) return m ; return _self_ref(m-1)+_self_ref(m-2) ; } ; Is it possible? Thank you! http://en.wikipedia.org/wiki/Fixed_point_combinator#Y_combinator I don't think there's a built in way to

Re: How the GC distinguishes code from data

2011-01-06 Thread Pelle
On 01/06/2011 07:31 AM, %u wrote: If you have allocated a large uint[], most likely =C3=ACt will be flagged NO_SCAN, meaning it has no pointers in it, and the GC will ignore it. Ah, but the trouble is, no one said that this array has to be in the GC heap! I could easily have a void[] and a

Re: terminology: l-value r-value

2011-01-04 Thread Pelle
On 01/04/2011 02:55 PM, spir wrote: Hello, I'm bluffed by the 2 terms l-value r-value used in C-line language common terminologies. I think I guess what they mean, but I don't understand the need for such absconse idioms. Why not: l-value- variable r-value- value (or

Re: Odd to!string call

2010-12-26 Thread Pelle
On 12/21/2010 07:38 PM, Andrej Mitrovic wrote: I found this by accident: import std.stdio; import std.conv; void main() { writeln(to!string(2, 2)); // writes 10 writeln(to!string(1, 0)); // std.conv.ConvException: Radix error } I'm not sure why std.conv.to would even take multiple

Re: List of derived types?

2010-12-16 Thread Pelle Månsson
On 12/16/2010 02:16 PM, d coder wrote: Greetings I need a way to know (using traits or other compile time constructs) all the types derived from a given type. Is it possible in D? Is it possible to get a list of all the user-defined classes? I could use that to filter out the classes that I

Re: Concurrency and transfering ownership of data between threads?

2010-12-14 Thread Pelle Månsson
On 12/13/2010 09:45 PM, Heywood Floyd wrote: Good Evening from Berlin! Have been reading the chapter about concurrency by Andrei. Nice. I have some questions, of varying quality, I'm sure. Let's say that we have some sort of structure of rather complex data. To give us something concrete

Re: import inside a class overrides symbols imported in module scope?

2010-12-09 Thread Pelle Månsson
On 12/09/2010 10:53 PM, Trass3r wrote: It was quite hard to track that one down. In the following example the import statement was mixed into the class among other code so it wasn't as obvious as here. import std.traits; class Foo { import std.string; static assert(isNumeric!int); } foo.d(6):

Re: C++ istream / ostream equivalent ?

2010-12-02 Thread Pelle Månsson
On 12/02/2010 09:05 AM, vincent picaud wrote: Matthias Pleh Wrote: Thank you for your reply and yes that works :) Now i m facing with the following problem, what is the trick for input stream ? ( something like std::istream operator(std::istream in,A a) { // A.someData in;

Re: 'in' for plain arrays?

2010-12-02 Thread Pelle Månsson
On 12/02/2010 01:07 PM, spir wrote: Hello, Is there an equivalent of 'in' for (non-associative) arrays? Cannot find any 'contains' function. (Wouldn't it be nice to have in work for all arrays? What is the reason why it only works with AAs?) Denis -- -- -- -- -- -- -- vit esse estrany ☣

Re: Const foreach

2010-11-22 Thread Pelle Månsson
On 11/22/2010 04:12 PM, Simen kjaeraas wrote: spir denis.s...@gmail.com wrote: On Sun, 21 Nov 2010 20:21:14 -0500 bearophile bearophileh...@lycos.com wrote: If in a D2 program I have an array of mutable items I may want to iterate on them but not modify them, so I'd like the iteration

Re: defining in a module symbols for export

2010-11-22 Thread Pelle Månsson
On 11/22/2010 08:18 PM, spir wrote: Hello, Let us say I have a parsing library. Now, I want to define parsers in stand-alone modules -- for code structuration and reusability. Then, import them from apps that need them. Is there another way than defining the parser (== list of patterns) at

Re: segfault

2010-11-14 Thread Pelle Månsson
On 11/12/2010 02:03 PM, Steven Schveighoffer wrote: Pelle, I spent all this time helping him, and you swoop in with the answer :) I was in a rush when answering, causing the swoopiness of my post. :-) I only knew the answer because I had almost exactly the same bug a week ago, or so

Re: Combining variadic functions with class templates

2010-09-30 Thread Pelle
On 09/30/2010 08:25 PM, Sebastian Schuberth wrote: On 30.09.2010 20:20, wrzosk wrote: void main() { Vec3f v(1,1,1); } I still get Building Release\ConsoleApp1.exe... main.d(14): found 'v' when expecting ';' following statement Building Release\ConsoleApp1.exe failed! Change Vec3f v(1,1,1);

Re: Immutable woes

2010-09-21 Thread Pelle
On 09/21/2010 09:29 AM, Bob Cowdery wrote: Hi I'm stuggling with immutable. I have a fixed size buffer which is used as a circular buffer of floats and is effectively double buffering data I wish to transfer to another thread. At an appropriate point I take the top half or bottom half of the

Re: ubyte[] - immutable(ubyte)[]

2010-09-10 Thread Pelle
On 09/10/2010 04:40 AM, Andrej Mitrovic wrote: I'm trying to use algorithm.copy, but I get back nothing in the copy buffer. How do I to copy an array of ubyte's? iimport std.algorithm, std.concurrency, std.stdio; void main() { enum bufferSize = 4; auto tid =

Re: slow runtime

2010-09-10 Thread Pelle
On 09/10/2010 10:17 AM, Jonathan M Davis wrote: On Friday 10 September 2010 00:50:32 bearophile wrote: Jonathan M Davis: Aren't they _always_ on the heap? void main() { int[10] a; int[] b = a[]; } Bye, bearophile Ah, good point. When you have a slice of a static array as opposed

Re: Question about typeof(this)

2010-09-10 Thread Pelle
On 09/10/2010 03:20 PM, Jacob Carlborg wrote: On 2010-09-07 22:32, Don wrote: Jacob Carlborg wrote: On 2010-09-07 17:29, Don wrote: Jacob Carlborg wrote: I'm reading http://www.digitalmars.com/d/2.0/declaration.html#Typeof where it says: typeof(this) will generate the type of what this

Re: Generic collection/element function signatures in D2 versus D1

2010-09-08 Thread Pelle
On 09/08/2010 02:24 PM, Steven Schveighoffer wrote: On Tue, 07 Sep 2010 14:06:58 -0400, Steven Schveighoffer schvei...@yahoo.com wrote: On Tue, 07 Sep 2010 11:37:20 -0400, Pelle pelle.mans...@gmail.com wrote: On 09/07/2010 04:33 PM, Steven Schveighoffer wrote: Yes, a valid return. Your

Re: Generic collection/element function signatures in D2 versus D1

2010-09-07 Thread Pelle
On 09/07/2010 03:15 PM, Steven Schveighoffer wrote: On Tue, 07 Sep 2010 08:56:15 -0400, Jacob Carlborg d...@me.com wrote: On 2010-09-07 14:49, Steven Schveighoffer wrote: On Sun, 05 Sep 2010 09:40:59 -0400, BLS windev...@hotmail.de wrote: On 05/09/2010 02:16, Jonathan M Davis wrote: void

Re: Generic collection/element function signatures in D2 versus D1

2010-09-07 Thread Pelle
On 09/07/2010 04:33 PM, Steven Schveighoffer wrote: Yes, a valid return. Your function should be: void foo(void delegate(const(C) f) const It helps to understand that inout/const/immutable has NOTHING to do with code generation, it only has to do with limiting what compiles. For this reason,

Re: Understanding isInfinite(Range)

2010-09-06 Thread Pelle
On 09/04/2010 02:11 PM, Simen kjaeraas wrote: Peter Alexander peter.alexander...@gmail.com wrote: == Quote from Steven Schveighoffer (schvei...@yahoo.com)'s article On Fri, 03 Sep 2010 11:12:29 -0400, Andrej Mitrovic andrej.mitrov...@test.com wrote: What does char[1 + Range.empty] do? It

Re: Understanding isInfinite(Range)

2010-09-06 Thread Pelle
On 09/06/2010 08:53 PM, Philippe Sigaud wrote: On Mon, Sep 6, 2010 at 18:47, Pelle pelle.mans...@gmail.com mailto:pelle.mans...@gmail.com wrote: On 09/04/2010 02:11 PM, Simen kjaeraas wrote: Is there a way you could write an isStatic(expr) template? Using template

Re: SO rotate question

2010-09-03 Thread Pelle
On 09/02/2010 10:24 PM, bearophile wrote: simendsjo: Suggestions for D-ifying the code is welcome. Your unit tests are not good enough, they miss some important corner cases. This my first version in D2: import std.string: indexOf; /// return True if s1 is a rotated version of s2 bool

Re: SO rotate question

2010-09-03 Thread Pelle
On 09/03/2010 01:35 PM, bearophile wrote: Pelle: bool isRotated(T)(T[] a, T[] b) { return a.length == b.length (a.length == 0 || canFind(chain(a,a), b)); } Nice clean solution. I suggest to add pure and two const in the signature. canFind isn't really the best possible name

Re: built-in string hash ?

2010-08-28 Thread Pelle
On 08/28/2010 10:25 PM, bearophile wrote: torhu: string a = abc; auto hash = typeid(a).getHash(a); If higher performance is necessary, you may pre-compute part of that: void main() { string a = abc; auto hash1 = typeid(a).getHash(a); auto stringHash =(typeid(a).getHash);

Re: associative array of associative arrays.

2010-08-13 Thread Pelle
On 08/13/2010 01:17 AM, dcoder wrote: Hello. How do you declare and initialize a map that looks like the following: Name = [ Personal Info] Where personal info is type string[string]. I can't get this to compile. I'm wondering what I am doing wrong: import std.stdio; void main() {

Re: Problem with std.array(std.regex.splitter())

2010-08-09 Thread Pelle
On 08/09/2010 12:50 AM, bearophile wrote: This D2 code: import std.regex: splitter, regex; import std.array: array; void main() { array(splitter(, abc, de, regex(, *))); } Gives the errors: test.d(4): Error: template std.array.array(Range) if (isForwardRange!(Range)) does not match any

Re: std.file.read

2010-08-02 Thread Pelle
On 08/02/2010 10:23 AM, Dmitry Olshansky wrote: On 02.08.2010 5:23, bearophile wrote: Can you tell me why std.file.read() returns a void[] instead of something like a ubyte[]? Well, it magically converts to whatever array type you have. So this works: ubyte[] data = read(trash.txt); This

Re: null dereference exception vs. segfault?

2010-08-02 Thread Pelle
On 08/02/2010 11:27 PM, bearophile wrote: Ryan W Sims: The problem isn't how to check it on a case-by-case basis, there are plenty of ways to check that a given pointer is non-null. The problem is debugging _unexpected_ null dereferences, for which a NPE or its equivalent is very helpful, a

Re: null dereference exception vs. segfault?

2010-08-02 Thread Pelle
On 08/03/2010 12:02 AM, bearophile wrote: Pelle: What I really wish for is non-nullable types, though. Maybe in D3... :P I think there is no enhancement request in Bugzilla about this, I will add one. I think there has been, at least this has been discussed on the newsgroup. To implement

Re: null dereference exception vs. segfault?

2010-08-02 Thread Pelle
On 08/03/2010 12:32 AM, bearophile wrote: Pelle: I think a good thing would be NonNull!T, but I haven't managed to create one. If this structure exists and becomes good practice to use, maybe we can get the good syntax in D3. In 20 years or so :P Maybe we are talking about two different

Re: null dereference exception vs. segfault?

2010-08-02 Thread Pelle
On 08/03/2010 01:08 AM, bearophile wrote: Pelle: struct NotNull(T) if(is(typeof(T.init !is null))) { Is this enough? struct NotNull(T) if (is(T.init is null)) { this(T t) { enforce(t !is null, Cannot create NotNull from null); enforce() is bad, use Design by Contract

Re: D2 map trouble

2010-07-28 Thread Pelle
On 07/28/2010 12:57 AM, Nick Sabalausky wrote: Trying to convert some D1 code to D2: On 2.047, I'm trying to do this: import std.string; void foo(string str) { str = std.algorithm.map!( (char a) { return inPattern(a, [digits, letters])? a : '_'; } )(str); } And I'm getting:

Re: Cannot initialize associative array.

2010-06-23 Thread Pelle
On 06/23/2010 09:41 AM, Ali Çehreli wrote: Ali Çehreli wrote: dcoder wrote: So, I moved the initialization to inside the main function, and now it works. Great. I think we need to put this question in the FAQ. For future reference, if it really needs to be global: uint[string] mywords;

Re: opAddAssign still works

2010-05-11 Thread Pelle
On 05/11/2010 01:38 AM, Trass3r wrote: Yeah it still works for compatibility reasons but is deprecated. Not yet, it's not. To compile something that's deprecated, you will need the -d switch. Right now, both are allowed, but the old one is scheduled for deprecation and presumably later

Re: Fixed-size arrays on the heap

2010-05-06 Thread Pelle
On 05/06/2010 01:10 PM, bearophile wrote: Lars T. Kyllingstad: In particular, note Kasumi Hanazuki's post and Andrei's response to it. Thank you, it seems Andrei agrees with me. But I think here thinks have to be kept tidy, otherwise it's easy to make a mess. The syntax offers various

Re: Operators overloading in D2 again

2010-05-03 Thread Pelle
On 05/03/2010 04:28 PM, Dan wrote: Hi, it certainly helps. However I can't help myself, I still thinking that this is the most complicated, hard read and to understand way to overload operators. Maybe there is something I'm missing but I can't really see the reason of all that. Other

Re: How to implement a copy

2010-03-19 Thread Pelle Månsson
On 03/18/2010 05:43 PM, Paul D. Anderson wrote: If I'm implementing a struct and want to provide for duplication, is there a standard way to implement this? Here's an example: //--- struct S { // members of the struct -- three integer values int a;

Re: Tidy attributes

2010-03-11 Thread Pelle Månsson
On 03/11/2010 10:20 PM, bearophile wrote: While looking for possible attribute problems to add to Bugzilla, I have seen the following D2 program compiles and runs with no errors or warnings: static foo1() {} static does not apply to free functions, I would guess this means the same as

Re: Tidy attributes

2010-03-11 Thread Pelle Månsson
On 03/11/2010 10:44 PM, bearophile wrote: As far as I know, it's enum that has that purpose. Oh, but they are not the same. enum declares a constant, whereas static declares a variable. A static global is still mutable. Thank you for your answers, bearophile Why thank you!

Re: Static attributes aren' immutable

2010-03-05 Thread Pelle Månsson
On 03/05/2010 07:50 PM, bearophile wrote: div0: putting it in Foo simply puts it in a namespace. So my (wrong) idea of immutable applied to a struct was that every thing in such namespace becomes immutable (I think this is a bit more intuitive). What do you think of modifying D2 so in a

Re: raii

2010-02-28 Thread Pelle Månsson
On 02/28/2010 09:16 PM, Ellery Newcomer wrote: Hello The impetus: I agree, except I more and more think that scope classes were a mistake. Structs with destructors are a much better solution, and wrapping a class inside a struct would give it RAII semantics. The problem: In designing a

Re: running an external .exe

2010-02-17 Thread Pelle Månsson
On 02/16/2010 08:09 PM, Funog wrote: Is it possible to run an external .exe and have access to its standard input/output? Apparently std.process does not allow this. You'll want to choose either the input or the output stream, otherwise you might get eaten by a deadlock.

Re: Why isn't == used to compare structs

2010-02-08 Thread Pelle Månsson
On 02/08/2010 01:48 PM, Trass3r wrote: Why isn't == used to compare the struct members in the code above? I mean, if I compare the structs with == it could also use == to compare the members. If I use is to compare the structs it could use is to compare them members. Structs are compared

Re: default opAssign(string) behaviour

2010-01-28 Thread Pelle Månsson
On 01/28/2010 02:32 AM, strtr wrote: Personally, I use (D1)std2.conv a lot to get values from strings and thus would love the following default behaviour for all types: int i = 0; // i = 0 i = cast( int ) 0; // i = 48 ( If I read the utf8 table correctly ) What keeps this from being the case?

Re: boolean over multiple variables

2010-01-26 Thread Pelle Månsson
On 01/26/2010 01:02 AM, Nick Sabalausky wrote: strtrst...@spam.com wrote in message news:hjd6t1$be...@digitalmars.com... This may be is a very basic question, but is there a way to let me omit a repeating variable when doing multiple boolean operations? if ( var == a || var == b || var == c

Re: boolean over multiple variables

2010-01-25 Thread Pelle Månsson
On 01/23/2010 12:29 AM, strtr wrote: Simen kjaeraas Wrote: Not tested, but they should work: if ( anySame( var, a, b, c, d ) ) { } if ( allSame( var, a, b, c, d ) ) { } A lot prettier. I thought there would be a generic (basic) solution to this which I just didn't know about but maybe I

Timer library?

2010-01-25 Thread Pelle Månsson
I'm in need for a timer library that measures the acutal time. I have tried std.c.time's clock(), but it only measures time spent inside the program, not actual time elapsed. I need at least millisecond resolution, so std.c.time.time() is not an option. I wonder, is there a good library for

Re: Timer library?

2010-01-25 Thread Pelle Månsson
On 01/25/2010 04:02 PM, strtr wrote: Stanislav Blinov Wrote: Pelle M�nsson wrote: I'm in need for a timer library that measures the acutal time. I have tried std.c.time's clock(), but it only measures time spent inside the program, not actual time elapsed. I need at least millisecond