Re: Understanding Safety of Function Pointers vs. Addresses of Functions

2015-07-13 Thread jmh530 via Digitalmars-d-learn
On Monday, 13 July 2015 at 02:52:11 UTC, Laeeth Isharc wrote: I am venturing in territory still new to me, but I think that was his point - foreach with tuples looks like it is looping, but really it is unpacking them statically at compile time. And similarly with the recursive version. I d

Re: Align object to vector using Dgame framework

2015-07-13 Thread codenstuff via Digitalmars-d-learn
On Monday, 13 July 2015 at 19:07:55 UTC, Márcio Martins wrote: On Monday, 13 July 2015 at 16:11:03 UTC, codenstuff wrote: [...] This is not really a game development forum but here you go: auto rads = atan2(object.velocity.y, object.velocity.x); // returns radians auto degs = angle * (180.0f

Linked variables

2015-07-13 Thread via Digitalmars-d-learn
Does the standard library have a way to create a forward link between two variables of the same type? One variable is the source and the other is the sink. When the source variable is changed, the sink variable is too. Changing the sink variable has no effect on the source variable. I have alrea

Re: Manually allocate delegate?

2015-07-13 Thread Tofu Ninja via Digitalmars-d-learn
On Sunday, 12 July 2015 at 12:56:17 UTC, Adam D. Ruppe wrote: On Sunday, 12 July 2015 at 08:38:01 UTC, Tofu Ninja wrote: Is it even possible? Yes, though you need to use an entirely different approach for closures: make a struct. [...] This seems like a reasonable solution, even though it

Re: Align object to vector using Dgame framework

2015-07-13 Thread via Digitalmars-d-learn
On Monday, 13 July 2015 at 16:11:03 UTC, codenstuff wrote: I've been using Dgame framework for simple simulations. I need moving object to be aligned to their velocity vectors. How is it possible to do that using Dgame? I see that shape object has setRotation and setRotationCenter. Not sure h

Re: Delayed const variable initialization

2015-07-13 Thread Yuxuan Shui via Digitalmars-d-learn
On Monday, 13 July 2015 at 17:18:53 UTC, Jesse Phillips wrote: On Monday, 13 July 2015 at 14:41:36 UTC, Steven Schveighoffer wrote: You can also do a temporary lambda that you call immediately, but I'm not 100% sure of the syntax. Someone will chime in with the answer :) -Steve Syntax is ea

Re: Delayed const variable initialization

2015-07-13 Thread Jesse Phillips via Digitalmars-d-learn
On Monday, 13 July 2015 at 14:41:36 UTC, Steven Schveighoffer wrote: You can also do a temporary lambda that you call immediately, but I'm not 100% sure of the syntax. Someone will chime in with the answer :) -Steve Syntax is easy: void main() { bool condition; const x = { i

Align object to vector using Dgame framework

2015-07-13 Thread codenstuff via Digitalmars-d-learn
I've been using Dgame framework for simple simulations. I need moving object to be aligned to their velocity vectors. How is it possible to do that using Dgame? I see that shape object has setRotation and setRotationCenter. Not sure how to use these to achieve the effect. I realize that defau

Re: Delayed const variable initialization

2015-07-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/13/15 3:11 AM, Yuxuan Shui wrote: How can I do something like this? const(A) x; if (condition) { x = func1(); } else { x = func2(); } This is a valid use case, and to make this work I'll have to use Rebindable, which is really inconvenient. auto xvalue() { if(condition) { r

Re: I'm getting NAN out of nowhere

