Named tuple from struct

2011-01-08 Thread Guilherme Vieira
Is is possible to get a named tuple from a struct type? E.g.: struct S { int foo; string bar; } S s; S.tupleof t; // S.tupleof is a tuple type, as opposed to s.tupleof, // which yields a tuple instance t[0] = 1; t.bar = 2; If not, I think it would be quite useful. Even still,

Re: auto declarations

2011-01-08 Thread bearophile
Ellery Newcomer: int a = 1, *b = null; Walter has disallowed code like this in D because in C it is a well known source of bugs (so much that C style guides strongly suggest to declare only each variable in a distinct statement and line of code). auto a = 1, b = null; I have discussed

Re: Named tuple from struct

2011-01-08 Thread Jacob Carlborg
On 2011-01-08 09:15, Guilherme Vieira wrote: Is is possible to get a named tuple from a struct type? E.g.: struct S { int foo; string bar; } S s; S.tupleof t; // S.tupleof is a tuple type, as opposed to s.tupleof, // which yields a tuple instance t[0] = 1;

Calling anonymous delegate recursively ?

2011-01-08 Thread tsukikage
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!

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: Calling anonymous delegate recursively ?

2011-01-08 Thread Andrej Mitrovic
As a workaround you can do this for now: import std.stdio; enum deleg = returnFib(); ulong delegate(ulong m) returnFib() { return (ulong m) { if(m 2) return m; return deleg(m-1)+deleg(m-2); }; } void main() { writeln(returnFib()(10)); } Otherwise

Re: Calling anonymous delegate recursively ?

2011-01-08 Thread Stewart Gordon
On 08/01/2011 16:00, Pelle wrote: snip http://en.wikipedia.org/wiki/Fixed_point_combinator#Y_combinator snip How are you getting around D not supporting recursively defined types? Stewart.

Re: Calling anonymous delegate recursively ?

2011-01-08 Thread Stewart Gordon
On 08/01/2011 17:40, Andrej Mitrovic wrote: snip Otherwise I'd really like the ability for a lambda to call itself. Perhaps a feature request is in order. I'm not sure what D would gain in practice. If you want a function that calls itself, why not just name the function? Stewart.

Re: Calling anonymous delegate recursively ?

2011-01-08 Thread Andrej Mitrovic
On 1/8/11, Stewart Gordon smjg_1...@yahoo.com wrote: On 08/01/2011 17:40, Andrej Mitrovic wrote: snip Otherwise I'd really like the ability for a lambda to call itself. Perhaps a feature request is in order. I'm not sure what D would gain in practice. If you want a function that calls

Re: Calling anonymous delegate recursively ?

2011-01-08 Thread tsukikage
Thank Pelle , and others. I'm thinking ways to do this task : http://rosettacode.org/wiki/Anonymous_recursion With this last version of Y-combinator http://rosettacode.org/wiki/Y_combinator#D , it look like this: ulong fib(long n) { if(n 0) throw new Exception(No negative) ; return

Re: What's wrong with this code?

2011-01-08 Thread Michal Minich
On Sat, 08 Jan 2011 20:34:39 +, Sean Eskapp wrote: if(left == null) 1) write if (left is null) instead if checking for null. Equality operator is rewritten to a.opEquals(b), which you don't want if you checking for null. this() { left = right = null; } 2) default

Re: What's wrong with this code?

2011-01-08 Thread Tomek Sowiński
Sean Eskapp napisał(a): I had some code that was segfaulting, so I rewrote the basic idea as a fibonacci function, and lo and behold, it still segfaults. Why, and how to fix? This looks fishy: class Fib { private const Fib* left, right; ... this(in Fib left, in Fib right)

Implicit type conversion

2011-01-08 Thread Michal Minich
Use case: import std.variant; void foo (Variant v) {} void main () { Variant v = 3; // ok, this () called v = 3; // ok, opAssing called foo (v); // ok, struct copy, this(this) called foo (3); // error } I'm trying to understand what is needed to make

Re: std.container.Array/RefCounted(T) leaking memory?

2011-01-08 Thread %u
What method are you using to test the memory? I'm puzzled that you've put a comment there rather than the code you're actually using. I'm not using code, I'm checking the working set of my process in Task Manager, and through every iteration, it adds 128 MB. If you run this code twice,

druntime

2011-01-08 Thread Ellery Newcomer
where did libdruntime.a go in dmd.2.051.zip:/linux/lib ?

writef vs writeln and printing to the console

2011-01-08 Thread Andrej Mitrovic
Unfortunately I can't provide a simple test case, but I have a case where using: writef(..\n); inside a loop that runs a dozen times does not print out each line as the statement is reached, instead it prints out everything at once when the application is done. If I use this:

Re: What's wrong with this code? (OP)

2011-01-08 Thread Sean Eskapp
Tomek got it right. Fixed by copying the objects, rather than using pointers. Thanks!

Re: druntime

2011-01-08 Thread Jonathan M Davis
On Saturday 08 January 2011 13:32:19 Ellery Newcomer wrote: where did libdruntime.a go in dmd.2.051.zip:/linux/lib ? I think that it's included inside of libphobos.a now, and has been for a few releases. The libraries are still separate, and you can build them separately, but from what I can

Re: druntime

2011-01-08 Thread Ellery Newcomer
On 01/08/2011 09:02 PM, Jonathan M Davis wrote: On Saturday 08 January 2011 13:32:19 Ellery Newcomer wrote: where did libdruntime.a go in dmd.2.051.zip:/linux/lib ? I think that it's included inside of libphobos.a now, and has been for a few releases. The libraries are still separate, and you

Re: druntime

2011-01-08 Thread Jonathan M Davis
On Saturday 08 January 2011 19:16:26 Ellery Newcomer wrote: On 01/08/2011 09:02 PM, Jonathan M Davis wrote: On Saturday 08 January 2011 13:32:19 Ellery Newcomer wrote: where did libdruntime.a go in dmd.2.051.zip:/linux/lib ? I think that it's included inside of libphobos.a now, and has

Re: interface function overloading

2011-01-08 Thread %u
== Quote from Jonathan M Davis (jmdavisp...@gmx.com)'s article On Saturday 08 January 2011 22:01:11 %u wrote: Isn't it possible to have a hierarchy in interface definitions such that it is possible to overload according to best interface match? This now won't compile due to multiple