Trailing commas in constructor arguments?
In the following snippet is the line marked WOAH legal? The compiler doesn't complain about the trailing comma in the constructor arguments. import std.stdio; class Foo { public this(string foo) { } } void main(string[] args) { auto foo = new Foo(bar, ); // -- WOAH }
How to make sure GC allocated resources stay around when used in C functions?
Based on this conversation in another thread: http://forum.dlang.org/thread/wdddgiowaidcojbrk...@forum.dlang.org?page=5#post-yjmrqgesjtadecutvkye:40forum.dlang.org I've realised i may have a nasty bug lurking in the code. Now i want to completely understand what is happening. Take the following code: struct Args { Element element; string uniqueData; Callback callback; } class Element { void foo(Callback callback, string uniqueData = null) { auto handler = function(ClientData data) { // Use data. }; auto cleanup = function(ClientData data) { free(data); }; Args* args = cast(Args*)malloc(Args.sizeof); (*args)= Args.init; (*args).element= this; (*args).uniqueData = uniqueData; (*args).callback = callback; c_function(handler, args, cleanup); } } I want to make sure that `callback` and `uniqueData` are never cleaned up by the GC until i wish to allow them to be freed. A comment was made that in the above scenario `callback` and `uniqueData` allow the potential of being cleaned up and that a call to `GC.addRoot` might fix this problem. Would it be as simple to just add: GC.addRoot(cast(void*)args); GC.setAttr(cast(void*)args, GC.BlkAttr.NO_MOVE); to the above example? Would this not allow collection until a call to GC.removeRoot(). Or do i have to handle `callback` and `uniqueData` individually? If so how do you stop a delegate and string from being cleaned up by the GC? Any help or explanations are very much appreciated. This is the actual production code: https://github.com/nomad-software/tkd/blob/master/source/tkd/element/element.d#L172
Re: How to make sure GC allocated resources stay around when used in C functions?
On Monday, 12 May 2014 at 19:13:28 UTC, Kagamin wrote: AFAIK, addRoot is for memory allocated in GC heap, and addRange is for other types of memory, so you can't add non-gc memory as root (just a guess, see docs). I would allocate whole Args in GC heap and add is as root, yes, it would prevent collection until the root is removed. A better way would be to store Args in a linked list in the widget, this way it will be fully managed, and Args will live as long as the widget class instance references them without additional tinkering with GC. Ah yeah, i never thought, i could allocate Args on the GC heap. I have to allocate it on the fly and not store it in the widget because there could be many. I'll have a fiddle.
Re: How to make sure GC allocated resources stay around when used in C functions?
On Monday, 12 May 2014 at 20:03:46 UTC, Kagamin wrote: Why many? I'd say, you typically have 0 subscriptions (label, textbox) per widget, seldom - 1 (button, combobox, checkbox). There are many events that can be bound to on any widget. https://github.com/nomad-software/tkd/blob/master/source/tkd/element/uielement.d#L328
Re: How to make sure GC allocated resources stay around when used in C functions?
On Tuesday, 13 May 2014 at 06:27:14 UTC, Kagamin wrote: Do you always bind all of them? They are not bound automatically but may be bound later. You can bind to events such as mouse-enter, mouse-click, keypresses, etc. In fact this is how keyboard shortcuts are handled. I've added a potential fix to remove the allocation from the unmanaged heap and let the GC handle it. See what you think: https://github.com/nomad-software/tkd/commit/d77ff8603e26e7645c60b2613b996f1b21e751fc
Re: DFL is the best UIcontrols for D,compare it to dwt, tkd,dtk,dlangui,anchovy......
On Tuesday, 13 May 2014 at 20:42:11 UTC, jack death wrote: It would be cool if somebody will handle developing of DFL. It's better to have one such toolkit, than tons of complex and not finished toolkits. Tkd is finished. Gtk-D is finished. You aren't going to get very far unless you actually learn to use your tools, complex or not. Tkd is about as simple as it gets for GUI programming. Tkd-D is more complex but that's the price you pay for needing to create something more complex. isn't that the truth. as much as i like D, i find it unusable for me, since i do not have a ui-/db-toolkit. i want to use the language, not invent everything every step or fight for it. You've obviously never looked. https://github.com/gtkd-developers/GtkD https://github.com/nomad-software/tkd https://github.com/rejectedsoftware/mysql-native http://dlang.org/phobos/etc_c_sqlite3.html https://github.com/adilbaig/Tiny-Redis http://www.wikiservice.at/d/wiki.cgi?DatabaseBindings
Re: How to make sure GC allocated resources stay around when used in C functions?
On Wednesday, 14 May 2014 at 07:11:45 UTC, Kagamin wrote: It must be scanned, so you shouldn't specify NO_SCAN attribute, it's for memory blocks, which are guaranteed to not hold pointers to GC memory, like ubyte[] buffers for i/o, so managed blocks can be safely collected without looking at content of NO_SCAN blocks. Ah yes. I've completed the changes and that has cured the problems i was experiencing and fixed a nasty bug. Thanks. They are not bound automatically but may be bound later. So they will be allocated on demand - only if it's bound, Args will be allocated, Yes. so widget will have only one Args allocated, or as many as were actually bound. Or do you want to save on one pointer per widget? By default most widget have none bound until a command or binding is added. Only one command can be added to widgets that support it (e.g. buttons) but all can have many events bound if the developer so wishes. Keyboard shortcuts are probably rare too, widgets should handle most common shortcuts like text editing or copying on their own without special handling by the user program, right? They do but you are free to bind actions to more events if you wish.
Re: TKD set focus on window?
On Wednesday, 14 May 2014 at 17:08:21 UTC, Joakim wrote: Hi, Quick question regarding TKD (tkinter): Is there a way to set focus on the application window automatically on run? I'm on Mac OS X if that's of any importance. I have tried to grep the documentation but I can't find anything relevant. Thanks! class App : TkdApplication { ... this.mainWindow.raise(); // -- in UiElement this.mainWindow.focus(); // -- in UiElement ... } Window inherits from UiElement. Remember to look at the methods in the parents of each class.
Re: TKD AddProtocolCommand example
On Wednesday, 14 May 2014 at 21:41:04 UTC, DaveG wrote: Hopefully better formatting of code here: import tkd.tkdapplication; class Application : TkdApplication { private void exitCommand(CommandArgs args) { this.exit(); } private void saveMeCommand(CommandArgs args) { new MessageDialog(this.mainWindow,Saving...) .setMessage(Bye) .show(); } override protected void initInterface() { this.mainWindow.addProtocolCommand(WindowProtocol.saveYourself, this.saveMeCommand); auto frame = new Frame(2, ReliefStyle.groove) .pack(10); auto label = new Label(frame, Hello World!) .pack(10); auto exitButton = new Button(frame, Exit) .setCommand(this.exitCommand) .underlineChar(1) .pack(10); } } void main(string[] args) { auto app = new Application(); app.run(); } I'm at work at the minute I'll take a look later on.
Re: TKD AddProtocolCommand example
On Wednesday, 14 May 2014 at 21:23:02 UTC, DaveG wrote: tkd\window\window.d(426): Error: undefined identifier CommandCallback Added the missing import and now all works fine. Fixed in v1.0.5-beta. Any more issues open them up in github and i'll deal with them there. :) https://github.com/nomad-software/tkd
Re: TKD AddProtocolCommand example
On Thursday, 15 May 2014 at 19:02:58 UTC, Mengu wrote: On Thursday, 15 May 2014 at 17:30:22 UTC, Gary Willoughby wrote: On Wednesday, 14 May 2014 at 21:23:02 UTC, DaveG wrote: tkd\window\window.d(426): Error: undefined identifier CommandCallback Added the missing import and now all works fine. Fixed in v1.0.5-beta. Any more issues open them up in github and i'll deal with them there. :) https://github.com/nomad-software/tkd i just was about to send a PR :( he he, too slow. ;) If you see anything else feel free to make another.
Re: D Newbie Trying to Use D with Major C Libraries
On Thursday, 15 May 2014 at 22:25:47 UTC, Tom Browder via Digitalmars-d-learn wrote: I am a volunteer developer with the well-known 3D CAD FOSS project BRL-CAD: http://brlcad.org I have wanted to use D for a long time but I hadn't taken the plunge. Yesterday I advertised to the BRL-CAD community my new project to attempt to create D bindings for BRL-CAD's C libraries, and I created a branch for the project. I have been looking for specific information on creating D bindings from C headers for which there seems to be sufficient information available, but I would appreciate recommendations as to the best method. I have successfully built my first pure D program but now need to test the feasibility of my project. What I have not seen yet is the exact way to build a D program which uses D bindings and its matching C library. I have just created a Cookbook page on the D Wiki where I show my first attempt for a real GNU Makefile as an example for the project. The page link is here: http://wiki.dlang.org/Using_C_libraries_for_a_D_program I would appreciate it if an experienced D user would correct that recipe so it should compile the desired binary source correctly (assuming no errors in the input files). Thanks for any help. Best regards, -Tom For a start use dub to build D projects, it's becoming the de-facto build tool. http://code.dlang.org/ Then take a look at one of my projects in which i've ported C headers to D. https://github.com/nomad-software/tcltk In that repo i've included all the C headers as well as their D counterparts for reference. Converting headers is not straightforward when you first start but once you understand the rules it gets easier. Here's some helpful links: http://dlang.org/interfaceToC.html http://www.gamedev.net/page/resources/_/technical/game-programming/binding-d-to-c-r3122 http://forum.dlang.org/thread/qvjjzoxoufxnxzoky...@forum.dlang.org http://forum.dlang.org/thread/wmzqweodmbpkfjbve...@forum.dlang.org http://forum.dlang.org/thread/fzqloumcqbdvnccva...@forum.dlang.org Once the D file is created and imported into your program you just need to link the necessary library and you're good to go. See the `package.json` file in the above repository for how i do it for Posix and Windows. Windows DLL's are supplied in the `dist` directory.
Re: D Newbie Trying to Use D with Major C Libraries
On Friday, 16 May 2014 at 20:28:31 UTC, Tom Browder via Digitalmars-d-learn wrote: On Fri, May 16, 2014 at 2:31 PM, Gary Willoughby via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Friday, 16 May 2014 at 19:17:05 UTC, Dicebot wrote: Using .di is more idiomatic as those are supposed to denote declaration-only interface files (with no implementation). In practice it makes almost no difference though so many people use plain .d by habit. ... That's right. I always use .d files when porting C headers because i just see them as regular D code. I like to classify .di files as D 'headers' generated from pure D libraries (using the -H compiler switch). That's just my opinion though and to be honest i don't think it matters. :) Okay, Dicebot and Gary, that makes good sense I think, thanks. So I should use the .d for the binding source files since there will almost certainly be implementation code in them. Best, -Tom Yeah , I do and Deimos does too: https://github.com/D-Programming-Deimos
Re: Programming a Game in D? :D
On Thursday, 22 May 2014 at 15:39:36 UTC, David wrote: Hey, I'm really new to D, and pretty new to programming overall too, But I want to make a 3d Game, (just sth. small). I really like D and want to do it in D, but in the Internet there is no shit about programming a game in D ^^ Is there any engine written in D? For example the CryEngine is for C++, so I would have to write a wrapper? So, how do I write a wrapper? I would need a wrapper for DirectX too right? Are there any wrappers ore Engines for D i can use? btw. I know I dont write that in 1 day ^^ Are there any tutorials or sth. on Programming a Game in D? S I just wanna come as far to have a little Cube where i can run around on with a few phisics :) so just the startup to load a world and so on Thanks in advance :) And sry my english sucks :D First, read this: http://ddili.org/ders/d.en/index.html
Re: Passing a function as an argument to another function : what is this sorcery ?
On Sunday, 25 May 2014 at 09:37:46 UTC, Derix wrote: Hello everyone, So I'm Getting Started With Gtkd [1] and the tuto includes this piece of code : ... DrawingArea da = new DrawingArea(590, 200); da.addOnDraw(onDraw); layout.put(da, 5, 30); add(layout); // Add the layout to our main window showAll(); } bool onDraw(Context c, Widget w) { //draw things return true; } } and I'm a bit puzzled by the line da.addOnDraw(onDraw); I'm pretty sure I've met this construct before along with relevant explainations, but I find myself a bit forgetful and in need of a refresher. Hence questions : 1) What is the generic name for this kind construct ? 2) Any hint to some reading about the supporting theory or rationale ? It's basically passing an existing function via a pointer. Notice the ampersand ()? That gets the underlying memory location (i.e. pointer). Normal procedural type functions can be passed like this as can methods of classes (if you have access to them). When passing a class method like this it can be referred to as passing a delegate. Delegates internally store another pointer to it's surrounding context. For example, a function can be passed like this: void foo() { // Do something. } bar.addFoo(foo); Then in the addFoo method foo can be called as if it was a normal function. You can also write the above like this: bar.addFoo(function(){ // Do something. }); As function literals are passed via a pointer by default so no ampersand needed. The problem is that normal functions can not refer to anything outside of their scope. For this you need a delegate which contains a context pointer (which is a reference to it's surroundings). Here is an example if using a class method. class Foo { public void bar() { // Do something. } public void baz() { // Refers to bar outside of this method's scope. this.bar(); } } auto foo = new Foo(); // baz can refer to the instance of Foo (it's context) // so it can call bar. qux.addBaz(foo.baz); You can also use the literal notation too: qux.addBaz(delegate(){ // I can now use things outside this scope. }); Like function literals, delegates are also passed by their pointer by default. 3) When the onDraw function is actually called, whence does it takes its arguments from ? What is that Context ? Does it float around as some sort of implicit global object ? When was it instanciated ? When passing functions or methods like this they need to be typed just like anything else you would pass as an argument. Like this: alias void delegate(string) MyCallback; Here we define the signature of a delegate using an alias. Once a method is defined taking this alias as a type then it will only accept a delegate with this signature. class Foo { // Only accept 'void delegate(string)' void bar(MyCallback baz) { // call conforming to the MyCallback signature. baz(hello world); -- } } auto foo = new Foo(); // Passed delegate conforms to the MyCallback signature. foo.bar(delegate(string x){ writeln(x); }); Functions are typed the same way: alias void function(string) MyCallback; 4) Is onDraw a predefined event belonging to the class DrawingArea ? Is the name of the onDraw function thus constrained ? onDraw will just be a method that accepts a delegate (or standard function). 5) What is the chain of events leading to the onDraw event occuring ? I'd guess it's the 'showAll()' line, but by the way where does this 'showAll()' come from ? In the documentation I've no idea you'll have to read the source to find that out. I don't see it as a method belonging to the class DrawingArea. Is it inherited from a superclass ? Probably.
Re: TDPL - Andrei Alexandrescu
On Sunday, 25 May 2014 at 15:07:56 UTC, DLearner wrote: Does the current D specification differ from that used in the book (and, if it does, is there a link to the changes)? http://erdani.com/tdpl/errata/
Re: floating point conversion
I have a couple of functions that you may find useful for comparing floats. https://github.com/nomad-software/dunit/blob/master/source/dunit/toolkit.d#L42 https://github.com/nomad-software/dunit/blob/master/source/dunit/toolkit.d#L134
Re: '!' and naming conventions
On Wednesday, 18 June 2014 at 20:55:36 UTC, cym13 wrote: Hello, I see a lot of functions and other stuff with a '!' in the name such as 'bitfields!' or 'ctRegex!'. What does it mean exactly? I think this will be helpful: http://nomad.so/2013/07/templates-in-d-explained/
Re: dub --annotate option
On Thursday, 19 June 2014 at 17:45:56 UTC, FreeSlave wrote: Dub has option called --annotate. It's described like this: Do not perform any action, just print what would be done I supposed it's something similar to -n option of Jam build system (I really like this feature). But dub's annotate prints nothing. So what is that? I have DUB version 0.9.21 I would raise an issue here: https://github.com/D-Programming-Language/dub/issues Sönke is very prompt at replying to issues. :)
Help to find crash in simple stack type?
I've created a simple stack type using calloc/free which seems to work nicely. Then instead of using C functions i've tried to implement the same type using the GC. However i'm experiencing a crash. I've been staring at this snippet for hours now any help would be appreciated. This is a simplified snippet showing the crash: import std.stdio; import core.memory; class Stack(T) { private T* _data; private T* _pointer; private immutable size_t _minimumSize; private size_t _size; private size_t _count; public this() { this._minimumSize = 32_000; this._size = this._minimumSize; this._data = cast(T*)GC.calloc(this._size, GC.BlkAttr.NO_MOVE); this._pointer = this._data; this._pointer--; } public void push(T value) { this._pointer++; if ((this._size / T.sizeof) (this._count + 1)) { this._size *= 2; writefln(realloc to %s bytes, this._size); this._data = cast(T*)GC.realloc(this._data, this._size, GC.BlkAttr.NO_MOVE); this._pointer = (this._data + this._count); } this._count++; *this._pointer = value; } } unittest { auto stack = new Stack!(int); for (int x = 1; x = 300_000 ; x++) { stack.push(x); } } It seems to crash when the loop iteration is at about 260,000 and i've no idea why. I'm using Ubuntu 64bit latest DMD.
Re: Help to find crash in simple stack type?
On Saturday, 12 July 2014 at 17:11:00 UTC, Rainer Schuetze wrote: On 12.07.2014 19:05, Rainer Schuetze wrote: Thanks for the reduction. GC.realloc seems broken for reallocations to sizes larger than the current GC pool. Please file a bug report. Actually done that myself: https://issues.dlang.org/show_bug.cgi?id=13111 Thanks a lot guys!
Re: DStyle: Braces on same line
On Saturday, 12 July 2014 at 19:01:56 UTC, Danyal Zia wrote: Hi, I noticed that in Andrei's talks and his book, he used braces on the same line of delcaration, however Phobos and other D libraries I know use braces on their own line. Now I'm in a position where I need to take decision on coding style of my library and I get accustomed to use braces on same line but I'm worried if that would make my library less readable to other D users. Should I worry about it? Or is that's just a debatable style that won't really matter if it's persistent throughout library? Thanks Here is the 'official' style that is followed by most people including me. http://dlang.org/dstyle.html
Re: Implement Interface dynamically
On Monday, 14 July 2014 at 14:45:01 UTC, Frustrated wrote: Is there a way to take an interface and implement it generically? e.g., All functions are implemented either as throw and/or return defaults and properties are implemented as getter/setters. This is for mocking up so I a simple way to create a class based off only the interface. Essentially something similar to whitehole and blackhole except properties are useable. In fact, I suppose it would be nice to have something analogous to them except properties are implemented. Then one could do Blackhole!(Bluehole!C) where Bluehole implements properties as getters and setters. You can maybe get some ideas from this mocking code i wrote: https://github.com/nomad-software/dunit/blob/master/source/dunit/mockable.d
Re: Implement Interface dynamically
There's some handy refection stuff in there too: https://github.com/nomad-software/dunit/blob/master/source/dunit/reflection.d
Re: Really nooB question - @property
On Sunday, 20 July 2014 at 16:35:52 UTC, Eric wrote: There are a lot of discussions in the forums about how @property should or could be implemented. But I can't seem to find anything that explains why or when I should use @property with the current compiler. Can anyone explain why and when I should use the @property tag? Thx. Eric I wondered the same: http://forum.dlang.org/thread/uskutitmqgdfjeusr...@forum.dlang.org
How to copy an object to separate allocated memory?
I was reading Ali's book (http://ddili.org/ders/d.en/index.html) and saw this piece of code on how to get the true size of an object: MyClass* buffer = cast(MyClass*)GC.calloc(__traits(classInstanceSize, MyClass) * 10); That got me thinking, how would i actually 'fill' this memory with instances of that class?
Re: How to detect current executable file name?
On Monday, 18 February 2013 at 03:28:59 UTC, eGust wrote: I need to locate the directory of current executable file, but I can't find how to do that in Phobos. I tried core.runtime.Runtime.args[0], but failed. Is there a standard method of Phobos to do that? I only know the way of Windows (GetModuleFileName), but I think as a common task there should be a platform-independent way to get it in the standard library. import std.stdio; import std.file : thisExePath; import std.path : dirName; void main(string[] args) { writeln(dirName(thisExePath())); }
Preferred program config file format and parsing library?
What is the preferred format people here use for program config files? Json, Xml, ini, etc? Also what libraries exist to parse the preferred format?
Re: Preferred program config file format and parsing library?
On Sunday, 3 August 2014 at 09:31:20 UTC, Marc Schütz wrote: On Saturday, 2 August 2014 at 12:42:00 UTC, Gary Willoughby wrote: What is the preferred format people here use for program config files? Json, Xml, ini, etc? JSON is nice for data exchange, but I dislike it for configuration. It doesn't even support comments, or disabling sections of the file. YML is friendlier in this regard. DUB is considering switching from JSON to SDL: http://sdl.ikayzo.org/display/SDL/Home http://forum.rejectedsoftware.com/groups/rejectedsoftware.dub/thread/2/ Interesting, are there D libs available to parse yaml and sdl?
Re: Preferred program config file format and parsing library?
On Sunday, 3 August 2014 at 11:38:47 UTC, John Colvin wrote: On Sunday, 3 August 2014 at 10:54:10 UTC, Gary Willoughby wrote: On Sunday, 3 August 2014 at 09:31:20 UTC, Marc Schütz wrote: On Saturday, 2 August 2014 at 12:42:00 UTC, Gary Willoughby wrote: What is the preferred format people here use for program config files? Json, Xml, ini, etc? JSON is nice for data exchange, but I dislike it for configuration. It doesn't even support comments, or disabling sections of the file. YML is friendlier in this regard. DUB is considering switching from JSON to SDL: http://sdl.ikayzo.org/display/SDL/Home http://forum.rejectedsoftware.com/groups/rejectedsoftware.dub/thread/2/ Interesting, are there D libs available to parse yaml and sdl? http://code.dlang.org/packages/dyaml Great, ta.
Re: building a D app with multiple source files
On Tuesday, 5 August 2014 at 07:29:46 UTC, nikki wrote: edit : btw, I understand how to build an app that conscists out of a few source files, I'd just do 'dmd file1.d file2.d' I amtalking here about the situation where that's unpractical because of the amount and folder structure. You can take a look at the dub build tool to automate all this (as mentioned above). Dub works by compiling and linking everything together in your source folder. You specify the main entry point in a dub.json file. It's pretty easy to use and good for handling dependencies over the internet. To compile things manually you can use rdmd to automatically parse the files that need compiling. When using rdmd you only need to specify the file that contains the main function to build everything around it. for example: rdmd program.d This will pull in all imports inside program.d and compile and link them too.
Re: building a D app with multiple source files
On Tuesday, 5 August 2014 at 08:06:57 UTC, nikki wrote: edit: couldn't find that flag in dmd --help (only -Ipath), atleast I know what it does now, hope I'll remember.. thanks a lot though @ great helpful community Remember rdmd is just a program to help collect and organise parameters. It still passes everything to dmd. In fact if you use the --chatty option with rdmd it will show you everything it is doing including what it is passing to dmd.
Re: private selective imports
On Wednesday, 6 August 2014 at 18:33:23 UTC, Dicebot wrote: Most voted DMD bug : https://issues.dlang.org/show_bug.cgi?id=314 Yeah this is a famous bug that seems to catch everyone out at some stage.
What hashing algorithm is used for the D implementation of associative arrays?
What hashing algorithm is used for the D implementation of associative arrays? Where in the D source does the AA code live?
Linked list as a bidirectional range? I have some questions...
Just for a bit a fun i've implemented a simple doubly linked list and trying out some range based stuff. Whilst doing so i have some questions which you guys might be able to answer. 1. In your opinion when accessing the elements of a linked list should they yield the data stored within the nodes or the entire nodes themselves? Different languages do this differently. For example, C# yields nodes[1], Java yields data[2]. 2. Suppose when accessing my linked list, it yields data and not nodes, how do iterate in reverse? I don't want to add unnecessary methods or properties. 3. How would you implement the 'save' method of a forward range in the context of a linked list? If my understanding is correct the 'saved' range is iterated and discard, so cannot use any references to the underlying range. This might also solve question 2. [1]: http://msdn.microsoft.com/en-us/library/he2s3bh7(v=vs.110).aspx [2]: http://docs.oracle.com/javase/7/docs/api/java/util/LinkedList.html
Re: Linked list as a bidirectional range? I have some questions...
On Monday, 11 August 2014 at 18:20:51 UTC, H. S. Teoh via Digitalmars-d-learn wrote: If you make your linked list container the same thing as a range over it, then iterating over the range will empty the container as well, which generally isn't what you want. Yes but only if it's been implemented purely as an input range. I was wondering if it was implemented as a forward range. Forward ranges allow iteration without destroying the contents. I was wondering how the 'save' method of the forward range could be implemented with a linked list. If my understanding is correct this method yields a copy to iterate over and discard. It's much better to separate the container itself from ranges over the container. This then allows you to have separate container methods that return ranges of different types. That does answer it partially. This abstraction could return ranges over the nodes or items. but ultimately these have to expose the underlying data or provide a copy. (i.e. the 'save' method of forward ranges.) Also iterating in reverse (which should be possible with a doubly linked list) such ranges will have to be bidirectional ranges. These questions are all kind of inter-linked. I want to iterate forward and back through the list and if possible provide a nice public interface. It doesn't seem right to expose the nodes as that smells of a leaking abstraction. Hiding the nodes make it harder to iterate without a nice interface i.e. bidirectional range. Ranges are nice but the (forward range's) 'save' method needs careful consideration. opApply is nice but i can't see a way to overload it for reverse iteration.
Re: Linked list as a bidirectional range? I have some questions...
On Monday, 11 August 2014 at 20:02:38 UTC, H. S. Teoh via Digitalmars-d-learn wrote: On Mon, Aug 11, 2014 at 07:35:04PM +, Gary Willoughby via Digitalmars-d-learn wrote: On Monday, 11 August 2014 at 18:20:51 UTC, H. S. Teoh via Digitalmars-d-learn wrote: If you make your linked list container the same thing as a range over it, then iterating over the range will empty the container as well, which generally isn't what you want. Yes but only if it's been implemented purely as an input range. I was wondering if it was implemented as a forward range. Forward ranges allow iteration without destroying the contents. I was wondering how the 'save' method of the forward range could be implemented with a linked list. If my understanding is correct this method yields a copy to iterate over and discard. Only if you explicitly call .save when you iterate over it. The following code does NOT preserve the original range: auto fwdRange = LinkedList(...); foreach (e; fwdRange) { ... } while the following does: auto fwdRange = LinkedList(...); foreach (e; fwdRange.save) { ... } which is uglier. It's much better to separate the container itself from ranges over the container. This then allows you to have separate container methods that return ranges of different types. That does answer it partially. This abstraction could return ranges over the nodes or items. but ultimately these have to expose the underlying data or provide a copy. (i.e. the 'save' method of forward ranges.) I don't understand your objection here. You just implement your .front method to return the appropriate type. The dirty details of how iteration is implemented need not be exposed. Also iterating in reverse (which should be possible with a doubly linked list) such ranges will have to be bidirectional ranges. You could do that, but it's not necessary. Nothing stops you from implementing, say, a byDataReverse() method that returns a forward range that just happens to return items from the original list in reverse order. These questions are all kind of inter-linked. I want to iterate forward and back through the list and if possible provide a nice public interface. It doesn't seem right to expose the nodes as that smells of a leaking abstraction. Hiding the nodes make it harder to iterate without a nice interface i.e. bidirectional range. Your original question asked for a range that iterates over either data items or nodes, so what's the problem with exposing the nodes? If you didn't want the range to iterate over the nodes in the first place, then don't implement byNodes(), that's all. Ranges are nice but the (forward range's) 'save' method needs careful consideration. All you have to do in .save is to return a copy of the range, which is *not* the same thing as a copy of the container. (Again, this shows that it's a bad idea to conflate the container with a range over its elements.) opApply is nice but i can't see a way to overload it for reverse iteration. opApplyReverse. Anyway, clearly we're not understanding each other, so let me present some concrete code so that we aren't just talking past each other: // This is the container. It is NOT a range of any sort. class LinkedList(T) { private class Node { T data; Node next, prev; } Node head, tail; /** * Returns: A range over the data in the container in * forward order. */ auto byData() { // This is the range that the user will use to // iterate over the container's contents. struct Result { Node current; @property ref T front() { // N.B.: no Node object is // exposed to the public, they // only see the data. return current.data; } @property bool empty() { return current is null; } void popFront() { current = current.next; } @property Result save() { // N.B.: no copying of data // needed; no container // duplication needed. return Result(current); } } static
Re: Linked list as a bidirectional range? I have some questions...
On Monday, 11 August 2014 at 20:02:38 UTC, H. S. Teoh via Digitalmars-d-learn wrote: opApplyReverse. Was that a joke or does opApplyReverse exist?
Re: Linked list as a bidirectional range? I have some questions...
On Tuesday, 12 August 2014 at 17:00:26 UTC, ketmar via Digitalmars-d-learn wrote: On Tue, 12 Aug 2014 16:50:33 + Gary Willoughby via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Was that a joke or does opApplyReverse exist? it's not a joke. http://dlang.org/statement.html ctrl+f, opApplyReverse Ha, awesome!
Re: Linked list as a bidirectional range? I have some questions...
On Monday, 11 August 2014 at 20:02:38 UTC, H. S. Teoh via Digitalmars-d-learn wrote: Anyway, clearly we're not understanding each other, so let me present some concrete code so that we aren't just talking past each other: I've used your advice and implemented a range over the list as suggested, the problem being i cannot get it to pass the isForwardRange check. Code: http://dpaste.dzfl.pl/cad89406bbcc#line-220 You'll notice the assert on line 220 fails. Any idea what i'm doing wrong?
Re: Linked list as a bidirectional range? I have some questions...
On Wednesday, 13 August 2014 at 18:58:59 UTC, H. S. Teoh via Digitalmars-d-learn wrote: On Wed, Aug 13, 2014 at 06:31:32PM +, Gary Willoughby via Digitalmars-d-learn wrote: On Monday, 11 August 2014 at 20:02:38 UTC, H. S. Teoh via Digitalmars-d-learn wrote: Anyway, clearly we're not understanding each other, so let me present some concrete code so that we aren't just talking past each other: I've used your advice and implemented a range over the list as suggested, the problem being i cannot get it to pass the isForwardRange check. Code: http://dpaste.dzfl.pl/cad89406bbcc#line-220 You'll notice the assert on line 220 fails. Any idea what i'm doing wrong? You need to put @property on .save. T Gah! Thanks, i need sleep. :)
Re: Linked list as a bidirectional range? I have some questions...
On Wednesday, 13 August 2014 at 19:43:20 UTC, H. S. Teoh via Digitalmars-d-learn wrote: On Wed, Aug 13, 2014 at 07:37:09PM +, Gary Willoughby via Digitalmars-d-learn wrote: On Wednesday, 13 August 2014 at 18:58:59 UTC, H. S. Teoh via Digitalmars-d-learn wrote: On Wed, Aug 13, 2014 at 06:31:32PM +, Gary Willoughby via Digitalmars-d-learn wrote: [...] I've used your advice and implemented a range over the list as suggested, the problem being i cannot get it to pass the isForwardRange check. Code: http://dpaste.dzfl.pl/cad89406bbcc#line-220 You'll notice the assert on line 220 fails. Any idea what i'm doing wrong? You need to put @property on .save. T Gah! Thanks, i need sleep. :) No worries, the only reason I could pinpoint this almost immediately was because I got bitten by exactly the same problem before, and it took me *hours* to figure out what was wrong. :-/ T Thinking about it why should that matter when not compiled using -property? I'm guessing the template enforces it should be a property?
In the new D release why use free functions instead of properties?
In the new D release there have been some changes regarding built-in types. http://dlang.org/changelog.html?2.066#array_and_aa_changes I would like to learn why this has been done like this and why it is desired to be free functions rather than properties?
Re: In the new D release why use free functions instead of properties?
On Tuesday, 19 August 2014 at 00:55:24 UTC, Idan Arye wrote: On Tuesday, 19 August 2014 at 00:54:25 UTC, Idan Arye wrote: On Monday, 18 August 2014 at 21:17:11 UTC, Jonathan M Davis wrote: On Monday, 18 August 2014 at 21:02:09 UTC, Gary Willoughby wrote: In the new D release there have been some changes regarding built-in types. http://dlang.org/changelog.html?2.066#array_and_aa_changes I would like to learn why this has been done like this and why it is desired to be free functions rather than properties? Probably because they never should have been properties in the first place. Properties are supposed to emulate variables, whereas something like dup is clearly an action. So, it's clearly not supposed to be a property. However, because D doesn't require parens on a function with no arguments, you can still call it without parens. Some of the changes probably also help with cleaning up the AA internals, which is sorely needed. - Jonathan M Davis Also std.algorithm's heavy usage of passing delegates as template arguments makes it more elegant to use free functions: import std.algorithm; import std.compiler; void main() { int[][] arr=[[1,2],[3,4]]; static if (version_minor=65){ auto arr2=arr.map!(a = a.dup)(); }else{ auto arr2=arr.map!(a.dup)(); } arr2[0][0]=9; assert(arr2[0][0] == 1); } Sorry - that should have been: import std.algorithm; import std.compiler; void main() { int[][] arr=[[1,2],[3,4]]; static if (version_minor=65){ auto arr2=arr.map!(a = a.dup)(); }else{ auto arr2=arr.map!(dup)(); } arr2[0][0]=9; assert(arr2[0][0] == 1); } This kind of makes sense for `dup` because that could be applied across types but what about rehash, byKey, byValue, keys, values, etc of AA's? Surely these will only be used by AA's? Is this more about speed optimisation?
Re: How I can iterate data in structure
On Friday, 22 August 2014 at 10:44:31 UTC, Marc Schütz wrote: On Friday, 22 August 2014 at 08:44:51 UTC, Suliman wrote: foreach (field; result.tupleof) Why I should here specify type of iterable element, but not first element that I use for iteration? I mean: foreach (_some_type_possible_enum_ field; result) ? You mustn't, because your struct could have fields of different types. When you `foreach()` over a tuple, the compiler unrolls the loop body, which allows it to use a (potentially) different type on each iteration. If you don't want this, and all the fields have the same type, you can iterate over an array made from the fields: foreach (field; [result.tupleof]) { writeln(field); } Or you could implement opApply or range primitives in the struct. http://ddili.org/ders/d.en/foreach_opapply.html http://dlang.org/phobos/std_range.html
Re: Is this RDMD bug ?
On Saturday, 23 August 2014 at 16:28:46 UTC, novice2 wrote: I have 2 reduced files, wich i can't compile with new (DMD 2.066) rdmd.exe under Windows 7 32-bit. Command: rdmd --force --build-only aaa.d Message Error 42: Symbol Undefined _D3etc3bbb3fooFZi But command: dmd aaa.d etc\bbb.d Compile without errors. And then i replace rdmd.exe by old (from DMD 2.065) compile OK too. Can anybody reproduce this? /*** begin of file aaa.d ***/ import etc.bbb; void main() { int i = foo(); } /***/ /*** begin of file etc\bbb.d ***/ module etc.bbb; public int foo() { return 1; } /***/ Confirmed. If you change the module name everything works. i.e. change `etc` to something else.
Re: Is this RDMD bug ?
On Saturday, 23 August 2014 at 17:29:15 UTC, sigod wrote: PR that introduced regression: https://github.com/D-Programming-Language/tools/pull/108 Filed: https://issues.dlang.org/show_bug.cgi?id=13366
Is this a bug when creating proxies in classes?
Compiling the following code: import std.typecons; class Foo { private int foo; mixin Proxy!(foo); this(int x) { this.foo = x; } } void main() { } Produces this error: :!rdmd --force -de -debug -w test.d /usr/include/dmd/phobos/std/typecons.d(4043): Error: template instance isArray!(typeof(a)) template 'isArray' is not defined test.d(7): Error: mixin test.Foo.Proxy!(foo) error instantiating Failed: [dmd, -de, -debug, -w, -v, -o-, test.d, -I.] Can anyone else confirm or am i doing something wrong. I'm using DMD 2.066.0 64bit Ubuntu 14.04.
Re: Is this a bug when creating proxies in classes?
On Monday, 25 August 2014 at 21:14:42 UTC, Ali Çehreli wrote: On 08/25/2014 12:17 PM, Marc Schütz schue...@gmx.net wrote: On Monday, 25 August 2014 at 19:12:48 UTC, Marc Schütz wrote: On Monday, 25 August 2014 at 18:44:36 UTC, Ali Çehreli wrote: It can be explained if the mixed-in template is evaluated at the mixin context without bringing in the imported modules to that context. I don't know whether it is true or whether it is a known limitation. You're right, that's it! It works when I import std.traits first. So... the fix is to import std.traits inside template Proxy. Going to submit a PR. https://github.com/D-Programming-Language/phobos/pull/2463 Thanks! And I learned from you in the pull request the following fact: quote Quoting http://dlang.org/template-mixin : Unlike a template instantiation, a template mixin's body is evaluated within the scope where the mixin appears, not where the template declaration is defined. It is analogous to cutting and pasting the body of the template into the location of the mixin. /quote Ali With that in mind what is strange is that if in my example you change the class for a struct everything works as expected. Why is that?
Re: DIP64 - Regarding 'pure' and 'nothrow'
On Wednesday, 27 August 2014 at 13:49:48 UTC, Aerolite wrote: Hey all, I just read the wiki article on DIP64 - http://wiki.dlang.org/DIP64 The discrepancy between the annotation-style attributes such as '@safe', '@property', etc and the keyword attributes 'pure' and 'nothrow' has always really bugged me ever since I started using D. How likely is it that DIP64 will be accepted and implemented? Or, more specifically, how much does this discrepancy bother others, including Walter and Andrei? Or is the author of this DIP wrong in his assessment that 'pure' and 'nothrow' are in fact standard attributes? I bothers the heck outta my OCD. :)
Does D provide automatic dereferencing for accessing members through pointers?
This is something that has been on my mind since i discovered this the other day. Does D provide automatic dereferencing for accessing members through pointers? Here's an example: import core.stdc.stdlib : malloc, free; struct Foo { public int bar; } void main(string[] args) { auto foo = cast(Foo*)malloc(Foo.sizeof); foo.bar = 42; // Dereference the struct before accessing members. assert((*foo).bar == 42); // No dereferencing! eh? assert(foo.bar == 42); free(foo); } I've taken a look in the std lib and the second form is used a lot. Why don't you need to dereference the pointer 'foo' to reach its member 'bar'?
Re: Does D provide automatic dereferencing for accessing members through pointers?
On Wednesday, 27 August 2014 at 19:36:08 UTC, Brian Schott wrote: On Wednesday, 27 August 2014 at 19:25:42 UTC, Gary Willoughby wrote: Why don't you need to dereference the pointer 'foo' to reach its member 'bar'? The compiler inserts the dereference for you. (It knows which types are references and which are values and can do this correctly) This makes the syntax consistent between value and reference types. Awesome. Ta.
Re: Is this a bug when creating proxies in classes?
On Tuesday, 26 August 2014 at 20:41:47 UTC, Marc Schütz wrote: On Tuesday, 26 August 2014 at 18:13:52 UTC, Gary Willoughby wrote: With that in mind what is strange is that if in my example you change the class for a struct everything works as expected. Why is that? This is bizarre... I tried a few things, but I have no idea. At first I thought the `static if` that calls `isArray` is inside another `static if`, but this is not the case. Might be a compiler bug? Anyone else know or can reduce this if it's a bug?
Re: Is this a bug when creating proxies in classes?
On Thursday, 28 August 2014 at 16:23:48 UTC, anonymous wrote: On Tuesday, 26 August 2014 at 18:13:52 UTC, Gary Willoughby wrote: With that in mind what is strange is that if in my example you change the class for a struct everything works as expected. Why is that? That's because when not mixed into a class, Proxy did import std.traits: static if (!is(typeof(this) == class)) { private import std.traits; Ah right, yes. ta.
Re: D daemon GC?
On Sunday, 31 August 2014 at 09:02:55 UTC, JD wrote: Last snippet works for me, dots get printed to the logfile as expected. Ok, it works now. Using the recommended _Exit() function with DMD 2.066 on Linux. Thanks you all for your help! Best regards, Jeroen On a side note, i've created daemons like this before but then i found a rather nice posix system call to do it all for me: extern (C) { /** * The daemon() function is for programs wishing to detach themselves * from the controlling terminal and run in the background as system * daemons. * * (This function forks, and if the fork(2) succeeds, the parent calls * _exit(2), so that further errors are seen by the child only.) On * success daemon() returns zero. If an error occurs, daemon() returns * -1 and sets errno to any of the errors specified for the fork(2) and * setsid(2). * * Params: * nochdir = If nochdir is zero, daemon() changes the calling process's * current working directory to the root directory (/); otherwise, * the current working directory is left unchanged. * noclose = If noclose is zero, daemon() redirects standard input, * standard output and standard error to /dev/null; otherwise, no * changes are made to these file descriptors. */ int daemon(int nochdir, int noclose); } This is a lot easier to use. :)
Re: basic question about adresses and values in structs
On Monday, 1 September 2014 at 18:08:48 UTC, nikki wrote: so I am still very new to structs and and * adress and pointer stuff, I have this basic code : struct S { int value = 0; } void func(S thing){ writeln(thing); //BFC52B44 thing.value = 100; } S guy = {value:200}; writeln(guy); //BFC52CCC func(guy); writeln(guy.value);// this prints 200, because the adress was not the same I think I see whats going on but I don't know how to fix it? void func(ref S thing){ writeln(thing); thing.value = 100; } The ref keyword passes the variable into the function by reference, so that it is not copied.
Re: Query Parser Callstack
On Monday, 1 September 2014 at 21:00:46 UTC, Nordlöw wrote: Are there some nice traits or internals to query the current call stack for address or perhaps even their (mangled) names. I'm mostly interested in using this to detect infinite recursions in my recursive descent parser. This provided that my parser slice hasn't changed since last call to the same function. I've no idea how it is used but '_d_traceContext' might be of use: import std.stdio; int foo(int n) { writefln(foo: 0x%X, foo); writefln(%s, _d_traceContext(foo)); return n; } extern(C) Throwable.TraceInfo _d_traceContext(void* ptr = null); void main(string[] args) { auto x = foo(100); } Found in object_.d in the druntime repo.
Re: dub github dependencies?
On Thursday, 4 September 2014 at 16:43:13 UTC, evilrat wrote: how i can specify github repo branch? i've already tried adding everything i have in mind but no luck so far. so in theory it should be like this: -- dub.json dependencies: { cairod: {version: ~ReworkWin32, path: https://github.com/evilrat666/cairoD.git} } but it says missing package description, while it obviuosly there... any suggestions? i know i could use local clone but what if someone else need to use it? Packages have to exist on http://code.dlang.org/
Re: Novice web developer trying to learn D
On Sunday, 7 September 2014 at 21:06:48 UTC, zuzuleinen wrote: Hello, First, here is my Linkedin profile http://www.linkedin.com/in/andreiboar in order to make an image of my professional background. I do realise here are really good programmers for which this background might sound like a joke, but this is what I did so far. After watching some presentantions from DConf, and trying the language I decided to give it a try in the future. Currrently I'm reading the Programming in D book by Ali Çehreli, and then The D Programming Language by Andrei Alexandrescu in order to learn more. The reason I post this is to ask you what other books do you think I should try in order to become hireable in the next 2 years? As a web developer I know I lack a lot of information, but I'm willing to do the hard work. So if anyone has any other books/things I need to know and is willing to make me like a small roadmap to become a good D developer I would really appreciate. Thanks a lot, Andrei Hi and welcome. I find it great that you want to learn and grow as a developer, many web devs don't and yet still think they're awesome. Using a language like D is a complete departure from what you've been doing so far because it compiles to native code and with that brings quite a few things to learn. So where to start. First, i would take time to learn about pointers. These are pretty fundamental when dealing with native code and there's no real way of getting around that. Here's a five minute guide: http://denniskubes.com/2012/08/16/the-5-minute-guide-to-c-pointers/ After that i would probably familiarise myself with the compiler and linker: http://dlang.org/dmd-windows.html http://dlang.org/dmd-linux.html http://www.lurklurk.org/linkers/linkers.html You're already reading Ali's and Andrei's books so that's good. Try reading the phobos documentation to familiarise yourself with the library: http://dlang.org/phobos/index.html Maybe controversial but i would also consider reading the C book for a good grounding in pointers and memory allocation, etc. A lot of this is relevant in D. http://en.wikipedia.org/wiki/The_C_Programming_Language It's nice to know these basics and you'll appreciate D a whole lot more coming from C. ;) Remember to ask questions here as you go.
Re: Novice web developer trying to learn D
On Monday, 8 September 2014 at 20:58:20 UTC, ketmar via Digitalmars-d-learn wrote: On Mon, 08 Sep 2014 20:47:19 + AsmMan via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Before go to D I recomend you to take a look at the C programming language (as Gary Willoughby already mentioned). I think it's really fundamental. do you really want him to drop programming? there is no need to start with Ford Model T to drive Lamborghini Estoque. *conceptions* are fundamental, not languages. and D is much better starting point than C. i know it, i have almost two decades of C expirience. I would agree but that little C book is an amazing read and full of valuable lessons.
Re: dub can't read files from cache
On Wednesday, 17 September 2014 at 12:08:51 UTC, Kagamin wrote: Looks like an error from the compiler, non-ascii characters in file path can affect it. Try raising an issue here: https://github.com/D-Programming-Language/dub/issues
How does GC.addRange work?
How does GC.addRange work? i.e. what is it doing? I'm assuming reading the docs that it adds a range for the GC to scan but what actually happens? Does the GC look into this range and check for the existence of pointers it's currently managing? For example, if i nulled a pointer in the range i added would that trigger the GC to collect that resource on the next sweep? (assuming it was the last reference.)
Re: How does GC.addRange work?
On Saturday, 20 September 2014 at 23:08:08 UTC, ketmar via Digitalmars-d-learn wrote: On Sat, 20 Sep 2014 22:21:13 + Gary Willoughby via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: So zeroing values will inform the GC the reference has gone? yes. Thanks, i just wanted to make it clear in my mind.
Re: New changes to DDOC where is the u tag coming from in parent classes?
On Monday, 22 September 2014 at 20:44:25 UTC, Gary Willoughby wrote: Below is a change that results from re-generating my documentation using ddoc. I wonder where the new u tags are coming from that wrap the parent class name. -div class=module-membersh2a name=Button/aclass span class=symbolButton/span: tkd.widget.textwidget.TextWidget; +div class=module-membersh2a name=Button/aclass span class=symbolButton/span: utkd.widget.textwidget.TextWidget/u; Has there been a new ddoc symbol defined and not mentioned in: http://dlang.org/ddoc.html I've redefined most of these in my own .ddoc file and can't seem to get rid of the new tag. Is there a master ddoc file being read from somewhere? Any help? This has started to occur with the latest compiler release.
Re: New changes to DDOC where is the u tag coming from in parent classes?
On Tuesday, 23 September 2014 at 10:54:35 UTC, Kagamin wrote: On Monday, 22 September 2014 at 20:44:25 UTC, Gary Willoughby wrote: Is there a master ddoc file being read from somewhere? https://github.com/D-Programming-Language/dmd/blob/master/src/doc.c#L132 Thanks! I'd bet my arse it's DDOC_PSUPER_SYMBOL! I haven't seen that one before, i'll try it later.
A few questions regarding GC.malloc
A few questions regarding GC.malloc. When requesting a chunk of memory from GC.malloc am i right in assuming that this chunk is scanned for pointers to other GC resources in order to make decisions whether to collect them or not? What does BlkAttr.FINALIZE do when used in the GC.malloc call?
Re: Can I make a variable public and readonly (outside where was declared) at same time?
On Friday, 26 September 2014 at 17:16:04 UTC, AsmMan wrote: I know I can combine it by making an extra variable plus a property like this: class Foo { private int a_; void do_something1() { a_ = baa(); } void do_something2() { if(cond) a_ = baa2(); } @property int a() { return a; } } This is the C#'s to do which I'm translated to D within my limited knowledge. I don't do much OOP, maybe it's possible and I don't know. I'm using @property to make 'a' accessible and readonly at same time but I wanted to do that without this a_ extra variable, i.e, only the methods within the Foo class can assign a new value to a but a instance of Foo can't. An imaginary code example: class Foo { public MAGIC_HERE int a; void do_something1() { a = baa(); } void do_something2() { if(cond) a = baa2(); } } And then: Foo f = new Foo(); writeln(f.a); // output value of a f.a = 10; // compile error: a is readonly outside Foo's methods. I hope it's clear (sorry for por English) I think the extra variable and the properties are the way to go and it's the idiomatic way. In fact that's the reason properties are there. Saying that though, you can achieve what you want implementing a little more code using opDispatch. opDispatch intercepts calls to undefined members and deals with them, in this case forwarding to a private variable. http://dlang.org/operatoroverloading.html#dispatch
What is a sink delegate?
What is a sink delegate? Discussed here: http://forum.dlang.org/thread/m0bdgg$1t7j$1...@digitalmars.com?page=6#post-m0emvc:242av5:241:40digitalmars.com
Re: How do I check if a function got CTFE?
On Thursday, 2 October 2014 at 17:56:29 UTC, AsmMan wrote: I'd like to check if a function got CTFE, ie, the compiler was able to replace my foo(s); by the computed value at compile-time. I'm trying to convert the binary executable to assembly by using objconv tool but I'm finding it very diffucult to find anything in there, since some converters I've used which does ELF to ASM keep the function name, e.g, foo() function is a foo label somewhere in the file but this convert doesn't and use some numbers instead of. I don't know if it's related how is the windows object file format designed. You could use __ctfe http://forum.dlang.org/thread/yzioyjhiqedktswkw...@forum.dlang.org
Hunting down rogue memory allocations?
Say i have created a program written in D, what tools are available for me to track memory allocations? If you write a program and its performance is slow because you suspect too many allocations are taking place in unrecognised areas, what tools or techniques do you use to find where they are and eliminate them?
Re: Hunting down rogue memory allocations?
On Thursday, 2 October 2014 at 20:31:29 UTC, Kiith-Sa wrote: On Thursday, 2 October 2014 at 20:16:56 UTC, Gary Willoughby wrote: Say i have created a program written in D, what tools are available for me to track memory allocations? If you write a program and its performance is slow because you suspect too many allocations are taking place in unrecognised areas, what tools or techniques do you use to find where they are and eliminate them? If *time* spent by allocations is a problem, profile with `perf top` (assuming you have Linux): Look for 'gc', 'malloc', 'calloc', etc. (Plain perf record will also work, but not be as quick/interactive. CodeXL works too.) See https://perf.wiki.kernel.org/index.php/Tutorial - you probably need some specific arguments to get caller info, didn't use it for a while so I don't remember. If e.g. the GC is an issue, it should be immediately evident with some GC function taking e.g. over 5% of time. Usually the actual overhead will be much higher but divided into multiple smaller functions that will take little time individually. Drill down into one of these and look at its callers. Eliminate the most common source of calls, look again, repeat. Usually removing a source of alloc calls will result in better speedup than the profiler suggests. If *space* is a problem, Valgrind doesn't work with most D programs for some reason (probably D's fault), so, good luck with that. But eliminating the biggest time wasters usually helps space as well (or rather, it makes it more controllable as you know better where you allocate memory). Great thanks, I'll look into those.
Is there a current version of rdmd for gdc?
Is there a current version of rdmd for gdc?
Re: coding practices: include whole module or only the needed function
On Monday, 6 October 2014 at 21:24:56 UTC, AsmMan wrote: Which practice do you use: if you need only one or two functions from a module: import myModule : func, func2; or (import whole module, assuming no function name conflits of course) import myModule; any words why one over the other are welcome. I like the first one why it explicitly show why I'm importing such a module and I think (personally) it make code more easy to read/understand/maitain. Also it's very useful inside functions (local imports) where we can overload the function like in: int f(int arg) { import foo : f; return f(somethingElse, arg); } I used it recently. Be mindful of this classic bug: https://issues.dlang.org/show_bug.cgi?id=314
Re: 'write' crashes without extra window
On Wednesday, 8 October 2014 at 03:33:38 UTC, Adam D. Ruppe wrote: You could just wrap the write function in a try/catch to explicitly ignore the error. Or if the write function is there only for debug purposes you could wrap it in a debug/version block. http://ddili.org/ders/d.en/cond_comp.html
Method signature differences in core modules on dmd and gdc?
I've been recently trying GDC out to compile some D code and i'm running into the problem of differing function signatures in core modules. For example: stack.d:79: error: function core.memory.GC.calloc (ulong sz, uint ba = 0u) is not callable using argument types (ulong, BlkAttr, TypeInfo_Array) stack.d:110: error: function core.memory.GC.realloc (void* p, ulong sz, uint ba = 0u) is not callable using argument types (string*, ulong, BlkAttr, TypeInfo_Array) snip These compile fine using DMD. Anybody know what the issue is here?
Re: Method signature differences in core modules on dmd and gdc?
On Sunday, 12 October 2014 at 19:34:30 UTC, Iain Buclaw wrote: On Sunday, 12 October 2014 at 19:20:49 UTC, Gary Willoughby wrote: I've been recently trying GDC out to compile some D code and i'm running into the problem of differing function signatures in core modules. For example: stack.d:79: error: function core.memory.GC.calloc (ulong sz, uint ba = 0u) is not callable using argument types (ulong, BlkAttr, TypeInfo_Array) stack.d:110: error: function core.memory.GC.realloc (void* p, ulong sz, uint ba = 0u) is not callable using argument types (string*, ulong, BlkAttr, TypeInfo_Array) snip These compile fine using DMD. Anybody know what the issue is here? GDC is still on version 2.065. Ah right, so these methods changed recently?
Re: Recommended GUI library?
On Friday, 17 October 2014 at 16:34:04 UTC, K.K. wrote: I'm looking for suggestions for a GUI library, to create a somewhat light GUI that can also be created without too much fuss, and support for Windows Linux. The GUI I'm looking to make would be one that is just one window, with support for tabs (just like the ones in the properties page for items on Windows), and support for opening up file browsing (just normal system one is good). Then pretty much each of the tabs are just gonna be for setting up info to send to a bunch of smaller programs. Ive used Tcl/Tk with Python before, and I briefly tried out a D version, with choppy results. So what library would anyone suggest for what I'm looking to do, or which library have you taken a liking to? Thanks, for any suggestions! If you want something small and simple you could try this: https://github.com/nomad-software/tkd
Re: DDoc module description?
On Sunday, 19 October 2014 at 01:11:39 UTC, Jeremy DeHaan wrote: Although perhaps unnecessary, I added DDoc documentation to my module for a short description of the body. This showed up in the place I wanted it to be in when I built the html documentation, so I was pretty happy. (below the module name and before any module members) I then went to override the DDOC macro to set it up with the correct formatting with the rest of the site I'll be putting the documentation on. The single line documentation I had written for the module apparently does not reside in BODY, and with the new formatting, it just casts it to the bottom of the page. It now resides below the footer. Is there anything I can do to correct this? If not then I'll just say screw it and not bother, but I thought it looked pretty nice. Especially for modules that have more than one class in them. It's hard to tell what's gone wrong but i'm guessing something has been missed in your macro. For reference this is my ddoc file that i use for generating html and it works great: DDOC = !DOCTYPE HTML html head meta http-equiv=content-type content=text/html; charset=utf-8 / link type=text/css href=http://www.nomad.so/ddoc/css/theme.css; rel=stylesheet media=all / script type=text/javascript src=http://www.nomad.so/ddoc/javascript/jquery-2.0.3.min.js;/script script type=text/javascript src=http://www.nomad.so/ddoc/javascript/jquery.scrollTo.min.js;/script script type=text/javascript src=http://www.nomad.so/ddoc/javascript/index.js;/script title$(TITLE)/title /head body h1$(TITLE)/h1 $(BODY) /body /html H2 = h2$0/h2 H3 = h3$0/h3 STRONG = strong$0/strong EM = em$0/em PRE = pre$0/pre PARAM_TABLE = table class=parameter-list$0/table PARAM_ROW = $(TR $(TD $1)$(TD $2)) DDOC_DECL = $(H2 $0) DDOC_DECL_DD = div class=declaration-description$0/div DDOC_CLASS_MEMBERS = div class=class-members$0/div DDOC_SUMMARY = $(P $0) DDOC_DESCRIPTION = $(P $0) DDOC_MEMBERS = div class=members$0/div DDOC_ENUM_MEMBERS = div class=enum-members$0/div DDOC_MODULE_MEMBERS = div class=module-members$0/div DDOC_STRUCT_MEMBERS = div class=struct-members$0/div DDOC_TEMPLATE_MEMBERS = div class=template-members$0/div DDOC_SECTIONS = div class=sections$0/div DDOC_SECTION = $(P $0) DDOC_SECTION_H = $(H3 $0) DDOC_PARAMS = $(H3 Parameters)$(PARAM_TABLE $0) DDOC_PARAM_ROW = $(TR $0) DDOC_PARAM_ID = $(TD $0) DDOC_PARAM_DESC = $(TD $0) DDOC_AUTHORS = $(H3 Authors)$(P $0) DDOC_BUGS = $(H3 Bugs)$(P $0) DDOC_COPYRIGHT = $(H3 Copyright)$(P $0) DDOC_DATE = $(H3 Date)$(P $0) DDOC_DEPRECATED = $(H3 Deprecation Information)$(P $0) DDOC_EXAMPLES = $(H3 Examples)$(P $0) DDOC_HISTORY = $(H3 History)$(P $0) DDOC_LICENSE = $(H3 License)$(P $0) DDOC_RETURNS = $(H3 Return Value)$(P $0) DDOC_SEE_ALSO = $(H3 See Also)$(P $0) DDOC_STANDARDS = $(H3 Standards)$(P $0) DDOC_THROWS = $(H3 Exceptions Thrown)$(P $0) DDOC_VERSION = $(H3 Version Information)$(P $0) DDOC_PSYMBOL = span class=symbol$0/span DDOC_PSUPER_SYMBOL = span class=super-symbol$0/span DDOC_KEYWORD = $(STRONG $0) DDOC_PARAM = $0 D_CODE = $(PRE $0) D_COMMENT = span class=comment$0/span D_STRING = span class=string$0/span D_KEYWORD = span class=keyword$0/span D_PSYMBOL = span class=symbol$0/span D_PARAM = span class=parameter$0/span
Re: DDoc module description?
On Sunday, 19 October 2014 at 16:44:25 UTC, Jeremy DeHaan wrote: The problem seems to be when I do something like this. *blah.d* ///A module that contains blahblahblah. module something.blah; //Stuff goes here What will end up happening is the generated html file turns out like this: html !-- All the generated stuff here -- /html A module that contains blahblahblah. Try it using a normal comment style like this: /** * A module that contains blahblahblah. */ module something.blah; See if that compiles differently, it may be a bug with triple slash comments.
Re: DDoc module description?
On Sunday, 19 October 2014 at 17:43:51 UTC, Jeremy DeHaan wrote: That's ok though. I can live with out it. I'll look through the bugzilla site and see if I can find a bug report for this or open up a new one. On a side note, is there any way that I can redefine the DDOC macro (or any other macro) once and have it be used for every file? That was the only thing I couldn't seem to find in the documentation for it. Just add the following line to your dmd.conf file (on GNU/Linux) or sc.ini file (on Windows): DDOCFILE=file http://dlang.org/dmd-windows.html#sc-ini http://dlang.org/dmd-linux.html#dmd-conf
Re: DDoc module description?
On Monday, 20 October 2014 at 01:58:27 UTC, Jeremy DeHaan wrote: Is there no way to specify one at compile time? Also, if I were to set the DDoc file like you suggest, does it look for one locally to dmd.conf/sc.ini or to the source code? See here for full information: http://dlang.org/ddoc.html The compiler checks in various places for a valid ddoc file.
Re: Why do some language-defined attributes have @ and some not?
On Thursday, 23 October 2014 at 00:59:26 UTC, Shriramana Sharma via Digitalmars-d- I submit that the syntax for attributes should be streamlined. Shall I go and open a Bugzilla item? No need: http://wiki.dlang.org/DIP64
Re: Why do some language-defined attributes have @ and some not?
On Friday, 24 October 2014 at 15:06:25 UTC, Ola Fosheim Grøstad wrote: I agree that @-stuff is trivial, but I don't think Python sets a good example. The codebase is basically divided in two, libraries have to support both, and I think they should have changed more if going to the trouble. Yes, Python has a real problem with this. I would like to see a proper deprecation path implemented in D. I don't want my code breaking but i'm willing to accept *informed* deprecation, followed by removal. Even if this process takes place over a few years.
Re: Tagged enums why reserved words are not permitted ?
On Tuesday, 28 October 2014 at 00:51:17 UTC, Jonathan M Davis via Digitalmars-d-learn The thing that's been done in Phobos in this type of situation is to put an underscore on the end of the keyword, so you'd get enum CrudOps { read, write, delete_ } and while that may not be what you want, it's pretty much the best that you can do. - Jonathan M Davis This is also mentioned in the style guide too. http://dlang.org/dstyle.html
Re: [SDL + TKD] Seg fault from creating DirectoryDialog
On Sunday, 2 November 2014 at 12:11:23 UTC, Jack wrote: Whole error is: http://codepad.org/C2l4rUel That's not the true error. That's dub throwing an exception when trying to run the built executable. As shown here: https://github.com/D-Programming-Language/dub/blob/master/source%2Fdub%2Fgenerators%2Fbuild.d#L464 I would suggest building the application without using dub then run the program through a debugger to find the location in the source where it's actually seg-faulting. I personally use this one: http://www.affinic.com/?page_id=109.
Re: [SDL + TKD] Seg fault from creating DirectoryDialog
On Sunday, 2 November 2014 at 23:05:05 UTC, Jack wrote: On Sunday, 2 November 2014 at 17:39:46 UTC, Gary Willoughby wrote: On Sunday, 2 November 2014 at 12:11:23 UTC, Jack wrote: Whole error is: http://codepad.org/C2l4rUel That's not the true error. That's dub throwing an exception when trying to run the built executable. As shown here: https://github.com/D-Programming-Language/dub/blob/master/source%2Fdub%2Fgenerators%2Fbuild.d#L464 I would suggest building the application without using dub then run the program through a debugger to find the location in the source where it's actually seg-faulting. I personally use this one: http://www.affinic.com/?page_id=109. Thank you. I built the program using the compiler and debugged it with the C::B gui version of gdb, and it spewed out information about call stacks and things that, I confess, I have no idea what the hell it is: http://codepad.org/Bj3y6tqr and it seems to point to line 123 in tcl.d as shown here: http://picpaste.com/pics/Screenshot_from_2014-11-03_06_53_17-C6eIWp7k.1414969454.png And now, as I said before, don't know what this is exactly. Looks like a threading error somewhere. What version of Tcl/Tk are you linking against? Are you using threads in your program? Tcl/Tk can be a pain with threading as i've read. There exists thread-friendly versions as seen here: http://www.tcl.tk/doc/howto/compile.html Notice the --enable-threads switch. I don't really know what to suggest. Try reducing the program down until you've found where the issue stops happening. It may be an incompatibility with SDL?
Re: Reading unicode string with readf (%s)
On Monday, 3 November 2014 at 19:47:17 UTC, Ivan Kazmenko wrote: So, if there is an idiomatic way to read the whole file into a string which is Unicode-compatible, it would be great to learn that, too. Maybe something like this: import std.stdio; import std.array; import std.conv; string text = stdin .byLine(KeepTerminator.yes) .join() .to!(string);
Re: [SDL + TKD] Seg fault from creating DirectoryDialog
On Monday, 3 November 2014 at 22:26:14 UTC, Jack wrote: I'll try and think about this for a while Thanks for the help sir. No worries. I don't really know what else to suggest without seeing a little code. Do you have a simple full program that shows the error happening?
Re: [SDL + TKD] Seg fault from creating DirectoryDialog
On Tuesday, 4 November 2014 at 10:34:19 UTC, Jack wrote: No worries. I don't really know what else to suggest without seeing a little code. Do you have a simple full program that shows the error happening? Here's the main file: http://codepad.org/hu4r0ExB and Here's the module: http://codepad.org/ikXAzfdg Dependencies are DerelictSDL and Tkd. It's the most simple one I got that reproduces the error. Have you got a copy of the dub.json file you use?
Re: [SDL + TKD] Seg fault from creating DirectoryDialog
On Tuesday, 4 November 2014 at 18:22:49 UTC, Gary Willoughby wrote: On Tuesday, 4 November 2014 at 10:34:19 UTC, Jack wrote: No worries. I don't really know what else to suggest without seeing a little code. Do you have a simple full program that shows the error happening? Here's the main file: http://codepad.org/hu4r0ExB and Here's the module: http://codepad.org/ikXAzfdg Dependencies are DerelictSDL and Tkd. It's the most simple one I got that reproduces the error. Have you got a copy of the dub.json file you use? Ah, no matter, i've got all the libs installed and linking now.
Re: [SDL + TKD] Seg fault from creating DirectoryDialog
On Tuesday, 4 November 2014 at 10:34:19 UTC, Jack wrote: Here's the main file: http://codepad.org/hu4r0ExB and Here's the module: http://codepad.org/ikXAzfdg Dependencies are DerelictSDL and Tkd. It's the most simple one I got that reproduces the error. If you change the way SDL is initialised it works. Instead of doing: SDL_Init(SDL_INIT_EVERYTHING); do: SDL_Init(0); SDL_InitSubSystem(SDL_INIT_TIMER); SDL_InitSubSystem(SDL_INIT_AUDIO); SDL_InitSubSystem(SDL_INIT_JOYSTICK); SDL_InitSubSystem(SDL_INIT_HAPTIC); SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER); SDL_InitSubSystem(SDL_INIT_EVENTS); Initialising the following exhibits the crash. // SDL_InitSubSystem(SDL_INIT_VIDEO); So there must be an incompatibility with the video subsystem and tcl/tk.
Re: [SDL + TKD] Seg fault from creating DirectoryDialog
On Tuesday, 4 November 2014 at 23:09:33 UTC, Jack wrote: So there must be an incompatibility with the video subsystem and tcl/tk. So it seems. Thank you very much for helping me. You were a big help. Sorry i can't do more. I'm the author of Tkd and would like to get to the bottom of it.
Re: scope exception do not rise
On Wednesday, 5 November 2014 at 14:04:26 UTC, MadProgressor wrote: The scope(failure) is translated to a try catch after the satement you wann monitor. So put it before That shouldn't matter. See: http://dlang.org/exception-safe.html
Re: Delegates and C function pointers
On Saturday, 8 November 2014 at 12:23:45 UTC, Nicolas Sicard wrote: I would like to register a D delegate to a C API that takes a function pointer as a callback and a void* pointer to pass data to this callback. My solution is in http://dpaste.dzfl.pl/7d9b504b4b965. Is this code correct? Is there something simpler or already in Phobos that I have overlooked? Thanks -- Nicolas It looks very similar to what i'm doing here: https://github.com/nomad-software/tkd/blob/master/source/tkd/element/element.d#L174 I think you can simplify it though by just using a delegate member in the data struct. Like this (untested): static struct Data { void delegate() callback; } static extern(C) void adapter(void* ptr) { auto d = *(cast(Data*) ptr); d.callback() }
Re: Live without debugger?
On Sunday, 9 November 2014 at 08:26:59 UTC, Suliman wrote: I know that a lot of people are using for programming tools like Sublime. I am one of them. But if for very simple code it's ok, how to write hard code? Do you often need debugger when you are writing code? For which tasks debugger are more needed for you? I mainly use Vim for writing D code and rarely rely on a debugger nowadays because to be frank none really worked in the past with D. Recently however, D has made strides forward in GDB compatibility (thanks to Iain Buclaw, et al) and i find it works really well using a nice GUI frontend. I personally use Affinic Debugger GUI[1]. Like you say sometimes you need to use a debugger when writing 'hard' code to find where that crash is or just to follow the logic. To be honest it is a shock using any language without a debugger as i've been spoilt rotten by Visual Studio in the past but with D i manage with what i've got just fine. [1]: http://www.affinic.com/?page_id=109
Re: How to use Linux message queues?
On Friday, 14 November 2014 at 16:45:45 UTC, Sean Kelly wrote: Sounds like a module that should be in core.sys.linux. Care to submit a pull request? Yes, these are usually added when someone requires them. Neven, if you're able, submitting a pull request to druntime of the complete module would be awesome. You can see how the others are structure here: https://github.com/D-Programming-Language/druntime/tree/master/src/core/sys/posix/sys
Re: How to use Linux message queues?
On Saturday, 15 November 2014 at 00:33:02 UTC, Neven wrote: On Friday, 14 November 2014 at 16:45:45 UTC, Sean Kelly wrote: Sounds like a module that should be in core.sys.linux. Care to submit a pull request? Ok, I've tried to make a module, though since I'm a D beginner (also a student who fiddles with D for Operating system classes) could you first feedback my code? I'm unsure in few parts which I commented on. I spent some time reading manuals, reading through ipc.d for info how to do it, and reading msg.h in my distro (Linux Mint x86-64 17) includes. http://pastebin.com/xxJe2FYa Not a bad start. A little tip, use c_long and c_ulong from core.stdc.config instead of long/ulong when interfacing with C. This is because its size changes when compiled on different architectures.
Re: How to use Linux message queues?
On Saturday, 15 November 2014 at 00:33:02 UTC, Neven wrote: Ok, I've tried to make a module, though since I'm a D beginner (also a student who fiddles with D for Operating system classes) Incidentally, where are you studying? It would be nice to know where D is being taught.
Re: TKd handling of custom events
On Wednesday, 19 November 2014 at 23:44:00 UTC, univacc wrote: Hello, I am using TKd to dray my linux/windows app which works very good! I would like to add a global Hotkey to my program via the Win32 API function RegisterGlobalHotkey. Is there a possibility to access Tk's event loop so that you can Handle the WM_HOTKEY message, the WinAPI sends you? Regards, univacc I don't think this is possible in Tcl/Tk without installing an extension as discussed here: http://computer-programming-forum.com/57-tcl/c9af2b9def3914c2.htm Tkd doesn't rely on any extensions and is just using vanilla Tcl/Tk.
Re: [dub] Size of executable
On Thursday, 27 November 2014 at 09:33:49 UTC, Chris wrote: I usually use dub to create and build projects. I built one of the projects with dub and then by hand with dmd[1] passing all the files etc. Turned out that the executable built with dub was 1.4 MB whereas the one built by hand was only 807 kB. Why is that? dub compiles and links every file in the source folder whether it's used or not. Whereas with dmd or rdmd you only compile and link the files you actually use.