2015-07-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/11/15 12:57 PM, flamencofantasy wrote: On Thursday, 9 July 2015 at 15:14:43 UTC, Binarydepth wrote: This is my code : import std.stdio : writeln, readf; void main(){ int[3] nums; float prom; foreach(nem; 0..2){ writeln("input a number : "); readf(" %d", &

Re: Delayed const variable initialization

2015-07-13 Thread ketmar via Digitalmars-d-learn
On Mon, 13 Jul 2015 09:08:13 +, Yuxuan Shui wrote: > No! What I want to do is to assign to 'const' only ONCE. So it is > basically an initialization. it is forbidden to do assigning to `const`. and D has *no* "uninitialized variable" thingy, even `x = void` is initialization too (in technica

Re: Delayed const variable initialization

2015-07-13 Thread via Digitalmars-d-learn
On Monday, 13 July 2015 at 08:56:07 UTC, Yuxuan Shui wrote: On Monday, 13 July 2015 at 07:43:16 UTC, Marc Schütz wrote: On Monday, 13 July 2015 at 07:11:33 UTC, Yuxuan Shui wrote: How can I do something like this? const(A) x; if (condition) { x = func1(); } else { x = func2(); } This is a

Using executeShell in multiple thread causes access violation error

2015-07-13 Thread Minas Mina via Digitalmars-d-learn
I have written a script that visits all directories in the current directory and executes a command. In my case, "git pull". When running the script serially, everything is fine. All git repositories are pulled. But I'd like to pull multiple repositories in parallel to speed things up. So I

Re: Delayed const variable initialization

2015-07-13 Thread tcak via Digitalmars-d-learn
On Monday, 13 July 2015 at 09:08:14 UTC, Yuxuan Shui wrote: On Monday, 13 July 2015 at 09:05:25 UTC, ketmar wrote: On Mon, 13 Jul 2015 08:56:05 +, Yuxuan Shui wrote: [...] as i wrote, what you really want is the ability to assign to `const`, which is forbidden in D. initialization of `x

Re: Delayed const variable initialization

2015-07-13 Thread Yuxuan Shui via Digitalmars-d-learn
On Monday, 13 July 2015 at 09:05:25 UTC, ketmar wrote: On Mon, 13 Jul 2015 08:56:05 +, Yuxuan Shui wrote: On Monday, 13 July 2015 at 07:43:16 UTC, Marc Schütz wrote: On Monday, 13 July 2015 at 07:11:33 UTC, Yuxuan Shui wrote: [...] const(A) = condition ? func1() : func2(); Well I sho

Re: Delayed const variable initialization

2015-07-13 Thread ketmar via Digitalmars-d-learn
On Mon, 13 Jul 2015 09:02:34 +, Yuxuan Shui wrote: > IMO this is too restrictive. Can't we just spit compile error for uses > before initialization, and allow const variables to be initialized > somewhere other than where it is defined? there is no "use before initialization", `x` is initiali

Re: Delayed const variable initialization

2015-07-13 Thread ketmar via Digitalmars-d-learn
On Mon, 13 Jul 2015 08:56:05 +, Yuxuan Shui wrote: > On Monday, 13 July 2015 at 07:43:16 UTC, Marc Schütz wrote: >> On Monday, 13 July 2015 at 07:11:33 UTC, Yuxuan Shui wrote: >>> How can I do something like this? >>> >>> const(A) x; >>> if (condition) { >>> x = func1(); >>> } else { >>>

Re: Delayed const variable initialization

2015-07-13 Thread Yuxuan Shui via Digitalmars-d-learn
On Monday, 13 July 2015 at 08:55:00 UTC, ketmar wrote: On Mon, 13 Jul 2015 07:11:32 +, Yuxuan Shui wrote: How can I do something like this? const(A) x; if (condition) { x = func1(); } else { x = func2(); } This is a valid use case, and to make this work I'll have to use Rebindable,

Re: Manually allocate delegate?

2015-07-13 Thread ketmar via Digitalmars-d-learn
On Sun, 12 Jul 2015 12:45:10 +, Adam D. Ruppe wrote: > On Sunday, 12 July 2015 at 11:42:09 UTC, ketmar wrote: >> nope. there is no way to overload context allocation function, >> afaik. at least without patching druntime, and i still don't know what >> one have to patch. ;-) > > _d_allocmemor

Re: Delayed const variable initialization

2015-07-13 Thread Yuxuan Shui via Digitalmars-d-learn
On Monday, 13 July 2015 at 07:43:16 UTC, Marc Schütz wrote: On Monday, 13 July 2015 at 07:11:33 UTC, Yuxuan Shui wrote: How can I do something like this? const(A) x; if (condition) { x = func1(); } else { x = func2(); } This is a valid use case, and to make this work I'll have to use Rebi

Re: Delayed const variable initialization

2015-07-13 Thread ketmar via Digitalmars-d-learn
On Mon, 13 Jul 2015 07:11:32 +, Yuxuan Shui wrote: > How can I do something like this? > > const(A) x; > if (condition) { >x = func1(); > } else { >x = func2(); > } > > This is a valid use case, and to make this work I'll have to use > Rebindable, which is really inconvenient. p.s.

Re: Delayed const variable initialization

2015-07-13 Thread via Digitalmars-d-learn
On Monday, 13 July 2015 at 07:11:33 UTC, Yuxuan Shui wrote: How can I do something like this? const(A) x; if (condition) { x = func1(); } else { x = func2(); } This is a valid use case, and to make this work I'll have to use Rebindable, which is really inconvenient. const(A) = condition

Delayed const variable initialization

2015-07-13 Thread Yuxuan Shui via Digitalmars-d-learn
How can I do something like this? const(A) x; if (condition) { x = func1(); } else { x = func2(); } This is a valid use case, and to make this work I'll have to use Rebindable, which is really inconvenient.