Re: Emacs d-mode indentation, 2 spaces to 4?
On Thursday, 5 October 2017 at 04:57:09 UTC, John Gabriele wrote: I'm using Emacs 25.2.2 with d-mode-20161022.717 on Debian Testing, and by default this mode indents by 2 spaces. Is there an easy way to configure it to use 4 spaces instead? Add below snippet to your .emacs file (add-hook 'd-mode-hook (lambda () (setq c-basic-offset 4) (setq tab-width 4)))
Re: For fun: Expressive C++ 17 Coding Challenge in D
On Wednesday, 4 October 2017 at 19:20:12 UTC, Jesse Phillips wrote: On Wednesday, 4 October 2017 at 15:26:02 UTC, Ali Çehreli wrote: On 10/04/2017 02:04 AM, Biotronic wrote: ... Hey where is the list of features used e.g: ranges, ufcs... Features used: D. But sure, added them to the gist: https://gist.github.com/Biotronic/0bc6048b880d67bfdca970453cc47cf9 Also added some more stuff to show off more D features, like unittests and @safe. -- Biotronic
Re: Andrei's "The D Programming Language" book. Up to date?
On Wednesday, 4 October 2017 at 20:49:26 UTC, John Gabriele wrote: Hi all, This is my first message to this forum. And what a pleasure it is to be here. :) I was just looking around at what D books are available. I see that Andrei's "The D Programming Language" was published in 2010. What's changed in the language, library, and community since then that I should be aware of if following along with and learning from that book? Incidentally, is a new edition is on its way any time soon? Thanks! The core language hasn't changed that much (yet some). Most of the differences from times back then are because we now have much more third-party libraries, and the implementation is much more stable. Or that's what I've heard anyway. And I think that the book is ahead of it's time, advertising features that probably only barely worked and were seldom used back then. Just what Modern c++ is known for too. That makes it feel easily three years younger than it really is. I wasn't here myself trough so I don't know for sure.
Re: Imports
On Thursday, 5 October 2017 at 00:28:32 UTC, Mike Parker wrote: On Wednesday, 4 October 2017 at 16:31:35 UTC, Jiyan wrote: [...] If you have this directory tree: - mylib -- pack1 --- a.d --- b.d pack2 - c.d [...] Thank you, i think i kinda got that :) But as i see it with sourcePaths the directories are not influencing the module names(in the directories except "source"), so "dir.sub" will just have the name "sub" is there a way around that, except naming every module like: module dir.sub;
Re: Imports
On Thursday, 5 October 2017 at 11:44:00 UTC, Jiyan wrote: [...] But as i see it with sourcePaths the directories are not influencing the module names(in the directories except "source"), so "dir.sub" will just have the name "sub" is there a way around that, except naming every module like: module dir.sub; You have to pass the parent directory of dir rather than dir itself, e.g.: - src -- dir --- sub.d dmd -Isrc Regardless, every module should have a module name at the top. There are situations where the inferred package & module names can't work.
Re: Imports
On Thursday, 5 October 2017 at 12:17:23 UTC, Mike Parker wrote: On Thursday, 5 October 2017 at 11:44:00 UTC, Jiyan wrote: [...] But as i see it with sourcePaths the directories are not influencing the module names(in the directories except "source"), so "dir.sub" will just have the name "sub" is there a way around that, except naming every module like: module dir.sub; You have to pass the parent directory of dir rather than dir itself, e.g.: - src -- dir --- sub.d dmd -Isrc Regardless, every module should have a module name at the top. There are situations where the inferred package & module names can't work. Ugh. Sorry, I mean for sourcePaths you have to pass `src` and not `dir`.
Re: Imports
On Thursday, 5 October 2017 at 12:18:57 UTC, Mike Parker wrote: Regardless, every module should have a module name at the top. There are situations where the inferred package & module names can't work. Ugh. Sorry, I mean for sourcePaths you have to pass `src` and not `dir`. And actually, now that I think about it, this is probably one of those situations where the defualt fails. So yes, you'll need a module name.
Re: Imports
On Thursday, 5 October 2017 at 12:25:27 UTC, Mike Parker wrote: And actually, now that I think about it, this is probably one of those situations where the defualt fails. So yes, you'll need a module name. Right. I had to go back and look at what I wrote in Learning D, which is the last (and only) time I played around with the default module behavior. I always use module statements (and you should too). When you import dir.sub and the compiler finds it's missing in its imported module list, it will look in for the `dir/sub.d` from the current working directory. If it doesn't find it, you get an import error. If you do this: dmd main.d ../dir/sub.d Then sub.d can have any module statement you want -- you could do this: module this.is.the.sub.module; And it wouldn't matter, as long as main.d imported this.is.the.sub.module and not dir.sub. However, if sub.d has no module statement, the compiler isn't going to infer a package. It's going to be in the default package, so it's simply `sub` and not `dir.sub`. If you import dir.sub, the compiler will still look for a subdirectory named `dir`, but it won't find it. This latter bit is your issue. dub is passing dir/sub.d to the compiler, but without a module statement the compiler treats it simply as `sub` and your `dir.sub` import fails.
learning reflection in D
https://run.dlang.io/is/8LbmzG 1) why .stringof and typeid() is equal logically and different in fact? What is difference between them? Is it that stringof compile time and typeid runtime things? Anyway wouldn't it be better they will equal both logically and literally? 2) Where do these attributes come from? I mean `pure nothrow @nogc @safe` except `@property` that I set explicitly?
Re: learning reflection in D
On Thursday, 5 October 2017 at 14:59:10 UTC, drug wrote: 1) why .stringof and typeid() is equal logically and different in fact? What is difference between them? Is it that stringof compile time and typeid runtime things? Anyway wouldn't it be better they will equal both logically and literally? stringof is a static debugging aid, just a string that kinda represents it in code. It isn't guaranteed to match anything, but should be enough that when you eyeball it it points you in the right direction... you shouldn't rely on it to be anything specific. typeid, on the other hand, is a published, documented object with methods and defined comparisons. So that's one difference. The other one is indeed compile time vs runtime: stringof is purely compile time, whereas typeid() returns a runtime object on a runtime object. To see the difference, try: Object o = new MyClass(); typeid(o); You'll see it is MyClass, but the static versions (stringof, typeof, etC) will all think of it as Object. 2) Where do these attributes come from? I mean `pure nothrow @nogc @safe` except `@property` that I set explicitly? You didn't specify a return value for those functions, which meant the compiler inferred a bunch about it. It inferred the return value and those other attributes to fill in the gap. If you gave an explicit return value `@property int` or `@property void`, then it wouldn't automatically fill stuff in anymore.
Re: learning reflection in D
05.10.2017 18:04, Adam D. Ruppe пишет: On Thursday, 5 October 2017 at 14:59:10 UTC, drug wrote: 1) why .stringof and typeid() is equal logically and different in fact? What is difference between them? Is it that stringof compile time and typeid runtime things? Anyway wouldn't it be better they will equal both logically and literally? stringof is a static debugging aid, just a string that kinda represents it in code. It isn't guaranteed to match anything, but should be enough that when you eyeball it it points you in the right direction... you shouldn't rely on it to be anything specific. typeid, on the other hand, is a published, documented object with methods and defined comparisons. So that's one difference. The other one is indeed compile time vs runtime: stringof is purely compile time, whereas typeid() returns a runtime object on a runtime object. To see the difference, try: Object o = new MyClass(); typeid(o); You'll see it is MyClass, but the static versions (stringof, typeof, etC) will all think of it as Object. 2) Where do these attributes come from? I mean `pure nothrow @nogc @safe` except `@property` that I set explicitly? You didn't specify a return value for those functions, which meant the compiler inferred a bunch about it. It inferred the return value and those other attributes to fill in the gap. If you gave an explicit return value `@property int` or `@property void`, then it wouldn't automatically fill stuff in anymore. Thank you, Adam!
Fun project (after a day of studying euclidean geometry) in Dlang
So I really felt like doing something in D today and decided to write a database engine. I am still working on the scheme/protocol/format for the database files (which is going well) (so far 111 lines of code in the `database.d` module). Next will be to finish the Database class up in said module (which I am doing now, only method is void addKey(string keyName, string type)). After that is done I will be adding more methods to make this database more useful (and actually have methods to assign data into it). I am going to probably add the networking tonight. I will post a link to it somewhere. Beware this is my first bigg-ish program in D. You will probably laugh at some of the things I did. Sadly it has nothing to do with Euclidean Geometry (maybe next time!).
Re: Sockets and the Promiscous Mode
On 2017/09/30 17:17, fichtknick wrote: Hello all only for learning purposes and my interest for deeper network programming. I wanted to write a program and filter the entire traffic in my network. I have a server and various computers in my network, but I dont know, as I in D the promiscous mode for sockets can switch on. Is this possible in D ? I dont want back to C and in Rust.. Rust :) I Love to write some Code in D, its a beautyful language. And so sorry for my english, i understand good, but to write english, i must more learn :) happy greetings fichtknick Hopefully I helped in someway. I do not know the method of doing low-level networking like looking at layer 2 (specifically ethernet) traffic. Godspeed.
Re: Sockets and the Promiscous Mode
On 2017/09/30 17:17, fichtknick wrote: Hello all only for learning purposes and my interest for deeper network programming. I wanted to write a program and filter the entire traffic in my network. I have a server and various computers in my network, but I dont know, as I in D the promiscous mode for sockets can switch on. Is this possible in D ? I dont want back to C and in Rust.. Rust :) I Love to write some Code in D, its a beautyful language. And so sorry for my english, i understand good, but to write english, i must more learn :) happy greetings fichtknick D is a good language.
Re: Sockets and the Promiscous Mode
On 2017/09/30 17:17, fichtknick wrote: Hello all only for learning purposes and my interest for deeper network programming. I wanted to write a program and filter the entire traffic in my network. I have a server and various computers in my network, but I dont know, as I in D the promiscous mode for sockets can switch on. Is this possible in D ? I dont want back to C and in Rust.. Rust :) I Love to write some Code in D, its a beautyful language. And so sorry for my english, i understand good, but to write english, i must more learn :) happy greetings fichtknick Promiscuous mode works on the layer 2 layer. In most cases this would be ethernet. With it on you would be able to see all ethernet frames (with payloads in them, like IP packets). This includes those not destined to your computer (by it's MAC address (a.k.a. hardware address)). Promiscuous mode only works if you are using a hub (or a switch that you can control) as hubs simply bit replicate all incoming frames to all other ports hence computers will even receive ethernet frames not intended for them. Hubs are not common these days as a switch actually sends etheret frames to the correct hosts (after its dictionary is fully built) but WiFi (because the electro-megnetic radiation goes everywhere (all devices receive the ethernet frames) and hence it is a hub. Anyway, networking is not my strongest point (I am studying it too currently). From what I know Dlang only allows one to use layer 3 protocols (like IP).
Re: Fun project (after a day of studying euclidean geometry) in Dlang
On Thursday, 5 October 2017 at 16:00:52 UTC, Tristan B. Kildaire wrote: link to it somewhere. Beware this is my first bigg-ish program in D. You will probably laugh at some of the things I did. Sadly it has nothing to do with Euclidean Geometry (maybe next time!). Will post a link as soon as I get more stuff done.
Re: Emacs d-mode indentation, 2 spaces to 4?
On Thursday, 5 October 2017 at 08:49:30 UTC, Aravinda VK wrote: On Thursday, 5 October 2017 at 04:57:09 UTC, John Gabriele wrote: I'm using Emacs 25.2.2 with d-mode-20161022.717 on Debian Testing, and by default this mode indents by 2 spaces. Is there an easy way to configure it to use 4 spaces instead? Add below snippet to your .emacs file (add-hook 'd-mode-hook (lambda () (setq c-basic-offset 4) (setq tab-width 4))) That did it! Thanks, Aravinda!
Re: Emacs d-mode indentation, 2 spaces to 4?
On Thursday, 5 October 2017 at 05:22:16 UTC, Ali Çehreli wrote: On 10/04/2017 09:57 PM, John Gabriele wrote: I'm using Emacs 25.2.2 with d-mode-20161022.717 on Debian Testing, and by default this mode indents by 2 spaces. Is there an easy way to configure it to use 4 spaces instead? I can't imagine it has its own tab width. d-mode is based on cc-mode. Setting the tab width in that mode or in general should work for d-mode as well. Just research tab width for Emacs. If nothing else works and you're happy with a global tab-width of 4, add this to your .emacs file: (setq-default tab-width 4) Ali Thank you, but tried this and it didn't work. Aravinda's solution worked though.
Re: Fun project (after a day of studying euclidean geometry) in Dlang
On 2017/10/05 18:21, Tristan B. Kildaire wrote: On Thursday, 5 October 2017 at 16:00:52 UTC, Tristan B. Kildaire wrote: link to it somewhere. Beware this is my first bigg-ish program in D. You will probably laugh at some of the things I did. Sadly it has nothing to do with Euclidean Geometry (maybe next time!). Will post a link as soon as I get more stuff done. If I have learned something about working with MSYS64 it is, DON'T. That console gets the text muddled up so badly that they appear in sometime what looks like reverse order. Always debug program via PowerShell or cmd (I like the former way more though). Coding using nano via MSYS64 is fine though.
Re: Fun project (after a day of studying euclidean geometry) in Dlang
On Thursday, 5 October 2017 at 17:49:00 UTC, Tristan B. Kildaire wrote: On 2017/10/05 18:21, Tristan B. Kildaire wrote: On Thursday, 5 October 2017 at 16:00:52 UTC, Tristan B. Kildaire wrote: link to it somewhere. Beware this is my first bigg-ish program in D. You will probably laugh at some of the things I did. Sadly it has nothing to do with Euclidean Geometry (maybe next time!). Will post a link as soon as I get more stuff done. If I have learned something about working with MSYS64 it is, DON'T. That console gets the text muddled up so badly that they appear in sometime what looks like reverse order. Always debug program via PowerShell or cmd (I like the former way more though). Coding using nano via MSYS64 is fine though. I'm still going to work on this tommrow after my studying. Then the commits will be rolling in again. Here are the links (the client is no where near usable): VioletDB: https://github.com/deavmi/VioletDB VioletClient: https://github.com/deavmi/VioletClient
Create uninitialized dynamic array
Hello! Preface: I need 1G array of ints (or anything else). Problem: I want to quickly fill it with my own data and I do not want to waste CPU time to fill it with zeros (or some other value). I do like this: void main() { int[] data; // key code: data.length = SOMETHING; // how to create an array and leave it uninitialized? // fill 'data' with some data foreach(i, ref v; data) v=i; // an example } Is there a pure way to make what I want?
Re: Andrei's "The D Programming Language" book. Up to date?
On Wednesday, 4 October 2017 at 20:49:26 UTC, John Gabriele wrote: Hi all, This is my first message to this forum. And what a pleasure it is to be here. :) I was just looking around at what D books are available. I see that Andrei's "The D Programming Language" was published in 2010. What's changed in the language, library, and community since then that I should be aware of if following along with and learning from that book? Incidentally, is a new edition is on its way any time soon? Thanks! I can only recommend his book. You get a "second-hand" insight into all decisions of D2 and Andrei's writing style is very vivid, so one can barely stop reading the book. In case you are interested on the list of things that have changed, there's http://erdani.com/tdpl/errata (it's mostly just typos though).
Re: Create uninitialized dynamic array
On Thursday, 5 October 2017 at 19:59:48 UTC, Igor Shirkalin wrote: I want to quickly fill it with my own data and I do not want to waste CPU time to fill it with zeros (or some other value). You could always just allocate it yourself. Something that large is liable to be accidentally pinned by the GC anyway, so I suggest: int[] data; int* dataptr = cast(int*) malloc(SOMETHING * int.sizeof); if(dataptr is null) throw new Exception("malloc failed"); scope(exit) free(dataptr); data = dataptr[0 .. SOMETHING]; // work with data normally here Just keep in mind it is freed at scope exit there, so don't escape slices into it.
Re: Looking for a mentor in D
On Tuesday, 3 October 2017 at 06:54:01 UTC, eastanon wrote: I have been reading the D forums for a while and following on its amazing progress for a long time. Over time I have even written some basic D programs for myself, nothing major or earth shuttering. I have downloaded and read Ali's excellent book. [...] Let's try to combine D, Python and programming at isems...@gmail.com
Re: Create uninitialized dynamic array
On Thursday, 5 October 2017 at 20:19:15 UTC, Adam D. Ruppe wrote: On Thursday, 5 October 2017 at 19:59:48 UTC, Igor Shirkalin wrote: I want to quickly fill it with my own data and I do not want to waste CPU time to fill it with zeros (or some other value). You could always just allocate it yourself. Something that large is liable to be accidentally pinned by the GC anyway, so I suggest: int[] data; int* dataptr = cast(int*) malloc(SOMETHING * int.sizeof); if(dataptr is null) throw new Exception("malloc failed"); scope(exit) free(dataptr); data = dataptr[0 .. SOMETHING]; // work with data normally here Just keep in mind it is freed at scope exit there, so don't escape slices into it. Thank you, Adam, for pinpoint answer. Doesn't it mean we have to avoid GC for such large blocks? And what if we need a lot blocks with less sizes? I'm from C++ world but... I like GC. Usually the block(s) is scoped with some more complex way, so it is good to pass it to GC for management. Maybe (say LDC) compiler can reject this unuseful initialization on simplest cases. Shortly, I'm still in doubt.
Re: Create uninitialized dynamic array
On Thursday, 5 October 2017 at 20:52:00 UTC, Igor Shirkalin wrote: Doesn't it mean we have to avoid GC for such large blocks? And what if we need a lot blocks with less sizes? No, it can work, especially if you are on 64 bit. Just if it is trivial I'd malloc it, but if the lifetime is nontrivial, sure, GC it. The GC.malloc function from `import core.memory;` works just like malloc, except the garbage collector is aware of it and will collect eventually: http://dpldocs.info/experimental-docs/core.memory.GC.malloc.html int[] data = (cast(int*) GC.malloc(SOMETHING * int.sizeof, 0, typeid(int)))[0 .. SOMETHING]; Note that `typeid` returns the TypeInfo for that type, so you can pass it there. Then the GC will collect if you like. Usually the block(s) is scoped with some more complex way, so it is good to pass it to GC for management. Yeah, that's good too.
Re: Create uninitialized dynamic array
On Thursday, 5 October 2017 at 19:59:48 UTC, Igor Shirkalin wrote: Is there a pure way to make what I want? oh i almost forgot about this function too: http://dpldocs.info/experimental-docs/std.array.uninitializedArray.1.html import std.array; double[] arr = uninitializedArray!(double[])(100);
Re: Create uninitialized dynamic array
On Thursday, 5 October 2017 at 21:04:30 UTC, Adam D. Ruppe wrote: On Thursday, 5 October 2017 at 19:59:48 UTC, Igor Shirkalin wrote: Is there a pure way to make what I want? oh i almost forgot about this function too: http://dpldocs.info/experimental-docs/std.array.uninitializedArray.1.html import std.array; double[] arr = uninitializedArray!(double[])(100); Ha! I saw it some day and forgot too! And GC.malloc is, I think, what I need. Thank you!
Infuriating DUB/DMD build bug.
I've got a github project and using DUB with DMD and I keep running into this problem. I've tried deleting the entire ...\AppData\Roaming\dub\packages folder, but the problem repeats the very next build attempt. Fetching derelict-util 2.0.6 (getting selected version)... Fetching derelict-ft 1.1.3 (getting selected version)... Fetching derelict-gl3 1.0.23 (getting selected version)... Fetching derelict-assimp3 1.3.0 (getting selected version)... Fetching gl3n 1.3.1 (getting selected version)... Fetching derelict-al 1.0.3 (getting selected version)... Fetching derelict-fmod 2.0.4 (getting selected version)... Fetching derelict-fi 2.0.3 (getting selected version)... Fetching derelict-glfw3 3.1.3 (getting selected version)... Performing "$DFLAGS" build using dmd for x86_64. derelict-util 2.0.6: building configuration "library"... derelict-al 1.0.3: building configuration "library"... derelict-assimp3 1.3.0: building configuration "library"... derelict-fi 2.0.3: building configuration "library"... derelict-fmod 2.0.4: building configuration "library"... derelict-ft 1.1.3: building configuration "library"... derelict-gl3 1.0.23: building configuration "library"... derelict-glfw3 3.1.3: building configuration "derelict-glfw3-dynamic"... Error: Error writing file '..\..\..\..\AppData\Roaming\dub\packages\derelict-glfw3-3.1.3\derelict-glfw3\.dub\build\derelict-glfw3-dynamic-$DFLAGS-windows-x86_64-dmd_2076-A09416BA47731198A57C73719DAAFE33\DerelictGLFW3.lib' dmd failed with exit code 1. I've cloned DMD and when I searched for "Error writing file" all it pulls up is: /** * Writes a file, terminate the program on error * * Params: * loc = The line number information from where the call originates * f = a `ddmd.root.file.File` handle to write */ extern (C++) void writeFile(Loc loc, File* f) { if (f.write()) { error(loc, "Error writing file '%s'", f.name.toChars()); fatal(); } } But shouldn't there be a line number before "Error writing file"? With writing files, that's usually a permissions thing? But all the other 8 packages build fine? Note: I had a similar problem with derelict-assimp3 package, so I went to an entirely different system and cloned my project. But now it fails with the same error, but with a different package.
Re: Imports
On Thursday, 5 October 2017 at 12:35:26 UTC, Mike Parker wrote: On Thursday, 5 October 2017 at 12:25:27 UTC, Mike Parker wrote: [...] Right. I had to go back and look at what I wrote in Learning D, which is the last (and only) time I played around with the default module behavior. I always use module statements (and you should too). [...] Thank you :) PS: is it spam to say thank you?
Re: Imports
On 10/05/2017 03:34 PM, Jiyan wrote: > PS: is it spam to say thank you? Thank you for asking! :p I used to have strong feelings about this in the past. I still think it's spam; I don't expect any thanks from anyone and I think gratitude should be implied. Some people have different opinions: They say it makes them happy to see an explicit gratitude. I don't care anymore especially because it's not very common anyway. Ali