Re: Does D has C#'s string.Empty?

2014-09-25 Thread Chris Cain via Digitalmars-d-learn
On Friday, 26 September 2014 at 01:09:01 UTC, AsmMan wrote: On Friday, 26 September 2014 at 00:53:24 UTC, ketmar via Digitalmars-d-learn wrote: On Fri, 26 Sep 2014 00:24:27 + AsmMan via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: It made me a bit confusing. How is the

Re: destroy(someStruct)

2014-09-20 Thread Chris Cain via Digitalmars-d-learn
On Saturday, 20 September 2014 at 22:46:10 UTC, John Colvin wrote: import core.stdc.stdio; struct S { ~this() { printf(%x\n.ptr, this); } } void main() { S* sp = new S; destroy(*sp); S s; destroy(s); auto sa = new

Re: literate programming in D

2014-08-30 Thread Chris Cain via Digitalmars-d-learn
On Saturday, 30 August 2014 at 07:33:38 UTC, Philippe Sigaud wrote: On Friday, 29 August 2014 at 23:58:19 UTC, Chris Cain wrote: I used https://www.npmjs.org/package/literate-programming (+ pandoc) to do this when writing https://dl.dropboxusercontent.com/u/2206555/uniformUpgrade.pdf in

Re: literate programming in D

2014-08-29 Thread Chris Cain via Digitalmars-d-learn
On Tuesday, 26 August 2014 at 14:55:08 UTC, nikki wrote: I've been googling without luck, is there a way to do literate programming in D?, similar to how it's done in Coffeescript ? http://www.coffeescriptlove.com/2013/02/literate-coffeescript.html basically me writing comments around code

Re: GC can collect object allocated in function, despite a pointer to the object living on?

2014-08-16 Thread Chris Cain via Digitalmars-d-learn
On Saturday, 16 August 2014 at 22:36:51 UTC, 岩倉 澪 wrote: void changeState(){ if(nextState != WaitState nextState != ExitState){ auto newState = cast(IState) Object.factory(game.states.~nextState); import std.exception; enforce(newState); // !!!

Re: Threadpools, difference between DMD and LDC

2014-08-04 Thread Chris Cain via Digitalmars-d-learn
On Monday, 4 August 2014 at 12:05:31 UTC, Philippe Sigaud via Digitalmars-d-learn wrote: OK, I get it. Just to be sure, there is no ThreadPool in Phobos or in core, right? IIRC, there are fibers somewhere in core, I'll have a look. I also heard the vibe.d has them. There is. It's called

Re: Converting from C const(dchar*) to dstring

2014-06-24 Thread Chris Cain via Digitalmars-d-learn
On Tuesday, 24 June 2014 at 17:59:41 UTC, Steven Schveighoffer wrote: // assuming 0 terminated dstring text = x[0..x.strlen].idup; strlen is only defined for char, not dchar: https://github.com/D-Programming-Language/druntime/blob/master/src/core/stdc/string.d#L44

Re: Converting from C const(dchar*) to dstring

2014-06-24 Thread Chris Cain via Digitalmars-d-learn
On Tuesday, 24 June 2014 at 18:17:07 UTC, Danyal Zia wrote: On Tuesday, 24 June 2014 at 17:59:41 UTC, Steven Schveighoffer wrote: const(dchar *)x = ...; // assuming 0 terminated dstring text = x[0..x.strlen].idup; -Steve const(dchar)* x = Hello\0; dstring text = x[0..x.strlen].idup;

Re: D aliases vs. C typedefs

2014-06-10 Thread Chris Cain via Digitalmars-d-learn
On Tuesday, 10 June 2014 at 22:00:34 UTC, Ali Çehreli wrote: http://stackoverflow.com/questions/10758811/c-syntax-for-functions-returning-function-pointers int (*(*(*f3)(int))(double))(float); f3 is a ... Ali f3 is a pointer to a function taking an int returning a pointer to a function

Re: Does D have a variant data type?

2014-06-07 Thread Chris Cain via Digitalmars-d-learn
On Saturday, 7 June 2014 at 19:10:19 UTC, katuday wrote: I am looking for something like boost::variant in C++ Like this? http://dlang.org/phobos/std_variant.html

Re: How to sort a 2D array by column

2014-06-07 Thread Chris Cain via Digitalmars-d-learn
This is my attemot to create a compare object. But I don't know how to use it together with .sort member function Don't use the .sort property. Use std.algorithm.sort, which has a less predicate (that should return a bool). http://dlang.org/phobos/std_algorithm.html#sort

Re: How to sort a 2D array by column

2014-06-07 Thread Chris Cain via Digitalmars-d-learn
On Saturday, 7 June 2014 at 19:14:01 UTC, Chris Cain wrote: This is my attemot to create a compare object. But I don't know how to use it together with .sort member function Don't use the .sort property. Use std.algorithm.sort, which has a less predicate (that should return a bool).

Re: Running a delegate inside a C function

2014-06-07 Thread Chris Cain via Digitalmars-d-learn
On Saturday, 7 June 2014 at 20:04:41 UTC, Denis Martinez via Digitalmars-d-learn wrote:     int ret = jack_set_process_callback(handle_, f, dg); dg here is giving you a pointer to the dg variable sitting on the stack. The stack is almost certainly getting overwritten at some point.

Re: Permutation Sort Algorithm Very Slow

2014-06-07 Thread Chris Cain via Digitalmars-d-learn
On Saturday, 7 June 2014 at 21:40:08 UTC, Agora wrote: Why is running slow? One of the main reasons is because the number of permutations an array has is n!. Thus the expected runtime is O(n!). That's a slow, slow algorithm in general. In particular, your array with length 11 has 39,916,800

Re: Permutation Sort Algorithm Very Slow

2014-06-07 Thread Chris Cain via Digitalmars-d-learn
On Saturday, 7 June 2014 at 22:01:25 UTC, Ali GOREN wrote: Thank you. I can not resolve it in quicker time, right? You might be able to come up with a faster way to permute, but it's mostly pointless because it will always be very slow. Use std.algorithm.sort if you want to sort quickly, as

Re: Different random shuffles generated when compiled with gdc than with dmd

2014-06-02 Thread Chris Cain via Digitalmars-d-learn
On Sunday, 1 June 2014 at 14:22:31 UTC, Joseph Rushton Wakeling via Digitalmars-d-learn wrote: I missed the debate at the time, but actually, I'm slightly more concerned over the remark in that discussion that the new uniform was ported from java.util.Random. Isn't OpenJDK GPL-licensed ... ?

Re: Different random shuffles generated when compiled with gdc than with dmd

2014-06-02 Thread Chris Cain via Digitalmars-d-learn
On Monday, 2 June 2014 at 18:46:18 UTC, Joseph Rushton Wakeling via Digitalmars-d-learn wrote: I'm really sorry, Chris, I was obviously mixing things up: on rereading, the person in the earlier forum discussion (not PR thread) who talks about porting from Java wasn't you. I'm very glad to be

Re: Fighting compiler - experienced programmer but D novice

2014-06-02 Thread Chris Cain via Digitalmars-d-learn
On Tuesday, 3 June 2014 at 03:17:10 UTC, Charles Parker wrote: ... Thanx for any help - Charlie Well one thing is that you don't need the type parameters on the this function. You're basically creating a templated this inside the templated class which is not what you want. try this:

Re: Modify char in string

2014-05-18 Thread Chris Cain via Digitalmars-d-learn
On Sunday, 18 May 2014 at 18:55:59 UTC, Tim wrote: Hi everyone, is there any chance to modify a char in a string like: As you've seen, you cannot modify immutables (string is an immutable(char)[]). If you actually do want the string to be modifiable, you should define it as char[] instead.