Re: array initialization problem

2009-01-20 Thread Chris Nicholson-Sauls
Rainer Deyke wrote: Denis Koroskin wrote: Arrays in D are reference types. Besides, it's best to avoid hidden allocations. Arrays in D are reference types except when they're not. int[] a = [5]; int[] b = a; a[0] = 4; assert(b[0] == 4); a.length = 2; assert(b.length == 1); a[0] = 3; // Is b[0

Re: loop through specific class members

2009-01-20 Thread Jarrett Billingsley
On Tue, Jan 20, 2009 at 7:42 PM, Christopher Wright wrote: > Naturally, __traits and foreach don't mix, so you'll have to use template > recursion. This is pretty damn ugly. I never understood why __traits likes returning arrays so much. Why not tuples? > Note that getVirtualFunctions returns

Re: loop through specific class members

2009-01-20 Thread Christopher Wright
Jarrett Billingsley wrote: On Tue, Jan 20, 2009 at 10:29 AM, Trass3r wrote: It seems like there is no way to automatically get the class methods in D1 currently?! __traits isn't supported, std.traits doesn't give anything usable, .tupleof only gets the fields (plus only giving an ExpressionTupl

Re: compile time output

2009-01-20 Thread Christopher Wright
Sergey Gromov wrote: Comment out the traits and it compiles. Traits are supposed to be compile-time. How's that possible for them to prevent compile-time evaluation? It's the amazing powers of the DMD CTFE engine! And it's why I don't use d2 these days. I think I'll dust off some old code

Re: compile time output

2009-01-20 Thread Bill Baxter
On Wed, Jan 21, 2009 at 8:25 AM, Trass3r wrote: > Trass3r schrieb: >> >> This works: >> >> string foo(const string[] members) >> { >>string result; >>foreach(m; members) >>result ~= m ~ " "; >>return result; >> } >> > > Furthermore there seems to be no way to use these member n

Re: compile time output

2009-01-20 Thread Trass3r
Trass3r schrieb: This works: string foo(const string[] members) { string result; foreach(m; members) result ~= m ~ " "; return result; } Furthermore there seems to be no way to use these member names in a __traits(getMember, class, m) call. This is driving me crazy.

Re: compile time output

2009-01-20 Thread Trass3r
This works: template classMixin() { static this() { const string[] members = __traits(allMembers, typeof(this)); pragma(msg, foo(members)); } } string foo(const string[] members) { string result; foreach(m; members) result ~= m ~ " "; retur

Re: compile time output

2009-01-20 Thread Sergey Gromov
Tue, 20 Jan 2009 21:12:18 + (UTC), BCS wrote: > Reply to Trass3r, > >> Sergey Gromov schrieb: >> >>> auto members = __traits(allMembers, Cls); >> >> Seeing this really simple example crashing makes me think that this >> has to be a bug. >> > > that auto might be mucking it up (if so it wou

Re: compile time output

2009-01-20 Thread BCS
Reply to Trass3r, Sergey Gromov schrieb: auto members = __traits(allMembers, Cls); Seeing this really simple example crashing makes me think that this has to be a bug. that auto might be mucking it up (if so it would be a bug).

Re: compile time output

2009-01-20 Thread BCS
Reply to Trass3r, auto members = __traits(allMembers, typeof(this)); try switching that to const[][] members = __traits(allMembers, typeof(this)); if that doesn't fix it try dropping this part (it might make it clearer what's going on) static if (is (typeof(__traits(getMember, this, m

Re: compile time output

2009-01-20 Thread Trass3r
Sergey Gromov schrieb: > class Cls { int bar; char[] baz; } string foo() { auto members = __traits(allMembers, Cls); return ""; } pragma(msg, foo()); dmd -c test.d test.d(11): Error: cannot evaluate foo() at compile time test.d(11): pragma msg string expected for message, not 'foo()'

Re: compile time output

2009-01-20 Thread Trass3r
BCS schrieb: template Tpl(T...) { alias T Tpl; } template Range(int l, int u) { static if(l foreach(str; Range!(0,set.length-1)) // compile time foreach over the numbers from 0 to set.length-1 pragma(msg, set[str]); } Still doesn't work for this code (used with a mixin): template class

Re: compile time output

2009-01-20 Thread Sergey Gromov
Tue, 20 Jan 2009 16:36:09 +0100, Trass3r wrote: > Is there any way to output information at compile time other than > pragma(msg? > pragma is driving me crazy, the following doesn't work: > > auto members = __traits(allMembers, typeof(this)); > foreach(m; members) > { > pragma(msg, m); > }

Re: compile time output

2009-01-20 Thread BCS
Reply to Trass3r, BCS schrieb: I don't do 2.0 but it looks to me like your mixing runtime and compile time stuff. A foreach over an array is a runtime foreach. Do you know how I could make it run at compile-time? template Tpl(T...) { alias T Tpl; } template Range(int l, int u) { static

Re: compile time output

2009-01-20 Thread Trass3r
BCS schrieb: I don't do 2.0 but it looks to me like your mixing runtime and compile time stuff. A foreach over an array is a runtime foreach. Do you know how I could make it run at compile-time?

Re: loop through specific class members

2009-01-20 Thread Trass3r
Jarrett Billingsley schrieb: On Tue, Jan 20, 2009 at 2:13 PM, Trass3r wrote: Yeah, __traits works quite well to get the function names, but I still can't manage to get the corresponding function object to pass it to ParameterTypeTuple (for checking the parameters for correctness). Ah, that's

Re: loop through specific class members

2009-01-20 Thread Jarrett Billingsley
On Tue, Jan 20, 2009 at 2:13 PM, Trass3r wrote: > Yeah, __traits works quite well to get the function names, but I still can't > manage to get the corresponding function object to pass it to > ParameterTypeTuple (for checking the parameters for correctness). Ah, that's what __traits(getMember) is

Re: loop through specific class members

2009-01-20 Thread Trass3r
Jarrett Billingsley schrieb: On Tue, Jan 20, 2009 at 10:29 AM, Trass3r wrote: It seems like there is no way to automatically get the class methods in D1 currently?! __traits isn't supported, std.traits doesn't give anything usable, .tupleof only gets the fields (plus only giving an ExpressionTu

Re: main return value, struct padding

2009-01-20 Thread Denis Koroskin
Jarrett Billingsley Wrote: > On Tue, Jan 20, 2009 at 12:21 PM, Steven Schveighoffer > wrote: > > So it appears it returns 0 unless you return something else (!) > > Ha! Yes (but not always), even though specs clearly say that void functions evaluate return values and discard them. IIRC, this

Re: compile time output

2009-01-20 Thread BCS
Reply to Trass3r, Is there any way to output information at compile time other than pragma(msg? pragma is driving me crazy, the following doesn't work: auto members = __traits(allMembers, typeof(this)); foreach(m; members) { pragma(msg, m); } -> Error: string expected for message, not 'm' Thoug

Re: compile time output

2009-01-20 Thread Trass3r
Bill Baxter schrieb: try indexing explicitly or using ref: foreach(i,m; members) { pragma(msg, members[i]); } foreach(ref m; members) { pragma(msg, m); } Latter one may not be useful. I can't recall. Neither one works for me :(

Re: main return value, struct padding

2009-01-20 Thread Jarrett Billingsley
On Tue, Jan 20, 2009 at 12:21 PM, Steven Schveighoffer wrote: > So it appears it returns 0 unless you return something else (!) Ha!

Re: main return value, struct padding

2009-01-20 Thread Steven Schveighoffer
"bearophile" wrote >I post this here, but if later I see it fit I may post something in the >main D group too. > > D allows to have the main() function of type void too. In such case I'd > like the program return 0 by default. If people agrees, this can become a > feature request. A test: [ste.

Re: compile time output

2009-01-20 Thread Ary Borenszweig
Trass3r wrote: Is there any way to output information at compile time other than pragma(msg? pragma is driving me crazy, the following doesn't work: auto members = __traits(allMembers, typeof(this)); Kind of offtopic, but I tried this (with typeof(Foo) and Foo is defined in the same module)

Re: loop through specific class members

2009-01-20 Thread Jarrett Billingsley
On Tue, Jan 20, 2009 at 10:29 AM, Trass3r wrote: > It seems like there is no way to automatically get the class methods in D1 > currently?! > __traits isn't supported, std.traits doesn't give anything usable, .tupleof > only gets the fields (plus only giving an ExpressionTuple for classes). You'r

Re: main return value, struct padding

2009-01-20 Thread Jarrett Billingsley
On Tue, Jan 20, 2009 at 10:25 AM, bearophile wrote: > Bill Baxter: > >> What does it return now? > > A random int, I presume. > > >>I always assumed returned zero for void main.< > > Me too. I've only ever seen void mains return 0. I think they used to return random ints but that was fixed long

Re: compile time output

2009-01-20 Thread Bill Baxter
On Wed, Jan 21, 2009 at 12:36 AM, Trass3r wrote: > Is there any way to output information at compile time other than > pragma(msg? > pragma is driving me crazy, the following doesn't work: > > auto members = __traits(allMembers, typeof(this)); > foreach(m; members) > { >pragma(msg, m); > }

compile time output

2009-01-20 Thread Trass3r
Is there any way to output information at compile time other than pragma(msg? pragma is driving me crazy, the following doesn't work: auto members = __traits(allMembers, typeof(this)); foreach(m; members) { pragma(msg, m); } -> Error: string expected for message, not 'm' Though the doc

Re: loop through specific class members

2009-01-20 Thread Trass3r
It seems like there is no way to automatically get the class methods in D1 currently?! __traits isn't supported, std.traits doesn't give anything usable, .tupleof only gets the fields (plus only giving an ExpressionTuple for classes).

Re: main return value, struct padding

2009-01-20 Thread bearophile
Bill Baxter: > What does it return now? A random int, I presume. >I always assumed returned zero for void main.< Me too. Bye, bearophile

Re: loop through specific class members

2009-01-20 Thread Trass3r
BCS schrieb: you can get the names even in D1.0. Not exactly clean but... http://codepad.org/Eu16XqFu Yeah but only works for structs. When used with classes returns an ExpressionTuple. Furthermore you only get the fields, I need the methods ;)

Re: main return value, struct padding

2009-01-20 Thread Bill Baxter
On Tue, Jan 20, 2009 at 11:15 PM, bearophile wrote: > I post this here, but if later I see it fit I may post something in the main > D group too. > > D allows to have the main() function of type void too. In such case I'd like > the program return 0 by default. If people agrees, this can become

main return value, struct padding

2009-01-20 Thread bearophile
I post this here, but if later I see it fit I may post something in the main D group too. D allows to have the main() function of type void too. In such case I'd like the program return 0 by default. If people agrees, this can become a feature request. A question: when D automatically adds som

Re: any scripting language for D 2.x?

2009-01-20 Thread Trass3r
%u schrieb: is there a script engine for D 2.x You might try lua. See announce section, I just released a new revision aiming at compatibility with D2.

D compiler without saving code to files

2009-01-20 Thread Tim M
Is it possible to compile D source code to object files without first saving the source to the filesystem. I kind of would like to generate the code within the program and use a static or dynamicly linked program to compile it. Not like interpreting script language.