Re: __traits and std.traits and constructors

2010-11-14 Thread Jonathan M Davis
On Sunday 14 November 2010 07:13:43 Philippe Sigaud wrote: > On Sun, Nov 14, 2010 at 11:16, Jonathan M Davis wrote: > > Is there a way to get use constructors with traits functions that take a > > function? For instance, functionAttributes!(func) takes a func and tells > > you whether it's pure, n

Re: segfault

2010-11-14 Thread Pelle Månsson
On 11/12/2010 02:03 PM, Steven Schveighoffer wrote: Pelle, I spent all this time helping him, and you swoop in with the answer :) I was in a rush when answering, causing the swoopiness of my post. :-) I only knew the answer because I had almost exactly the same bug a week ago, or so. Coincid

Re: Reading stdin in Windows 7

2010-11-14 Thread Adam Wall
I experience the exact same problem on Windows 7 64-bit. > import std.stdio; > > int main() { > char[] buf; > while (stdin.readln(buf)) > write(buf); > return 0; > } If compiled as "test.exe", running the following command: > echo "test line 1" | test Produces the following

Bemused by this build error

2010-11-14 Thread Bob Cowdery
Hi I copied a module because I am changing its form. The original is still in the build but is a different package and class name. The closest thing I can think it might be talking about is this line: x_points[] = (x_average[0][]+x_average[1][]+x_average[2][]+x_average[3][]+x_average[4][]+x_avera

Re: Switch constants

2010-11-14 Thread BCS
Hello bearophile, In a not-ranged cases body, like in the program below (that doesn't compile), the switch variable is a compile-time constant, so why doesn't the compile see x as constant there? template Foo(uint x) { static if (x <= 1) enum Foo = 1; else enum Foo = x * Foo!(x - 1); } int bar(

Re: runtime type and that bizarre "is()"

2010-11-14 Thread BCS
Hello Jonathan, On Sunday 14 November 2010 03:45:12 spir wrote: Hello, Is there a way to check the runtime type of an element? Meaning, for instance, process differently according to the actual type in a hierarchy? class C {} class C1 : C {int i;} bool checkTypeC1 (C c) { return is(typeof(c)

Re: __traits and std.traits and constructors

2010-11-14 Thread Philippe Sigaud
On Sun, Nov 14, 2010 at 11:16, Jonathan M Davis wrote: > Is there a way to get use constructors with traits functions that take a > function? For instance, functionAttributes!(func) takes a func and tells you > whether it's pure, nothrow, etc. However, giving it the type doesn't work > (i.e. > fu

Re: struct vs class

2010-11-14 Thread Lutger Blijdestijn
spir wrote: > On Sun, 14 Nov 2010 12:02:35 + > div0 wrote: > >> > Both of these points may conflict with semantic considerations above: >> > we may want to use structs for fast creation, but if ever they mean >> > "things", we must think at referencing them manually and/or using >> > ref

Re: Nested associative arrays

2010-11-14 Thread Jacob Carlborg
On 2010-11-13 18:27, div0 wrote: On 13/11/2010 15:49, Jacob Carlborg wrote: On 2010-11-13 14:56, div0 wrote: On 13/11/2010 11:02, Jacob Carlborg wrote: On 2010-11-12 17:44, Ellery Newcomer wrote: Should be. Are you having problems? (I don't use them much, but fwiw, it seems like tango had so

Re: struct vs class

2010-11-14 Thread Jonathan M Davis
On Sunday 14 November 2010 04:14:29 spir wrote: > On Sun, 14 Nov 2010 03:32:18 -0800 > > Jonathan M Davis wrote: > > On Sunday 14 November 2010 03:08:49 spir wrote: > > > Hello, > > > > > > > > > There seems to be 2 main differences between structs & classes: > > > 1. structs instances are dire

Re: runtime type and that bizarre "is()"

2010-11-14 Thread spir
On Sun, 14 Nov 2010 04:09:22 -0800 Jonathan M Davis wrote: > If you are dealing with a class hierarchy and you want to know whether a base > class reference referes to a particular derived class object, I believe that > the > correct way to do it is cast it to the derived type and check whethe

Re: struct vs class

2010-11-14 Thread spir
On Sun, 14 Nov 2010 12:02:35 + div0 wrote: > > Both of these points may conflict with semantic considerations above: > > we may want to use structs for fast creation, but if ever they mean > > "things", we must think at referencing them manually and/or using > > ref parameters. We may want

Re: runtime type and that bizarre "is()"

2010-11-14 Thread bearophile
spir: Only partial answers, other answers left to other people. > Is there a way to check the runtime type of an element? Meaning, for > instance, process differently according to the actual type in a hierarchy? You may use a cast(). If it return null then it's not castable. > Also, I would l

Re: struct vs class

2010-11-14 Thread spir
On Sun, 14 Nov 2010 03:32:18 -0800 Jonathan M Davis wrote: > On Sunday 14 November 2010 03:08:49 spir wrote: > > Hello, > > > > > > There seems to be 2 main differences between structs & classes: > > 1. structs instances are direct values, implement value semantics; while > > class instances ar

Re: runtime type and that bizarre "is()"

2010-11-14 Thread Jonathan M Davis
On Sunday 14 November 2010 03:45:12 spir wrote: > Hello, > > > Is there a way to check the runtime type of an element? Meaning, for > instance, process differently according to the actual type in a hierarchy? > > class C {} > class C1 : C {int i;} > bool checkTypeC1 (C c) { > return is(typeo

Re: struct vs class

2010-11-14 Thread div0
On 14/11/2010 11:08, spir wrote: Hello, There seems to be 2 main differences between structs& classes: 1. structs instances are direct values, implement value semantics; > while class instances are referenced (actually "pointed") 2. classes can be subtyped/subclassed in a simple way; structs

Re: struct vs class

2010-11-14 Thread bearophile
spir: > a value makes no sense by itself, it is bound to what it describes an aspect > of; referencing a value is meaningless, only copy makes no sense. For > instance, the position & color of a visual form should be values. Structs may have a meaning by themselves, all kind of member functions

runtime type and that bizarre "is()"

2010-11-14 Thread spir
Hello, Is there a way to check the runtime type of an element? Meaning, for instance, process differently according to the actual type in a hierarchy? class C {} class C1 : C {int i;} bool checkTypeC1 (C c) { return is(typeof(c) == C1); } void main () { C1 c1 = new C1(); writeln(is(

Re: struct vs class

2010-11-14 Thread Jonathan M Davis
On Sunday 14 November 2010 03:08:49 spir wrote: > Hello, > > > There seems to be 2 main differences between structs & classes: > 1. structs instances are direct values, implement value semantics; while > class instances are referenced (actually "pointed") 2. classes can be > subtyped/subclassed i

Re: Calling a D function from C

2010-11-14 Thread Carlo
On 13/11/2010 14:20, Simen kjaeraas wrote: Michal Minich wrote: first: extern (C) means that the function 'fun' is not defined in D, but in C. Wrong. It means the function has C calling convention. If it has a body, it is defined in D, and can be called from C (and D). If not, it is defined

Re: Calling a D function from C

2010-11-14 Thread Carlo
On 12/11/2010 16:19, Michal Minich wrote: V Fri, 12 Nov 2010 16:14:30 +0100, Carlo wrote: Sorry if I bother you again with this probably silly problem. Here is the point. I want to call the D function "fun" from a .c file: \\file libforc.d extern (C) int fun(int x,int y){ return x; }

Re: Trouble with OPTLINK

2010-11-14 Thread Aardvark Soup
Op 13-11-2010 22:14, bearophile schreef: Aardvark Soup: I've already tried cleaning up all build files and adding the current directory to the system PATH, both to no avail. This does not happen while I compile single-file programs that import from the standard library. Does anyone have an idea

struct vs class

2010-11-14 Thread spir
Hello, There seems to be 2 main differences between structs & classes: 1. structs instances are direct values, implement value semantics; while class instances are referenced (actually "pointed") 2. classes can be subtyped/subclassed in a simple way; structs cannot be really subtyped -- but the

Re: Is there a way to forward-declare interfaces to avoid module interdependencies?

2010-11-14 Thread Per Ångström
On 2010-11-11 17:21, Steven Schveighoffer wrote: First, you can't forward-declare classes in one file that are defined in another file, instead of importing. The reason is because in D, the module is the namespace that the class is declared in. So for instance, when you define IStudent in IStude

__traits and std.traits and constructors

2010-11-14 Thread Jonathan M Davis
Is there a way to get use constructors with traits functions that take a function? For instance, functionAttributes!(func) takes a func and tells you whether it's pure, nothrow, etc. However, giving it the type doesn't work (i.e. functionAttributes!T), and giving it this doesn't work (i.e. funct

Re: Nested associative arrays

2010-11-14 Thread spir
On Sun, 14 Nov 2010 10:35:42 +0100 spir wrote: > > I finally found the bit where it describes associative array literals > > and they look identical to initialising a flat array, so god only knows > > which one gets picked when. It would be better if they where made > > different. > > ... w

Re: Nested associative arrays

2010-11-14 Thread spir
On Sun, 14 Nov 2010 00:03:48 + div0 wrote: > yeah, but dmd's parser was written by hand so it's not surprising there > are inconsistency's with what works where. Well, most (all?) truely used languages have hand-written parsers, AFAIK. The issue is not with writing the parser, I guess, bu