Re: Template Inheritance
I think I got it! This seems to work: class Derived { //Pulls in all the template forms in the base class template get(args ...) { alias Base.get!args get; } //Create new versions of get() here. }
Re: Template Inheritance
Thanks! I guess I'll just have to live with redefining the functions, do some sort of interface/mixin thing, or change the class interface. It makes sense that template functions aren't virtual (how are you supposed to deal with vtables?), but I wish that at least an alias declaration could work. Maybe if there were some way to alias the base template and then modify it... Templates inheriting from templates would be a very interesting way to accomplish that, but it would be a very strange system...
Re: Template Inheritance
Correction: redefining in the *subclass*. Silly me.
Re: Template Inheritance
In the interim, I'm just redefining the template in the base class, but that's a really annoying hack to have to perform every single time I have to make a new form of the template.
Template Inheritance
I've been working on porting an old D library to D2, and I'm running into a nasty issue with templates and inheritance. I've got a base class like this: class Reader { void get(T)(ref T[] buffer); } and a subclass like this: class SubReader { void get()(SomeClass param); } The problem is that by creating a new form of the template in the subclass, I made the base class's version invisible. If I try to use "alias Reader.get get" like I would do for functions, the compiler complains that the symbols clash (no musical puns intended). Does anyone know how to get this to work?
Re: floating-WTF - Compiler-BUG with 64bit
Shouldn't this go into 'digitalmars.D' ?
Re: extends and implements
== Quote from Steven Schveighoffer (schvei...@yahoo.com)'s article > On Mon, 07 Nov 2011 13:22:07 -0500, %u wrote: > In order for such a humongously code-breaking change to occur, there would > have to be dire reasons why this was necessary. Because you liked Java is > not a qualifying reason. > -Steve Hey man, Sorry if I annoyed you. No need to feel insulted. I get it: the *real* reason is that it will break alot of code. I'm just asking, it's not a big deal. I find that it helps readability. But as others have stated, you list the the extended class first and that's good enough! thanks.
extends and implements
Hello. I know D isn't Java, but one trivial thing I liked about Java is the introduction of 'extends' and 'implements' as keywords as ways to clarify the class relationships when defining a class. You know: class Subclass extends SuperClass implements AnInterface { ... } Will they ever add this in to D? If not, why not? thanks.
gtkD problems and general gui question.
Hello. I downloaded gtkD MS Windows installer, and I tried to compile one of the examples shown on the gtkD website: http://www.dsource.org/projects/gtkd The example is below along with the problem: import gtk.MainWindow; import gtk.Label; import gtk.Main; void main(string[] args) { Main.init(args); MainWindow win = new MainWindow("Hello World"); win.setDefaultSize(200, 100); win.add(new Label("Hello World")); win.showAll(); Main.run(); } When I compile the above code, I get the following problem: $ dmd HelloGUI.d HelloGUI.d(1): Error: module MainWindow is in file 'gtk\MainWindow.d' which cannot be read import path[0] = C:\D\dmd2\windows\bin\..\..\src\phobos import path[1] = C:\D\dmd2\windows\bin\..\..\src\druntime\import If I look at my path I see that the path to gtk was installed by the windows installer: /usr/local/bin:/usr/bin:/cygdrive/c/Windows/system32:/cygdrive/c/Wi ndows:/cygdrive/c/Windows/System32/Wbem:/cygdrive/c/Windows/System3 2/WindowsPowerShell/v1.0:/cygdrive/c/D/dmd2/windows/bin:/cygdrive/c /D/dm/bin:/cygdrive/c/D/dmd/windows/bin:/cygdrive/c/Program Files (x86)/QuickTime/QTSystem:/cygdrive/c/Program Files (x86)/GTK2- Runtime/bin:/usr/lib/lapack My dmd version is: $ dmd -v DMD32 D Compiler v2.055 Copyright (c) 1999-2011 by Digital Mars written by Walter Bright Documentation: http://www.digitalmars.com/d/2.0/index.html Usage: Finally, is gtkD the way to go when it comes to learning gui with D? Which gui is the most popular with D? Which one has a future? And which is the easiest to learn? thanks.
Re: problems with DPL example.
== Quote from bearophile (bearophileh...@lycos.com)'s article > simendsjo: > > Shouldn't the original way work too? > I don't remember. > > Another point: I recommend compiling with debug symbols as it gives you > > a nice stacktrace. > I think debug symbols should be present on default, to produce a nice stack trace on default, and be disabled with a compiler switch :-) > Bye, > bearophile If I use file indirection instead of piping output to the d program, it works in cygwin window. I'm not a dos expert, so I don't know how to do the same test on windows. anyways, thanks!
Re: problems with DPL example.
Thanks. It works, but I get something weird in the output. I get the problem if I run it in a dos prompt or in a cygwin prompt: Microsoft Windows [Version 6.1.7600] Copyright (c) 2009 Microsoft Corporation. All rights reserved. D>echo hello | wordcount2.exe 0 hello std.stdio.StdioException@std\stdio.d(2156): Bad file descriptor 42A910 42A787 40318A 40239C 402141 403798 4037D7 4033D3 465D71 Do you know what this is caused by? thanks. Here's the code again: import std.stdio, std.string, std.array; void main() { uint[string] dictionary; foreach( line; stdin.byLine()) { // Break sentence into words // Add each word in the sentence to the vocabulary foreach( word; splitter(strip(line))) { if( word in dictionary) continue; // Nothing to do. auto newID = dictionary.length; dictionary[word.idup] = newID; writeln( newID, '\t', word); } } return; } thanks.
Re: problems with DPL example.
== Quote from simendsjo (simend...@gmail.com)'s article > Seems some functionality was moved in 2.052. From std.string documentation: > "IMPORTANT NOTE: Beginning with version 2.052, the following symbols > have been generalized beyond strings and moved to different modules." > And > "splitUse std.array.split instead" > std.array includes both split and splitter. > http://www.d-programming-language.org/phobos/std_array.html#split Okay, thanks for that. I added the extra module, and found I made a typo. So I corrected that too. Anyways, I am now having another problem. What can I do to fix it? : import std.stdio, std.string, std.array; void main() { uint[string] dictionary; foreach( line; stdin.byLine()) { // Break sentence into words // Add each word in the sentence to the vocabulary foreach( word; splitter(strip(line))) { if( word in dictionary) continue; // Nothing to do. auto newID = dictionary.length; dictionary[word] = newID; writeln( newID, '\t', word); } } return; } $ dmd wordcount.d wordcount.d(12): Error: associative arrays can only be assigned values with immutable keys, not char[] $ dmd -v DMD32 D Compiler v2.055 Copyright (c) 1999-2011 by Digital Mars written by Walter Bright Documentation: http://www.digitalmars.com/d/2.0/index.html Usage: thanks!
Re: How convice people that D it's wonderfull in a hour ?
== Quote from Zardoz (luis.panad...@gmail.com)'s article > Recently I've been asked if I could give a speech about D in my university. It > will be of one hour of long. > I not respond yet, but I think that I will do it. Actually I have the problem > that I don't know well how explain well too many features and things of D that > I like. I think that only talking about D's arrays and type system I will need > around half-hour. > Any recommendation of how I should focus it ? Well, I am going through the DPL book. The first chapter is pretty cool. Maybe just shamelessly copy Andreescu's chapter 1, but throw in stuff about garbage collection and threading model, which I think are pretty cool. I think having some cool examples that highlight features of the language is the way to go. Good luck with your presentation!
problems with DPL example.
Hello. I'm having problems compiling the following: // From chapter 1 of D Programming Language. // import std.stdio, std.string; void main() { uint[string] dictionary; foreach( line; stdin.byLine()) { // Break sentence into words // Add each word in the sentence to the vocabulary foreach( word; splitter(strip(line))) { if( word in dictionary) continue; // Nothing to do. auto newID = dictionary.length; dictionary[word] = newID; writeln( newid, '\t', word); } } return; } $ dmd wordcount.d wordcount.d(9): Error: undefined identifier splitter $ dmd -v DMD32 D Compiler v2.055 Copyright (c) 1999-2011 by Digital Mars written by Walter Bright Documentation: http://www.digitalmars.com/d/2.0/index.html I am doing the examples in cygwin. Anyone know what the problem is? thanks.
Re: how do I use newsgroup server?
== Quote from Nick Sabalausky (a@a.a)'s article > > I guess I don't know how to setup my outlook client to use the news > > link? When I click the news link. Nothing happens. > I don't have access to a Win7 machine ATM, but on both XP and Vista, you can > do: > Tools -> Accounts. There will be a button for "Add". Click that and then you > can choose "News". And just fill in all the info. The (NNTP) server is > "news.digitalmars.com", and it doesn't take a login. > Then you should see the news server in the big tree on the left side of the > main window. You can choose which groups to subscribe to (digitalmars.D, > digitalmars.D.learn, etc.). When you're subscribes to one, you can go to it > and click the "Headers" button to check for messages (at least that's what > it is in on XP). Downloading the headers might take awhile the first time. Directions look very promising. My outlook complains about "problem connecting to the server". So, when I tried to ping the ip address of news.digitalmars.com, all requests time out. So is it just that the server is down? by the way, thanks for helping me out!!
Re: how do I use newsgroup server?
== Quote from Nick Sabalausky (a@a.a)'s article > "%u" wrote in message news:j655f0$fm8$1...@digitalmars.com... > > Hello. > > > > I go to digitalmars to read digitalmars.D.learn newsgroup, but I > > have to click the http link. The http interface is kind of > > awkward. I'd like to try the newsgroup link. > > > > But, I don't know how to use it. How do I? Is there a client I > > can download and use for free that you recommend? I did a search > > and found a few usenet readers. Can I use that? I'd like to give > > it a try, but these days, I don't know if I can trust the sites. > > > > Anyways, thanks! > Pretty much any email client. (That is, *real* email clients, not that > webmail junk.) I use Outlook Express ("Windows Mail" in the Mac- alike > versions of Windows). Many people here use Thunderbird. And I'm told that > Opera has a built-in NG client that some people like too. I guess I don't know how to setup my outlook client to use the news link? When I click the news link. Nothing happens. So, I tried downloading this 'seamonkey' newsreader. When I installed it, and clicked the d-learning news link, a browser appears,but I don't have any postings. Anyways, I am using windows 7, if that helps. thanks.
OT: how do I use newsgroup server?
Hello. I go to digitalmars to read digitalmars.D.learn newsgroup, but I have to click the http link. The http interface is kind of awkward. I'd like to try the newsgroup link. But, I don't know how to use it. How do I? Is there a client I can download and use for free that you recommend? I did a search and found a few usenet readers. Can I use that? I'd like to give it a try, but these days, I don't know if I can trust the sites. Anyways, thanks!
newbie question
does D compatibility with C restrict D from evolving ? and if D drop this will that prevent complexity?
Re: quickSort
i have qustion why filter can't return int[] and if lambda return the last Expression without return keyword it would much cleaner
pattern matching
template factorial(int n) { const factorial = n * factorial!(n-1); } template factorial(int n : 1) { const factorial = 1; } i think this pattern matching or like it, can i do the same thing with regular function int factorial(int n) { return n* factorial(n-1); return 1 ; } int factorial(int n : 0) { return 1 ; } is that work? thanks in advance
Re: gdc setup without gcc
I have 2 issue: 1- i can't install the package, there is problem I don't know what is it? 2-it is not updated.
gdc setup without gcc
is there a way to install gdc without gcc because I already have gcc install in archlunix?
changing in two arrays
hi I create two arrays and I want the change in one of them effects the other one. i try int[] array1 = [1, 2, 3, 4, 5]; int[] array2; array2 = array1; // without .dup assert(array1 == array2); assert(array1 is array2); // here i am confused because 'is' mean thay have the same address or what? array2 ~= 6; assert(array1 == [1, 2, 3, 4, 5]); // here is the problem assert(array2 == [1, 2, 3, 4, 5, 6]);
Re: nested comments
I understand it thanks
Re: nested comments
commenting out code?? example please
nested comments
what is the purpose of nested comments ?
object.function()
I have a question, can I write all functions like this object.function() instead of functin(object) ? or that form for some function or cases.
Re: int or size_t ?
size_t val1 = int.max+1; int val2 = int.max+1; writeln(val1); // 2147483648 writeln(val2); // -2147483648 very clear example thanks you both
int or size_t ?
In Patterns of Human Error, the slide 31 point that you should replce int with size_t why that consider an error ?
Re: multiple return
thanks you all, it works. last thing, I have this Tuple!(int,int,int)(1, 2, 3) how can I use the return values individual? to be more clear if I rturn tuple(a, b, c) can I write in the code void main() { //call the function here writeln(a); }
multiple return
I have function which have more than one return, and the code compile and run but it gives rong result -I guess-, so i use tuple but the compiler can't return tuple. how can I return values? why I can't return tuple?
pointers and structures
what is the equivalent for this code in D? #include main() { struct S { int i; }; struct S s, *s_ptr; s_ptr = &s; s_ptr->i = 9; printf("%d\n", s_ptr->i); }
auto arr = new int[10];
is there any different b/w: auto arr = new int[10]; and int[10] arr; ?
Re: dmd & gdc in archlinux
== Quote from Jonathan M Davis (jmdavisp...@gmx.com)'s article > On Monday, March 07, 2011 12:10:27 %u wrote: > > == Quote from Jonathan M Davis (jmdavisp...@gmx.com)'s article > > > > > and add /path/to/unzipped/dmd2/linux/bin to your path. > > > > how can i add path ? > Put it in the appropriate bashrc file - be it your personal .bashrc or > /etc/bash.bashrc.local or whatever is appropriate for your system. On my Arch > system, I believe that I put it in /etc/bash.bashrc.local. Regardless, you > add a > line similar to this to your bashrc file: > export PATH=$PATH:/path/to/unzipped/dmd2/linux/bin > On my system, it's > export PATH=$PATH:/home/jmdavis/dmd2/linux/bin > - Jonathan M Davis Jonathan M Davis you are the best thanks
Re: dmd & gdc in archlinux
== Quote from Jonathan M Davis (jmdavisp...@gmx.com)'s article > and add /path/to/unzipped/dmd2/linux/bin to your path. how can i add path ?
Re: Writing an integer to a file
this is part of the code: void WritePushPop(cmd command, string segment, int index) { string temp = "TextFile.Asm"; AsmFile = new File(temp, FileMode.OutNew ); string x = toString(index); AsmFile.writeString("@"); AsmFile.write(index); AsmFile.writeLine("D=A"); AsmFile.writeLine("@0"); AsmFile.writeLine("A=M"); AsmFile.writeLine("M=D"); AsmFile.writeLine("D=A+1"); AsmFile.writeLine("@0"); AsmFile.writeLine("M=D"); } Now it wouldn't even build, it doesn't like the line: string x = toString(index); but this line works when I'm working with the console. Thanks!
Re: dmd & gdc in archlinux
== Quote from %u (asm...@hotmail.com)'s article > i can't install it and i use this command > yaourt -R gdc i mean yaourt -S gdc
Re: dmd & gdc in archlinux
in dmd: this the error massage object.d: Error: module object is in file 'object.d' which cannot be read import path[0] = /usr/include/d import path[1] = /usr/include/d/druntime/import in gdc: i can't install it and i use this command yaourt -R gdc
dmd & gdc in archlinux
i can't install dmd or gdc in arch linux from AUR i don't way?
Re: C++ to D: Help please
bearophile, You do have a point there, and I actually expected that response. I would have posted my attempt at implementation, but am unable to transfer info between the computer I'm typing this message on and the one I'm programming on at the moment. I have no problems converting small problems. Hence why I'm not trying to convert small scripts. My problems are in understanding the inner workings of multimodule programs, how to create them, create the make file to use in comepiling them, and then since I'm reading C/C++ (which I don't know much about) but trying to learn D, how to do it correctly in D? I do appreciate your response though. Have a blessed day.
C++ to D: Help please
I requested some assistance with operator overlaoding yesterday and I really appreciate the assistance provided. However, trying to incorporate the example just confused me a little more, it does not meld well with the code I translated from the tutorial I am reading. I am hoping that one of you experienced programmers out there could lend me a hand converting this small program to D. Not really interested in staying true to form with the way C++ does it because I don't know that much C++, just trying to learn D from the example. As just hoping to capture all the functionality of provided in the program so that I can observe the transition from C++ to D in a complete and useful example. The code is here: http://www.relisoft.com/win32/source/generic.zip Again, thank you all very much.
Re: "operator" overloading?
Thaks to everyone for your assistance.
"operator" overloading?
Hi everyone, Was hoping someone could help me make sense of this bit of C++ code: class canvas { operator HDC() { return _hdc; } protected: canvas(HDC hdc): _hdc(hdc) {} HDC _hdc; } >From what I understand, HDC is an alias for HANDLE in Windows. So they are overloading canvas such that when assigned to handle instance it returns _hdc? How is this done in D? Thanks
Re: Context-Free Grammars? What about arrays?
> Yes, they just happen to look identical: but that's the crux: How it "looks" is the *only* thing that parser/grammar are concerned with. > If it worked like this: > ::= '[' ']' ';' > ::= '[' ']' ';' > ...*Then* it would no longer be context-free because the parser would have to rely on the semantics of 'U' to determine how to parse it. Ahh that makes sense. Thank you for the great explanation! :)
Re: Inheritance problem
== Auszug aus Andrej Mitrovic (andrej.mitrov...@gmail.com)'s Artikel > On 2/11/11, bearophile wrote: > > Steven Schveighoffer: > > > >> Any code can access any members defined in the current module, regardless > >> > >> of access attributes > > > > I am not sure if Walter understands how much this rule makes it hard for > > people not already used to protected/private attributes to understand and > > learn to use those attributes correctly. The C# compiler doesn't have that > > rule, and it's much more strict. I think this makes learning the usage of > > those attributes faster. > > > > Bye, > > bearophile > > > I think one benefit of the current approach is that we'll be able to > use free functions which could be called as if they belong to a class > (if they have that class as the first parameter), since we could use > the uniform function call (UFC) syntax. But UFC doesn't work with > classes yet, otherwise we might be able to do this: > module foo; > import std.stdio; > class Foo { > private int _x, _y; > this(int x, int y) { > _x = x; > _y = y; > } > } > int sumXY(Foo foo) { > return foo._x + foo._y; > } > module main; > import foo; > import std.stdio; > void main() { > auto obj = new Foo(10, 10); > writeln(obj.sumXY()); // using UFC, but doesn't work yet > //~ writeln(obj._x + obj._y); // not allowed > } > We could have a bunch of templated functions in the foo module which > could work with any class inside that module. So it might help out > against the common God class problem. What do you think? Looks really interesting - would be a nice feature :)
Re: Inheritance problem
== Auszug aus bearophile (bearophileh...@lycos.com)'s Artikel > Steven Schveighoffer: > > Any code can access any members defined in the current module, regardless > > of access attributes > I am not sure if Walter understands how much this rule makes it hard for people not already used to protected/private attributes to understand and learn to use those attributes correctly. The C# compiler doesn't have that rule, and it's much more strict. I think this makes learning the usage of those attributes faster. > Bye, > bearophile I already used protected/private (and other languages like Java and... D too), but it was a bit unintelligible because protected means (for me) that every instance of an inheritanced class can access the protected members. An alternative to protected like modprotected or something like this should be added that people can declare it as modprotected which means that inheritanced classes of another module can also access these attributes.
Re: Inheritance problem
== Auszug aus Steven Schveighoffer (schvei...@yahoo.com)'s Artikel > On Fri, 11 Feb 2011 16:14:31 -0500, %u wrote: > > == Auszug aus Steven Schveighoffer (schvei...@yahoo.com)'s Artikel > > > > Thanks, but what about the following: > > > > import std.stdio : writeln; > > > > class a { > > > > public this(int v) { > > myVar = v; > > } > > > > protected int myVar; > > > > } > > > > class b : a { > > > > private a[] moreInstances; > > > > this(int v, int[] vars...) { > > super(v); > > moreInstances ~= this; > > > > foreach(int cur; vars) { > > moreInstances ~= new a(cur); > > } > > } > > > > int getVar() { > > return moreInstances[1].myVar; > > } > > > > } > > > > void main(string[] args) { > > b exp = new b(0, 1, 2); > > writeln(exp.getVar()); > > } > > > > This compiles fine and prints the number 1. myVar is also protected > > in class a, I also call myVar in the getVar()-method of class b. > Any code can access any members defined in the current module, regardless > of access attributes (that rule is outlined in the link I sent, I just > didn't quote that part). You have to split this into multiple modules to > see the other rules take effect. > -Steve Ah, okay... this means I have to Texture and Animation into one module. Thanks a lot!
Re: Inheritance problem
== Auszug aus Steven Schveighoffer (schvei...@yahoo.com)'s Artikel > On Fri, 11 Feb 2011 15:40:18 -0500, %u wrote: > > Hello, > > > > I've a problem with my class inheritance. I have class called Texture > > which implements the interface IDrawable and the abstract class > > APickable. > > The Texture-class contains 3 members which looks like this: > > > > GLuint pTextureID; > > > > Size pSize1, pSize2; > > > > Finally... my Texture-class looks like: > > > > class Texture : APickable, IDrawable { > >protected { > > GLuint pTextureID; > > Size pSize, pAnoutherSize; > >} > > } > > > > now... I have a second class called Animation which looks like this: > > > > class Animation : Texture { > >private { > > Texture[] pFrames; > >} > >public { > > this(string file, string[] paths...) { > > super(file); > > pFrames ~= this; > > foreach(string cur; paths) { > > pFrames ~= new Texture(cur); > > } > > } > > > > Size getSize() { > > return pFrames[0].pSize; > > } > >} > > } > > > > As I know, pFrames[0].pSize can be called... pSize in the Texture- > > class is marked as protected, but I get the following error: > > > > Error: class Texture member pSize is not accessible. > > > > When I mark the protected members of the Texture-class as public, it > > works (should be clear), but why do I get this error when mark them > > as protected? > > > > I hope anyone can help to solve the problem. > protected means you cannot access it outside the *instance*. The pFrames > array references *other instances* of Texture, so they are not accessible. > http://www.digitalmars.com/d/2.0/attribute.html#ProtectionAttribute > "If accessing a protected instance member through a derived class member > function, that member can only be accessed for the object instance which > is the ‘this’ object for the member function call." > -Steve Thanks, but what about the following: import std.stdio : writeln; class a { public this(int v) { myVar = v; } protected int myVar; } class b : a { private a[] moreInstances; this(int v, int[] vars...) { super(v); moreInstances ~= this; foreach(int cur; vars) { moreInstances ~= new a(cur); } } int getVar() { return moreInstances[1].myVar; } } void main(string[] args) { b exp = new b(0, 1, 2); writeln(exp.getVar()); } This compiles fine and prints the number 1. myVar is also protected in class a, I also call myVar in the getVar()-method of class b.
Inheritance problem
Hello, I've a problem with my class inheritance. I have class called Texture which implements the interface IDrawable and the abstract class APickable. The Texture-class contains 3 members which looks like this: GLuint pTextureID; Size pSize1, pSize2; Finally... my Texture-class looks like: class Texture : APickable, IDrawable { protected { GLuint pTextureID; Size pSize, pAnoutherSize; } } now... I have a second class called Animation which looks like this: class Animation : Texture { private { Texture[] pFrames; } public { this(string file, string[] paths...) { super(file); pFrames ~= this; foreach(string cur; paths) { pFrames ~= new Texture(cur); } } Size getSize() { return pFrames[0].pSize; } } } As I know, pFrames[0].pSize can be called... pSize in the Texture- class is marked as protected, but I get the following error: Error: class Texture member pSize is not accessible. When I mark the protected members of the Texture-class as public, it works (should be clear), but why do I get this error when mark them as protected? I hope anyone can help to solve the problem.
Inserting nodes into a tree
Please pardon my complete lack of knowledge. Please provide some suggestions/pointers so that I can improve myself. Given a table containing three values (ie, myName, myId, parentId), how does one insert those values into a tree such that the parent/child relationship defined in the table is maintained? Basically I'm given a file containing parents and children in no particular order. I would like to print all children of a given parent regardless of where they fall on the tree. Note, this is not a school related question, simply a retard trying to learn how to do things more efficiently. Thanks
Re: Context-Free Grammars? What about arrays?
Sorry, please ignore the very last line: Temp!(2) b; //Why does this break? I totally wasn't thinking about the fact that T is a tuple in "int[T] arr;". (I would intuitively think that it should still work, given that a tuple is just a bunch of types, but I can see why it wouldn't.) However, why the previous statement breaks: Temp!() a; is still puzzling me, since giving nothing to the tuple should be equivalent to nothing being in the array. Thanks.
Re: Context-Free Grammars? What about arrays?
> That will always parse to an associative array. Then in the semantic pass, if > U is a constant expression that turns out to be an integer it is reinterpreted as a static array. Ah, interesting. But that describes the implementation (i.e. how the compiler copes with the ambiguity) and not the language itself. > Context-free means that it's unambiguous as to which grammar rule is to be applied at any point during the parsing process. The problem is that it _is_ ambiguous what rule to apply. To me, just because static arrays and associative arrays happen to have similar _looks_ doesn't make parsing them context-free -- they're defined with completely separate syntaxes, and they just happen to look identical. The fact that the compiler has to do a semantic analysis in order to figure this out (which was originally a syntax problem) really makes me wonder why you mention that D is still context-free. > Not to mention, the context-free grammar is entirely for parsing tokens into > an abstract syntax tree. Again, just because the AST's _happen_ to _look_ the same for static and associative arrays, does that mean that this makes D context-free? The meaning of the expression is still ambiguous, whether or not it fits well within the tree. Furthermore, I would say that a struct like this: struct Temp(T...) { int[T] arr; } should work perfectly if T.length == 0, since it would then be a dynamic array. But the parser is forced to treat it as an associative array, and so _both_ of these break: Temp!() a; Temp!(2) b; //Why does this break? Why should the second one break, in any case?
Context-Free Grammars? What about arrays?
Hi, I think I'm having a little trouble understanding what's meant by context-free grammar. I've read that D is context-free, but is it really? What about an expression like: int[U] s; ? You can't tell -- without looking at the context -- whether U is a data type or a number, and so because associative arrays and regular arrays are syntactically different elements of the language, the syntax of D is tied in with its semantics, just like in C++. So is D really context-free? Or am I misunderstanding the meaning of the term? Thanks!
core languga
Hi excuse my ignorance what does that term mean? and what the different b/w learning D & pobos
Re: Ranges
> Related discussion: > http://www.digitalmars.com/d/archives/digitalmars/D/getNext_113217.html Oh sorry; thank you for the link!
Ranges
I've learned that an InputRange needs three methods to enumerate a collection: void popFront() @property T front() @property bool empty() but is that really necessary? Why not just have: bool next(out T value); ? Wouldn't this be much cleaner? Even the .NET implementation of IEnumerator only has two methods used for enumeration (MoveNext() and Current), instead of three.
Re: Why non-@property functions don't need parentheses
> It will be fixed at some point, but it hasn't been yet. Oh cool, all right; thanks!
Why non-@property functions don't need parentheses
Hi, I was wondering, why are we allowed to omit parentheses when calling functions with no arguments, when they are not @properties? Is there a good reason for relaxing the language rules like this? Thanks!
volatile deprecated, yet still in Phobos?
Hi, I've tried to compile programs and Phobos without deprecated features on, and yet I've come across a problem: Volatile statements are deprecated. So, for example, in thread.switchOut(), these statements are invalid: volatile tobj.m_lock = true; fiber_switchContext( oldp, newp ); What is the correct way to fix this? Thank you!
"__gshared static" versus "static __gshared"
Is this a bug? __gshared static i; makes i be thread-local, while static __gshared i; makes it be shared.
Re: D1: out of memory
== Quote from Robert Clipsham (rob...@octarineparrot.com)'s article > CTFE and templates will use up the most memory - particularly if you use > a lot of strings, as the memory allocated is never freed. You can work > around it be compiling files one at a time or a few at a time, so > instead of: > $ dmd file1.d file2.d > Use: > $ dmd -c file1.d > $ dmd -c file2.d > $ dmd file1.o file2.o > Note if you're doing this you may like to look into the -op option to > avoid object file conflicts which will lead to linker errors. Compiling main alone tops 400MB :D dmd -c -w proj_1\main.d The hassle is probably not worth the money for new memory.. if only I wasn't broke :D
Re: D1: out of memory
Er, bit exaggerated.. 450 to below 300 pls :)
D1: out of memory
How do I get dmd's memory usage a few hundred MBs down? I keep having to close everything in order not to get an out of memory error while compiling (-w -full). I'd like to get it from 700-800 to below 400 :) Any way to inspect which part is the biggest drain?
Re: Naming Conventions & Style Guide?
> I don't know what that abbreviation means. Haha I kind of made that up... just meant "My Mileage *Will* Vary" :) Huh, I never noticed the keyword conflict; that's totally legitimate, although personally I'd prefer PascalCased. But I don't like the "related to the language" idea; it shouldn't be any different. Interesting to know, though, nevertheless. :]
Re: Naming Conventions & Style Guide?
> Hmm.. I thought naming enums with capital letters was a standard thing in D land. I prefer them that way since they're constants, and since I almost always use a tag for an enum I never mistake it for anything else. YMMV. Huh, I guess now I see why they are the way they are. :) At first I wrapped Win32 constants, and so they were ALL_CAPS. Then I converted them to Windows/.NET-style, and they became PascalCased (both native and .NET use PascalCase)... then I read the style guide and started making them camelCased, and now I have code in each of these styles. Yeah, MMWV. :]
Naming Conventions & Style Guide?
Is there any particular reason that Phobos uses ALL_CAPS (such as FunctionAttributes.NOTHROW) and PascalCase (such as Endian.BigEndian) for enums, and yet the D Style Guide recommends lowerCamelCase?
Re: Exactly Replicating a Function's Signature?
> ref(const(immutable(string)[])) ? > That's crazy! Did you mean ref(const(immutable(char)[]))?? :] Haha... well it was just an idea on how to add the functionality, and like I mentioned, even if it was fine for 'ref' and 'lazy', it wouldn't make any sense for 'out' anyway, so I'd say screw my idea; forget it. :) The trouble with mixin is that it doesn't work the way templates like ParameterTypeTuple do, because if you dynamically generate the header then one of these must be true: 1. You can mixin() it in a template in Phobos, but that won't work because any data types not in the current (Phobos) module can't be referenced, which basically erases this solution completely. 2. You can just return a string and have the user use mixin() every time, but that's a very ugly and error-prone solution, since it would litter the user's code with lots of mixin()s. Hope that made sense... so my conclusion is that, with the current language/compiler features, it's likely there's no workable solution for this (although I'm happy to be proven wrong!!). :\
Re: Exactly Replicating a Function's Signature?
> The ugly solution would be to do this: > void test (ref int a) { } > void main () { writeln(typeof(&test).stringof); } > Which will print: "void function(ref int a)" and then parse out what you need. If you're referring to using mixin() to parse the signature, I've already thought of that, but it won't work because if the type of any parameter is a user-defined type, it will be inaccessible outside the module that provides this facility. This feature will require compiler and/or language modification(s); I don't believe you can add the storage-class feature correctly with the current language (though please correct me if I'm wrong). > Let me see if I get this straight (correct me if I'm wrong in understanding > this). > So you mean we would have e.g. ref as a type constructor: ref int x; Yes. > The problem with this is that now you're functions look like this: > foo(int x) { } No... why? ref would be just like const -- so your parameter's data type could be ref(const(string)). Why do you say the functions remove the type constructor from the header? [This is a bit unrelated, but while we're on the topic of documenting code through ref/out: I think it would be better if the language required the "ref" and "out" keywords on passing the parameters, like C# does... it prevents a lot of bugs that can happen when a function's header is changed, since now the caller code won't compiler, instead of compiling but working potentially incorrectly.) I actually noticed a different problem with treating storage classes as type constructors: while "ref" and "lazy" would work well, "out" would make no sense as a type constructor, so this solution probably won't work at all. Does anyone have any ideas on how to get storage classes to work correctly with ParameterTypeTuple, whether or not it's a dirty solution (so long as the solution works)?
Re: Exactly Replicating a Function's Signature?
> Is this what you're looking for?: No. :) (Though you already found this out at the end!) I was looking for some way to keep the storage classes and any other (meta)data about the parameters that may be added in the future to the library. I have a feeling this might be a very big change in how DMD handles parameters, but without this feature, perfect redirection -- which I think is possible in C++0x -- would be impossible in D. My suggestion would be that we treat "ref", "out", and "lazy" as type constructors rather than storage specifiers; that way, we could get rid of the concept of storage classes entirely, and it would unify the concept of references with other languages like C# and C++. How does this idea sound? :) (I think it's easier said than done, though...)
Re: Exactly Replicating a Function's Signature?
> In theory this has to be enough: typeof(F) F2; But in practice, I want to change the body of my function, or possibly add new parameters in the beginning or the end. Does this let me do either of these? Thank you!
Exactly Replicating a Function's Signature?
If I have an alias F that represents a function, is there any way for me to create a function func() whose signature is exactly the same as that of F? This includes parameter types, return types, and any/all storage modifiers (e.g. const, lazy, scope, etc.). Without this capability, it's impossible to perform perfect generic redirection for functions that pass arguments by reference or in a lazy fashion, right?
Re: std.container.Array/RefCounted(T) leaking memory?
> That would be bug 3516, wouldn't it? Huh... yes, it indeed would. Thanks for the link, I couldn't think of the right keywords to search for. :)
Re: std.container.Array/RefCounted(T) leaking memory?
> I find it very hard to believe that struct dtors are never called. Sorry, that part was my bad -- last time I checked, they didn't get called, but maybe my example was too complicated, since they did get called for a *simple* example. However, here's a situation in which no postblit or destructor is called whatsoever: import std.stdio; struct S { this(int dummy) { writeln("ctor"); } this(this) { writeln("postblit"); } ~this() { writeln("dtor"); } } S test(int depth) { return depth > 0 ? test(depth - 1) : S(0); } int main(string[] argv) { test(3); }
Re: __traits(getMember, ...) on instance member
Sorry, I just noticed a typo. The line saying pragma(msg, __traits(getMember, S, m)); should've said: pragma(msg, __traits(getMember, S, "m"));
__traits(getMember, ...) on instance member
Hi, Something has been confusing me, regarding passing around aliases of instance members. If I can say: struct S { int m; } pragma(msg, (S).m); How come I can't say: struct S { int m; } pragma(msg, __traits(getMember, S, m)); ? What's the difference, and what does each one mean? (I'm trying to create a MembersTuple(T) template that returns a tuple of all members, but this stumbling block is pretty much fatal to my implementation.) Thank you!
Re: std.container.Array/RefCounted(T) leaking memory?
> Tracking memory in a modern OS is not easy, and this is probably why no one wanted to make a statement on what was really happening. The issue is that the memory *is* leaking -- it's because the struct destructor is simply not getting called. If I call free() manually, the memory usage decreases normally, so it's not a measurement problem. Furthermore, this doesn't seem to be an Array(T)-related bug at all -- it seems that pretty much *any* struct with a destructor will not have its destructor called on exit. In fact, after reading the language specifications, it seems like the glossary contradicts itself: it defines Plain Old Data as referring "to a struct that [...] has no destructor. D structs are POD." By definition, if D structs were POD, then they could not have any destructors. It seems like the language contradicts itself, and the compiler only *sometimes* calls struct destructors. Any ideas? Is this a bug? And thank you for all your great responses! :)
(coff)-Implib lib from dll
Hey guys, I'm trying to connect to my mysql-server on windows. I'm using the mysql binding from http://www.steinmole.de/d/ because as I know the DDBI project doesn't support D2. I followed the instructions on the site and first created the lib file with implib with the following command: "implib libmysql.lib libmysql.dll" (without "). Next, I changed the extern(C) statement in mysql.d to extern(Windows). Now... I create a simple application with the following source: module test; pragma(lib, "libmysql.lib"); import mysql; int main(string[] args) { MYSQL* mysql; mysql = mysql_init(null); mysql_close(mysql); return 0; } I'm trying to compile the source file by using the following command: "dmd -d test.d mysql.d" (without quotas). The result is the following: test.obj(test) Error 42: Symbol Undefined _mysql_init@4 test.obj(test) Error 42: Symbol Undefined _mysql_close@4 --- errorlevel 2 I also tried "dmd -d test.d mysql.d libmysql.lib" without any success. When I remove the extern-statement from mysql.d, I get similar errors. Note... I'm using the github-version 0.2.3 which was released last week. I think my mistake is the linking because the binding works on Linux. But... not on Windows - perhaps... anyone know how what I'm doing wrong? Thanks...
Re: toDelegate() for D1
== Quote from Simen kjaeraas (simen.kja...@gmail.com)'s article > %u wrote: > > I only need something to make a void deleg() from a void func(). > This works for me: > ReturnType!( F ) delegate( ParameterTypeTuple!( F ) ) toDelegate( F )( F > fn ) { > return ( ParameterTypeTuple!( F ) args ){ return fn( args ); }; > } What am I doing wrong. I can't call the delegate twice with anything in between. void func(){ writefln("func"); } void main(){ void delegate() dg; dg = toDelegate(&func); dg(); // np //writefln(dg.ptr," ", dg.funcptr,"."); // Error: Stack Overflow @ second dg call //writefln(); // Error: Access Violation @ second dg call dg(); }
Re: Assertion failure: '!cases' on line 2620 in file 'statement.c'
== Quote from Don (nos...@nospam.com)'s article > > Yay for first time compiling dmd :) > Sorry you had to do that! Had to learn that once anyway :) Maybe I'll even be able to take a stab at fixing bugs someday..
Re: Assertion failure: '!cases' on line 2620 in file 'statement.c'
== Quote from Don (nos...@nospam.com)'s article > It's in a switch statement somewhere. > It sounds as though this is a bug which involves multiple files, so > it'll be difficult to reduce it. > If you're able to compile DMD, change this line in statement.c line 2620: > Statement *SwitchStatement::semantic(Scope *sc) > { > //printf("SwitchStatement::semantic(%p)\n", this); > tf = sc->tf; > + if (cases) error("xxx"); > assert(!cases); // ensure semantic() is only run once > and then you'll get the line number where the error is. Yay for first time compiling dmd :) > If you can provide the function which contains the switch statement, > there's a chance I could reproduce it. I've got something better.. a minimal version :) Which even crashes through bud. module main; enum E { A = 0 }; struct S{ int i; static S func( S s, E e ){ switch( e ) //<-- here { default:return s; } } static const S s_def = { 1 }; //static const S A = func(s_def, E.A ); // forward reference error + crash //static const S[1] ARR = [ E.A : func(s_def, E.A )]; // error : xxx + crash } void main(){} To test all this I switched from 1.065 to 1.066; just to make sure it hadn't been fixed already. And now my project won't compile any more even though bud+1.065 will happily do so.. bud+ 1.066 gives me the following (no crash though) Max # of fixups = 89 Max # of fixups = 4 Max # of fixups = 112 Max # of fixups = 17 Max # of fixups = 2871 Max # of fixups = 233 Max # of fixups = 138 Max # of fixups = 7 Max # of fixups = 353 Max # of fixups = 446 Max # of fixups = 5 Max # of fixups = 4117 Max # of fixups = 37 Max # of fixups = 288 Max # of fixups = 330 Max # of fixups = 338 Max # of fixups = 144 Max # of fixups = 660 Max # of fixups = 51 Max # of fixups = 4 Max # of fixups = 220 Max # of fixups = 2765 Max # of fixups = 12 Max # of fixups = 5 Max # of fixups = 5564 Max # of fixups = 2714 Internal error: backend\cgobj.c 2424 What does that mean?
Re: std.container.Array/RefCounted(T) leaking memory?
Sorry to bump this up, but is RefCounted(T) really leaking, or am I missing something? I would like to use this in my program, and I'm curious as to why no one responded, since if it's actually leaking, it would be an important issue. Thanks!
Re: Assertion failure: '!cases' on line 2620 in file 'statement.c'
== Quote from Don (nos...@nospam.com)'s article > %u wrote: > > Should I post it as a bug, even though I have no code to accompany it? > > I have no clue as to where to start my directed search for a minimal case. > Can you post the entire source code? > It's important that it be reproducible. It doesn't need to be minimal - > someone else can reduce it. I crashed it again :) Sorry, can't share the code.. I don't really have any time atm, look at it again tomorrow.
Re: toDelegate() for D1
== Quote from Simen kjaeraas (simen.kja...@gmail.com)'s article > %u wrote: > > I only need something to make a void deleg() from a void func(). > This works for me: > ReturnType!( F ) delegate( ParameterTypeTuple!( F ) ) toDelegate( F )( F > fn ) { > return ( ParameterTypeTuple!( F ) args ){ return fn( args ); }; > } I see what you did there(took me a few blinks and spec lookups): function literals default to delegates :) Thanks!!
Re: Assertion failure: '!cases' on line 2620 in file 'statement.c'
Should I post it as a bug, even though I have no code to accompany it? I have no clue as to where to start my directed search for a minimal case.
Re: interface function overloading
== Quote from Stanislav Blinov (bli...@loniir.ru)'s article > In C++ I sometimes have similar problems, especially with multiple > inheritance. Though, as Jonathan mentioned, those problems are even more > annoying because of hijacking: you don't always immediately notice them. > Long ago I've decided to always employ conversion methods for such > cases, which in D might look like this: > class C : I2{ >I1 toI1() { return this; } >I2 toI2() { return this; } > } > This unclutters the code a bit, i think: > void main(){ >func((new C).toI2()); // compare with func(cast(I2)(new C)); >C c = new C; >func(c.toI1()); // compare with(cast(I1)c); > } > The calls to conversion methods could be even shorter if they were > properties, because of omitted parens. Anyway, once I stuck to this > strategy, it never failed me. I employ this strategy as well but I thought I would like to try the overload method, just to experiment :)
Re: toDelegate() for D1
I only need something to make a void deleg() from a void func().
Assertion failure: '!cases' on line 2620 in file 'statement.c'
Assertion failure: '!cases' on line 2620 in file 'statement.c' This is what I got from trying to build my project(30+ modules) without bud.
toDelegate() for D1
is it available?
Generic method that takes in either delegate or function
Hi, Is there any way to specify a parameter as "something that can be called with parameter types A, B, C and that returns a value of type D", without caring whether it's a delegate, a function, or an object that overloads opCall? (This might require the use of templates, but I still can't figure it out...) Thank you!
Re: interface function overloading
== Quote from bearophile (bearophileh...@lycos.com)'s article > %u: > > func(cast(I2)(new C())); > That code smells a bit (http://en.wikipedia.org/wiki/Code_smell ). > Bye, > bearophile Extract the construction and you get: module main; interface I1{} interface I2 : I1{} class C : I2{ this(){} } void func(I1 i){} void func(I2 i){} void main(){ C c = new C(); func( cast(I2)c ); } What is the deeper problem in this little snippet? Or do you mean there is something wrong if you encounter this pattern. I don't think it's really that much worse than renaming one(or both) of the funcs. It forces you to cast all class:I2 objects to the func you want called, but all class:I1 objects already call the correct func. I think different named funcs is a better solution, but I don't think the cast solution exemplifies a pattern of indication to a deeper problem.
Re: interface function overloading
== 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 matches. > > > > > > module main; > > > > interface I1{} > > interface I2 : I1{} > > > > class C : I2{ > > this(){} > > } > > > > void func(I1 i){} > > void func(I2 i){} > > > > void main(){ > > func(new C()); > > } > > > Very little - if anything - in the way of overloading in D works by "best > match." It pretty much always has to be exact or implicitly convertible and be > the _only_ option which is implicitly convertible. Sometimes, it can be pretty > annoying, but it's done to avoid cases where you accidentally call one > function > when you mean another, like you can get in C++ fairly easily. > Take a look at http://www.digitalmars.com/d/2.0/hijack.html > - Jonathan M Davis I see, cast(ugly:) seems to work. func(cast(I2)(new C())); Thanks.
interface function overloading
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 matches. module main; interface I1{} interface I2 : I1{} class C : I2{ this(){} } void func(I1 i){} void func(I2 i){} void main(){ func(new C()); }
Re: std.container.Array/RefCounted(T) leaking memory?
> 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, does the memory usage double? Yes. I ran this code: { auto b = Array!(bool)(); b.length = 1024 * 1024 * 128 * 8; } { auto b = Array!(bool)(); b.length = 1024 * 1024 * 128 * 8; } and Task Manager showed two increases of 128-MB. Thank you!
std.container.Array/RefCounted(T) leaking memory?
Hi, This code seems to leak memory, as the memory isn't reclaimed: //Test memory here: low { auto b = Array!(bool)(); b.length = 1024 * 1024 * 128 * 8; //Test memory here: high } //Test memory here: high Am I missing something about how Array(T) (and RefCounted) works, or is this really a bug? Thank you!
Re: How the GC distinguishes code from data
> First, you should understand that the GC does not know what data is in a > memory block. That is exactly why I was wondering how it figures things out. :) > Data *allocated* as a void[] (which I highly recommend *not* doing) will be conservatively marked as containing pointers. Ah, all right, that clears things up! Thank you!!
Re: How the GC distinguishes code from data
> None what so ever. Huh.. then what about what is said in this link? http://d.puremagic.com/issues/show_bug.cgi?id=5326#c1 I was told that void[] could contain references, but that ubyte[] would not, and that the GC would need to scan the former but not the latter. Is that wrong? Thank you!
Re: How the GC distinguishes code from data
> Kinda sorta. I haven't had any problems from that. If you allocate very large blocks in the garbage collector you may face trouble :-) Haha okay, thanks. :) (This makes me shiver quite a bit...) > You have to add it to the garbage collector's list of roots But if I need to do that, then what would be the difference between void[] and ubyte[]?
Re: How the GC distinguishes code from data
> It assumes everything on the stack is pointers, at the moment, I believe Uh-oh... not the answer I wanted to hear, but I was half-expecting this. So doesn't that mean that, at the moment, D will leak memory? > If it's not on the garbage collected heap, it won't scan it unless you tell it to. But what if it's a void[] on a non-GC heap? Doesn't the language say that needs to be scanned too?
Re: How the GC distinguishes code from data
> If you have allocated a large uint[], most likely =C3=ACt will be flagged NO_SCAN, meaning it has no pointers in it, and the GC will ignore it. Ah, but the trouble is, no one said that this array has to be in the GC heap! I could easily have a void[] and a uint[] that both point to non-GC managed memory. Or I might even have a uint[] allocated on the stack! How does the GC distinguish these, when there's no "attribute" it can mark? (Or does it?!)
How the GC distinguishes code from data
Hi, There's a question that's been lurking in the back of my mind ever since I learned about D: How does the GC distinguish code from data when determining the objects to collect? (E.g. void[] from uint[], size_t from void*, etc.?) If I have a large uint[], it's practically guaranteed to have data that looks like pointers, and that might cause memory leaks. Furthermore, if the GC moves things around, it would corrupt my data. How is this handled? Thank you!