Re: Loop through all modules and module members?
On Sat, Jan 1, 2011 at 18:56, Andrej Mitrovic andrej.mitrov...@gmail.com wrote: On 1/1/11, Philippe Sigaud philippe.sig...@gmail.com wrote: I'm not sure it's doable at compile-time right now: you need to have access to the module code, as text. Do imports work in CT-evaluable functions? Philippe You're gonna love this: module mymodule; void main() { pragma(msg, import(.stringof[7..$] ~ .d)); } I saw your .stringof trick a few days ago and it made my day :-) But I didn't know you could text-import at compile-time (with access for the programmer, I mean. Obviously the compiler can import at CT). Cool! OK, then it's doable to get a compile-time list of imported modules from a module name. Too bad modules are not first class in D: would they have type, we could return a list of them [std.algorithm, std.concurrency, ...] Of course, you need to -J switch with the path of your module. I'm not much versed in DMD switches. I'll try and see. Philippe
Re: dmd compile with imported modules
rdmd has some problems with my lib-files. Instead of rdmd I just tried xfbuild and it works great on windows, but as I can see there is no linux 32 bit version which I would like to use?!
Re: cstrings
On Saturday 01 January 2011 20:12:31 Ellery Newcomer wrote: are there any other cstring - dstring functions than to!string(char*) ? something like to!(char[])(char*) (the memory allocation bothers me) to!(char[])() should work just fine, but I believe that you're going to have to have a memory allocation regardless, since a D array can't refer to an arbitrary pointer. A D array and a C/C++ array are two different different things, even though a D array uses a C/C++ array internally. A D array is able to be resized and reallocated and the like in a way that a C/C++ array can't be. - Jonathan M Davis
Re: cstrings
Am 02.01.2011 05:12, schrieb Ellery Newcomer: are there any other cstring - dstring functions than to!string(char*) ? something like to!(char[])(char*) (the memory allocation bothers me) You can simply make a slice. Indexing and sclicing works also with c-style pointers in D. Obviously $ is not allowed because bare pointers don't have a length. poinetr[0 .. strlen(pointer)] Be sure to not give this array to functions which relies on your char[] to be GC-allocated.
Re: void main returning int - why compiles?
Manfred Nowak: | Expression is allowed even if the function specifies a void return | type. The Expression will be evaluated, but nothing will be returned. | If the Expression has no side effects, and the return type is void, | then it is illegal. http://www.digitalmars.com/d/2.0/statement.html (cited 01/01/11) _and_ foo() is not marked to have no side effects. Walter has closer my issue with this comment: http://d.puremagic.com/issues/show_bug.cgi?id=5399 It is not a dangerous corner case, it is a deliberate design choice. It is meant to facilitate writing generic code so that the same code can be generated for void and non-void return values. But I don't understand still, I don't buy Walter's explanation still. I write my comments in D.learn because I don't want to fill Bugzilla with too much discussions. This compiles: int bar() { return 0; } void main() { return bar(); } While this doesn't, and this semantic difference looks like corner case of the general D rule (the good D rule seems that if it's a void function you can't return a value different from void, and if it's not a void function then you must return a value of the right type): int bar() { return 0; } void main() { auto temp = bar(); return temp; } If I want to create a void function foo(), and I want to generate code inside it, can't I just avoid to add a return statement in the generated code, instead of adding return and then letting the compiler silently ignore an eventually present return value? Bye, bearophile
Re: Loop through all modules and module members?
On 1/2/11, Philippe Sigaud philippe.sig...@gmail.com wrote: Of course, you need to -J switch with the path of your module. I'm not much versed in DMD switches. I'll try and see. Philippe Well it's a simple switch, really. If the module is in C:\dev\project\, use: dmd -JC:\dev\project\ On *nix it's the same, I believe. http://www.digitalmars.com/d/2.0/dmd-windows.html#switches http://www.digitalmars.com/d/2.0/dmd-linux.html#switches
Re: sizeof
Ellery Newcomer wrote: prints 12, DMD 2.051 linux So we have: ( linux32 , dmd 2.051) - 12 ( linux32 , gdc) - 12 ( linux64 , gdc) - 12 ( linux64 , ldc) - 16 ( win32 , dmd 2.051) - 16 ( cygwin32, gdc) - 16 Congrats Ellery: this looks like a stairway to hell. -manfred
Re: Initialising arrays at compile time
Peter Alexander: Ok, someone put me out of my misery, I can't figure out for the life of me how to do this. Basically, I have a vector class and want enums for the zero vectors: struct Vec { this(real x, real y) { e[0] = x; e[1] = y; } real[2] e; enum Vec zero = Vec(0, 0); } Is this good enough? struct Vec { double[2] e; static enum Vec zero = Vec([0.0, 0.0]); this(real x, real y) { e[0] = x; e[1] = y; } } void main() {} (I think that enum and static enum are the same thing.) Bye, bearophile
What is an Effect?
docs: | Expressions that have no effect, like (x + x), are illegal in | expression statements. But what sorts of effects are meant with this? In phobos the expressionStatement `cmp(foo, bar);' is used in unittest.d. A comment says: | Bring in unit test for module by referencing function in it wtf? Does this mean, that a second expressionStatement `cmp(foo, bar);' in unittest.d would be illegal, but not the first, because by the second statement the unit test of that module can no more be brought in? Is then in `int x= 42; x= 42;' the assignment of the value `42' to the varaible `x' illegal, because `x` already has this value as initialization? Furthermore: is the result of suppressing an effect nevertheless an effect, especially suppressing the default initialization of a variable? Somehow this reminds me on the time when set theory got the attribute naive. -manfred
Re: What is an Effect?
Manfred_Nowak Wrote: docs: | Expressions that have no effect, like (x + x), are illegal in | expression statements. But what sorts of effects are meant with this? (x + x) performs a calculation and throws out the result. x = 42; x = 42; This is performing an assignment of the same value. Note that the difference is that the first is context free. x = 42 is doing something even though it would not change behavior of the running program. The first one is just having the CPU run some computation and does not affect the state of the program.