Re: Fighting compiler - experienced programmer but D novice

2014-06-03 Thread Jacob Carlborg via Digitalmars-d-learn
On 03/06/14 05:57, Charles Parker wrote: Chris, that was it I needed to do both things. It then complained about trying to allocate the in_edges and out_edges arrays in the constructor which is how I thought dynamic arrays are allocated on the heap. I removed the 2 new statements, and both

Re: Delegate, scope and associative array

2014-06-03 Thread Edwin van Leeuwen via Digitalmars-d-learn
On Tuesday, 3 June 2014 at 05:40:44 UTC, Edwin van Leeuwen wrote: On Monday, 2 June 2014 at 23:44:01 UTC, Rene Zwanenburg wrote: On Monday, 2 June 2014 at 20:09:12 UTC, Edwin van Leeuwen wrote: As you may have guessed, a workaround is to copy the iteration variable yourself: unittest {

Re: Delegate, scope and associative array

2014-06-03 Thread Ali Çehreli via Digitalmars-d-learn
On 06/02/2014 10:40 PM, Edwin van Leeuwen wrote: On Monday, 2 June 2014 at 23:44:01 UTC, Rene Zwanenburg wrote: On Monday, 2 June 2014 at 20:09:12 UTC, Edwin van Leeuwen wrote: As you may have guessed, a workaround is to copy the iteration variable yourself: unittest { size_t

Re: Delegate, scope and associative array

2014-06-03 Thread Vlad Levenfeld via Digitalmars-d-learn
I've run across this myself. The workaround I used was to call a function from inside the foreach loop, and in that function you construct the delegate (with the index variable passed as a parameter).

Re: Delegate, scope and associative array

2014-06-03 Thread Vlad Levenfeld via Digitalmars-d-learn
Hah, sorry, I didn't read the last post. I did exactly what Ali just suggested.

Re: Delegate, scope and associative array

2014-06-03 Thread Edwin van Leeuwen via Digitalmars-d-learn
On Tuesday, 3 June 2014 at 07:00:35 UTC, Ali Çehreli wrote: Here is a workaround: unittest { size_t delegate()[size_t] events; auto makeClosure(size_t i) { return { return i; }; } foreach( i; 1..4 ) { events[i] = makeClosure(i); } assert( events[1]()

Re: Delegate, scope and associative array

2014-06-03 Thread bearophile via Digitalmars-d-learn
Ali Çehreli: Here is a workaround: unittest { size_t delegate()[size_t] events; auto makeClosure(size_t i) { return { return i; }; } foreach( i; 1..4 ) { events[i] = makeClosure(i); } You can also use two lambdas to do that, without the makeClosure:

On ref return in DMD

2014-06-03 Thread Nordlöw
The title More ref return fixes in std.datetime now that the compiler allows them of https://github.com/D-Programming-Language/phobos/pull/2227/files made me curious to what is meant by ref return. Is this a recent improvement in DMD?

Re: On ref return in DMD

2014-06-03 Thread Jonathan M Davis via Digitalmars-d-learn
On Tue, 03 Jun 2014 10:14:21 + Nordlöw via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: The title More ref return fixes in std.datetime now that the compiler allows them of https://github.com/D-Programming-Language/phobos/pull/2227/files made me curious to what is

Re: On ref return in DMD

2014-06-03 Thread Nordlöw
No. We've been able to return by ref for ages. However, when Thx

Re: How to assign a delegate to a var ?

2014-06-03 Thread bioinfornatics via Digitalmars-d-learn
On Monday, 2 June 2014 at 23:27:03 UTC, Meta wrote: On Monday, 2 June 2014 at 22:18:39 UTC, bioinfornatics wrote: Hi, I would like store the delegate to another var but when i try i get: testTraitsWithDelegate.d(13): Error: expression template __lambda2 is void and has no value I do not

Re: How to assign a delegate to a var ?

2014-06-03 Thread bioinfornatics via Digitalmars-d-learn
On Tuesday, 3 June 2014 at 12:27:45 UTC, bioinfornatics wrote: On Monday, 2 June 2014 at 23:27:03 UTC, Meta wrote: On Monday, 2 June 2014 at 22:18:39 UTC, bioinfornatics wrote: Hi, I would like store the delegate to another var but when i try i get: testTraitsWithDelegate.d(13): Error:

Re: for, foreach identifier allowed in c throws error in d

2014-06-03 Thread Steven Schveighoffer via Digitalmars-d-learn
On Mon, 02 Jun 2014 17:25:24 -0400, John Colvin john.loughran.col...@gmail.com wrote: On Monday, 2 June 2014 at 20:23:12 UTC, Steven Schveighoffer wrote: On Mon, 02 Jun 2014 15:58:01 -0400, Steven Schveighoffer schvei...@yahoo.com wrote: I'm trying to think of a way to do this without

Re: Delegate, scope and associative array

2014-06-03 Thread Steven Schveighoffer via Digitalmars-d-learn
On Mon, 02 Jun 2014 19:43:58 -0400, Rene Zwanenburg renezwanenb...@gmail.com wrote: On Monday, 2 June 2014 at 20:09:12 UTC, Edwin van Leeuwen wrote: I'm probably missing something basic, but I am confused by what is going on in the following code. unittest { size_t delegate()[size_t]

Re: How to assign a delegate to a var ?

2014-06-03 Thread Ali Çehreli via Digitalmars-d-learn
On 06/03/2014 05:57 AM, bioinfornatics wrote: On Tuesday, 3 June 2014 at 12:27:45 UTC, bioinfornatics wrote: I would like store the delegate to another var but when i try i get: testTraitsWithDelegate.d(13): Error: expression template __lambda2 is void and has no value I do not want to

Re: How to assign a delegate to a var ?

2014-06-03 Thread bioinfornatics via Digitalmars-d-learn
On Tuesday, 3 June 2014 at 15:00:05 UTC, Ali Çehreli wrote: On 06/03/2014 05:57 AM, bioinfornatics wrote: On Tuesday, 3 June 2014 at 12:27:45 UTC, bioinfornatics wrote: I would like store the delegate to another var but when i try i get: testTraitsWithDelegate.d(13): Error: expression

DateTime custom string format

2014-06-03 Thread Robert Schadek via Digitalmars-d-learn
Is there a function in phobos that lets me do something like DateTime.format(MM:DD: ) with a DateTime instance?

Re: How to assign a delegate to a var ?

2014-06-03 Thread bioinfornatics via Digitalmars-d-learn
delegate has a context pointer that it uses when executing at run-time. However, there can't be a run-time context of a delegate that is created at compile-time. I think that is why the segfault. Is there a reason why it needs to be a delegate? Replacing every 'delegate' with 'function'

Getting started with vibe.d

2014-06-03 Thread Chris Saunders via Digitalmars-d-learn
I've made my first attempt to use dub/vibe.d and I'm running into some issues I can't find on the list. I'm on Ubuntu 14.04/x86_64, using the latest stable dub (0.9.21). I can create a new dub project: “”” $ dub init test vibe.d Successfully created an empty project in

Re: Getting started with vibe.d

2014-06-03 Thread Craig Dillabaugh via Digitalmars-d-learn
On Tuesday, 3 June 2014 at 16:16:10 UTC, Chris Saunders wrote: I've made my first attempt to use dub/vibe.d and I'm running into some issues I can't find on the list. I'm on Ubuntu 14.04/x86_64, using the latest stable dub (0.9.21). I can create a new dub project: “”” $ dub init test vibe.d

Re: Creating ranges over mutable, const, or immutable data structures.

2014-06-03 Thread Ali Çehreli via Digitalmars-d-learn
On 05/24/2014 11:01 AM, Ali Çehreli wrote: On 05/24/2014 10:02 AM, w0rp wrote: I have been writing my own hashmap which can provide forward ranges usable in @safe pure nothrow functions, because it's going to be useful for creating graph data structures with the same. I came to writing my

Re: DateTime custom string format

2014-06-03 Thread Jonathan M Davis via Digitalmars-d-learn
On Tue, 03 Jun 2014 17:07:02 +0200 Robert Schadek via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Is there a function in phobos that lets me do something like DateTime.format(MM:DD: ) with a DateTime instance? Not currently. It's on my todo list. I intend to get back

Re: DateTime custom string format

2014-06-03 Thread Robert Schadek via Digitalmars-d-learn
On 06/03/2014 07:12 PM, Jonathan M Davis via Digitalmars-d-learn wrote: On Tue, 03 Jun 2014 17:07:02 +0200 Robert Schadek via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Is there a function in phobos that lets me do something like DateTime.format(MM:DD: ) with a

Re: Getting started with vibe.d

2014-06-03 Thread Chris Saunders via Digitalmars-d-learn
Thanks, I somehow missed the vibe.d forums... I'd need an ldc solution in the end, but trying dmd is a good idea. The result is some kind of link error to libevent?: dub build vibe-d: [vibe-d, libevent, openssl] test: [test, vibe-d, libevent, openssl] Target is up to date. Using existing

Re: Getting started with vibe.d

2014-06-03 Thread Craig Dillabaugh via Digitalmars-d-learn
On Tuesday, 3 June 2014 at 17:41:27 UTC, Chris Saunders wrote: Thanks, I somehow missed the vibe.d forums... I'd need an ldc solution in the end, but trying dmd is a good idea. The result is some kind of link error to libevent?: dub build vibe-d: [vibe-d, libevent, openssl] test: [test,

Re: How to assign a delegate to a var ?

2014-06-03 Thread Jesse Phillips via Digitalmars-d-learn
On Tuesday, 3 June 2014 at 15:14:06 UTC, bioinfornatics wrote: without using a delegate, with a function that will not work as (int a) = a == 42 is a delegate no ? D will decide the type based on if context is needed. If you look at the output you had: , __ctmp1474).this(function (int

Re: DateTime custom string format

2014-06-03 Thread Jonathan M Davis via Digitalmars-d-learn
On Tue, 03 Jun 2014 19:39:14 +0200 Robert Schadek via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On 06/03/2014 07:12 PM, Jonathan M Davis via Digitalmars-d-learn wrote: On Tue, 03 Jun 2014 17:07:02 +0200 Robert Schadek via Digitalmars-d-learn

Re: Delegate, scope and associative array

2014-06-03 Thread via Digitalmars-d-learn
On Tuesday, 3 June 2014 at 13:30:13 UTC, Steven Schveighoffer wrote: There is a school of thought (to which I subscribe) that says you shouldn't allocate a separate closure for each loop iteration. Basically, a closure will only use the stack frame of the calling function, not any loop

asserts and release

2014-06-03 Thread Etienne via Digitalmars-d-learn
Are asserts supposed to be evaluated in DMD release? I was getting a privileged instructions error 0xC096 which was caused by an assert, when doing some gc programming in druntime

Re: asserts and release

2014-06-03 Thread Tobias Pankrath via Digitalmars-d-learn
On Tuesday, 3 June 2014 at 19:21:08 UTC, Etienne wrote: Are asserts supposed to be evaluated in DMD release? I was getting a privileged instructions error 0xC096 which was caused by an assert, when doing some gc programming in druntime Is this part of the runtime precompiled? If not the

Re: asserts and release

2014-06-03 Thread bearophile via Digitalmars-d-learn
Etienne: Are asserts supposed to be evaluated in DMD release? I was getting a privileged instructions error 0xC096 which was caused by an assert, when doing some gc programming in druntime assert(0) are not removed in release builds. They are a HALT. Bye, bearophile

Re: DateTime custom string format

2014-06-03 Thread Robert Schadek via Digitalmars-d-learn
On 06/03/2014 08:22 PM, Jonathan M Davis via Digitalmars-d-learn wrote: On Tue, 03 Jun 2014 19:39:14 +0200 Robert Schadek via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On 06/03/2014 07:12 PM, Jonathan M Davis via Digitalmars-d-learn wrote: On Tue, 03 Jun 2014 17:07:02

Re: DateTime custom string format

2014-06-03 Thread Brad Anderson via Digitalmars-d-learn
On Tuesday, 3 June 2014 at 18:22:59 UTC, Jonathan M Davis via Digitalmars-d-learn wrote: Well, I would prefer to do it myself, but I obviously can't say that I wouldn't accept it if someone else did it and did a good job of it. The main problem however is that we need to come up with a good

Re: why it said no identifier for declarator …

2014-06-03 Thread Jesse Phillips via Digitalmars-d-learn
On Tuesday, 3 June 2014 at 22:10:06 UTC, bioinfornatics wrote: I do not see why it fail in debug output we see that tuple have a field with given name. Your generated output (short and formatted) alias TL = Tuple!(int,x, bool function( const ref string ), xStartsWith , bool function(

Segfault in shared object when writeln

2014-06-03 Thread Harpo via Digitalmars-d-learn
Hello I am having the following problem. I am trying to turn a program I have written into a shared object. I have ran into some problems however. When I use writeln instead of printf my program segfaults. I have edited the code to just the parts causing the problem. =main.d

Re: Segfault in shared object when writeln

2014-06-03 Thread ed via Digitalmars-d-learn
On Wednesday, 4 June 2014 at 03:49:25 UTC, Harpo wrote: Hello I am having the following problem. I am trying to turn a program I have written into a shared object. I have ran into some problems however. When I use writeln instead of printf my program segfaults. I have edited the code to just

Re: Segfault in shared object when writeln

2014-06-03 Thread ed via Digitalmars-d-learn
On Wednesday, 4 June 2014 at 04:46:59 UTC, ed wrote: On Wednesday, 4 June 2014 at 03:49:25 UTC, Harpo wrote: Hello I am having the following problem. I am trying to turn a program I have written into a shared object. I have ran into some problems however. When I use writeln instead of printf

Re: Segfault in shared object when writeln

2014-06-03 Thread Harpo via Digitalmars-d-learn
Thanks! that was perfect. -Harpo

override toString() for a tuple?

2014-06-03 Thread Steve D via Digitalmars-d-learn
Is it possible to override std tuple's toString format? so that auto a = tuple(hello,1,2,3); writeln(a); prints (hello, 1, 2, 3) and not Tuple!(string, int, int, int)(hello, 1, 2, 3) I'm aware I could write a custom formatter function, but it would be nice not

Re: DateTime custom string format

2014-06-03 Thread Jonathan M Davis via Digitalmars-d-learn
On Tue, 03 Jun 2014 22:54:11 + Brad Anderson via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Tuesday, 3 June 2014 at 18:22:59 UTC, Jonathan M Davis via Digitalmars-d-learn wrote: Well, I would prefer to do it myself, but I obviously can't say that I wouldn't accept