Re: Fully-qualified symbol disambiguation is deprecated???
On Thursday, September 08, 2016 18:26:40 Nick Sabalausky via Digitalmars-d- learn wrote: > On 09/08/2016 06:22 PM, Nick Sabalausky wrote: > > On 09/08/2016 06:13 PM, Steven Schveighoffer wrote: > >> And > >> there are still some straggling bugs which cause this message to be > >> erroneously printed. > > > > I'm pretty sure I've hit one of those :( Can't be certain though until I > > examine my specific case further. > > Oh, although the whole "selective imports don't import the FQN" is a big > surprise to me. I think at least some of the messages I hit were from > that. (Can't say I'm a big fan of that particular one, but meh, whatever...) Yeah. I _really_ don't like that part, but unfortunately, we're stuck with it. - Jonathan M Davis
Re: D1: zlib string to decode
On Thursday, 8 September 2016 at 16:19:44 UTC, jicman wrote: I have a zlib string that I want to decode. Anybody has any idea how to do that? I am trying to figure out what to send with a POST to create a new internal log and the person that created the form is no longer available, but I need to find what are the pieces and data that I need to compress. I've done something similar years ago using AHK, where I compressed using zlib, then turned it to base64 so I could post it and pass it around as text. Still simply using the zlib API should be enough, especially if you provide all the memory management or fixed buffers of what you expect the data to fit in. If you just need to decompress one string (that's a file or stream), you can prepend a header and then use gzip to decompress it.
Re: Fully-qualified symbol disambiguation is deprecated???
On 09/08/2016 03:22 PM, Nick Sabalausky wrote: On 09/08/2016 06:13 PM, Steven Schveighoffer wrote: On 9/8/16 6:02 PM, Nick Sabalausky wrote: I'm getting deprecation messages ("Package...not accessible here, perhaps add static import") when simply trying to use fully-qualified symbol names to disambiguate a symbol. Is this really intended? Yes. It's difficult to attribute the message without context, though. Yea, unfortunately I don't have it narrowed down to a test case, atm. And there are still some straggling bugs which cause this message to be erroneously printed. I'm pretty sure I've hit one of those :( Can't be certain though until I examine my specific case further. Do you have __traits(allMembers) and __traits(getMember) in your code? There is this bug (fix of which caused other trouble and controversy :) ): https://issues.dlang.org/show_bug.cgi?id=15907 Ali
Re: Fully-qualified symbol disambiguation is deprecated???
On 09/08/2016 06:22 PM, Nick Sabalausky wrote: On 09/08/2016 06:13 PM, Steven Schveighoffer wrote: And there are still some straggling bugs which cause this message to be erroneously printed. I'm pretty sure I've hit one of those :( Can't be certain though until I examine my specific case further. Oh, although the whole "selective imports don't import the FQN" is a big surprise to me. I think at least some of the messages I hit were from that. (Can't say I'm a big fan of that particular one, but meh, whatever...)
Re: Fully-qualified symbol disambiguation is deprecated???
On 09/08/2016 06:13 PM, Steven Schveighoffer wrote: On 9/8/16 6:02 PM, Nick Sabalausky wrote: I'm getting deprecation messages ("Package...not accessible here, perhaps add static import") when simply trying to use fully-qualified symbol names to disambiguate a symbol. Is this really intended? Yes. It's difficult to attribute the message without context, though. Yea, unfortunately I don't have it narrowed down to a test case, atm. And there are still some straggling bugs which cause this message to be erroneously printed. I'm pretty sure I've hit one of those :( Can't be certain though until I examine my specific case further.
Re: Fully-qualified symbol disambiguation is deprecated???
On 9/8/16 6:13 PM, Steven Schveighoffer wrote: On 9/8/16 6:02 PM, Nick Sabalausky wrote: I'm getting deprecation messages ("Package...not accessible here, perhaps add static import") when simply trying to use fully-qualified symbol names to disambiguate a symbol. Is this really intended? Yes. I should amend this emphatic reply to say "in certain cases". FQN is still supported. But many times, you aren't actually importing a symbol when you thought you were (and it just worked). -Steve
Re: Fully-qualified symbol disambiguation is deprecated???
On 9/8/16 6:02 PM, Nick Sabalausky wrote: I'm getting deprecation messages ("Package...not accessible here, perhaps add static import") when simply trying to use fully-qualified symbol names to disambiguate a symbol. Is this really intended? Yes. It's difficult to attribute the message without context, though. And there are still some straggling bugs which cause this message to be erroneously printed. I posted an article on this: http://www.schveiguy.com/blog/2016/03/import-changes-in-d-2-071/ -Steve
Re: Fully-qualified symbol disambiguation is deprecated???
On 09/08/2016 03:02 PM, Nick Sabalausky wrote: I'm getting deprecation messages ("Package...not accessible here, perhaps add static import") when simply trying to use fully-qualified symbol names to disambiguate a symbol. Is this really intended? Sounds like the recent changes in 2.071: http://www.schveiguy.com/blog/2016/03/import-changes-in-d-2-071/ Ali
Fully-qualified symbol disambiguation is deprecated???
I'm getting deprecation messages ("Package...not accessible here, perhaps add static import") when simply trying to use fully-qualified symbol names to disambiguate a symbol. Is this really intended?
Re: VisualD core.exception.RangeError@pipedmd(286): Range violation
On Thursday, 8 September 2016 at 19:56:45 UTC, Rainer Schuetze wrote: I think I fixed both issues in this build: https://ci.appveyor.com/project/rainers/visuald/build/1.0.76/job/kq0a5bqpy7anou46/artifacts Well that was fast :) It does appear to be fixed on my machine, thanks a lot for the help.
Re: Generate unique members with recursive mixins or another solution?
On 09/08/2016 02:55 AM, ilariel wrote: Is it possible to generate unique fields and members with recursive template mixins? I don't fully understand the question but my answer is yes, D can do this as well. :p Ali
Re: VisualD core.exception.RangeError@pipedmd(286): Range violation
On 08.09.2016 20:15, Rainer Schuetze wrote: On 08.09.2016 19:35, Tofu Ninja wrote: On Thursday, 8 September 2016 at 07:45:56 UTC, Rainer Schuetze wrote: Fixed it again. You can find a prebuilt binary of pipedmd.exe here: https://ci.appveyor.com/project/rainers/visuald/build/1.0.75/job/n9tf67jxcir6kpmg/artifacts Thanks for the response, I think there is more going on than that bug. The pipedmd that you linked did the same thing that mine did when I got rid of the rangeerror@pipedmd(285). Pipedmd just locks up and never finishes the build. Here is the project that gives me the problem, don't have something smaller that demonstrates it. https://www.dropbox.com/s/awtweclzl9kdm53/DGraphics.7z?dl=0 dub 1.0.0 dmd v2.071.0 visuald v0.3.44 beta 1 Generate the visuald project with "dub generate visuald -ax86_64", the project itself only builds in x64. Also fun fact, I get a different error if the folder that project is in has spaces in the path... so yeah... Thanks for the repro case. I can reproduce the lock-up with that project. You can disable the usage of pipedmd by unchecking both "demangle names in link errors" and "monitor linker dependencies" on the global options page "Project and Solutions -> Visual D Settings" which reveals that the command line is cut short. This seems to happen for the "Separate compile and link" compilation mode in the project configuration. If you switch to "Combined compile and link" it links successfully, even with pipedmd enabled. I think I fixed both issues in this build: https://ci.appveyor.com/project/rainers/visuald/build/1.0.76/job/kq0a5bqpy7anou46/artifacts
Re: VisualD core.exception.RangeError@pipedmd(286): Range violation
On 08.09.2016 19:35, Tofu Ninja wrote: On Thursday, 8 September 2016 at 07:45:56 UTC, Rainer Schuetze wrote: Fixed it again. You can find a prebuilt binary of pipedmd.exe here: https://ci.appveyor.com/project/rainers/visuald/build/1.0.75/job/n9tf67jxcir6kpmg/artifacts Thanks for the response, I think there is more going on than that bug. The pipedmd that you linked did the same thing that mine did when I got rid of the rangeerror@pipedmd(285). Pipedmd just locks up and never finishes the build. Here is the project that gives me the problem, don't have something smaller that demonstrates it. https://www.dropbox.com/s/awtweclzl9kdm53/DGraphics.7z?dl=0 dub 1.0.0 dmd v2.071.0 visuald v0.3.44 beta 1 Generate the visuald project with "dub generate visuald -ax86_64", the project itself only builds in x64. Also fun fact, I get a different error if the folder that project is in has spaces in the path... so yeah... Thanks for the repro case. I can reproduce the lock-up with that project. You can disable the usage of pipedmd by unchecking both "demangle names in link errors" and "monitor linker dependencies" on the global options page "Project and Solutions -> Visual D Settings" which reveals that the command line is cut short. This seems to happen for the "Separate compile and link" compilation mode in the project configuration. If you switch to "Combined compile and link" it links successfully, even with pipedmd enabled.
Re: VisualD core.exception.RangeError@pipedmd(286): Range violation
On Thursday, 8 September 2016 at 07:45:56 UTC, Rainer Schuetze wrote: Fixed it again. You can find a prebuilt binary of pipedmd.exe here: https://ci.appveyor.com/project/rainers/visuald/build/1.0.75/job/n9tf67jxcir6kpmg/artifacts Thanks for the response, I think there is more going on than that bug. The pipedmd that you linked did the same thing that mine did when I got rid of the rangeerror@pipedmd(285). Pipedmd just locks up and never finishes the build. Here is the project that gives me the problem, don't have something smaller that demonstrates it. https://www.dropbox.com/s/awtweclzl9kdm53/DGraphics.7z?dl=0 dub 1.0.0 dmd v2.071.0 visuald v0.3.44 beta 1 Generate the visuald project with "dub generate visuald -ax86_64", the project itself only builds in x64. Also fun fact, I get a different error if the folder that project is in has spaces in the path... so yeah...
D1: zlib string to decode
Hi. I have a zlib string that I want to decode. Anybody has any idea how to do that? I am trying to figure out what to send with a POST to create a new internal log and the person that created the form is no longer available, but I need to find what are the pieces and data that I need to compress. Thanks for your help. josé
Re: Templates problem
On Thursday, 8 September 2016 at 10:20:42 UTC, Russel Winder wrote: On Wed, 2016-09-07 at 20:29 +, deXtoRious via Digitalmars-d-learn wrote: […] More to the general point of the discussion, I find that most scientifically minded users of Python already appreciate some of the inherent advantages of lower level statically typed languages and often rather write C/C++ code than descend into the likes of Cython. D has considerable advantages over C++ in conciseness and template facilities for achieving zero cost static polymorphism without descending into utter unreadability. Personally, I find myself still forced to write most of my non-Julia high performance code in C++ due to the available libraries and GPGPU support (especially CUDA), but in terms of language properties I'd much rather be writing D. Or Chapel. It's very early days for Chapel at the moment, but I don't really see it as being remotely comparable to D or even Julia, it's much closer to a DSL than a general purpose language. That's by no means a bad thing, it seems like it could be a very useful tool in a few years, but it's never going to completely substitute for the likes of Python, C++ or D even for purely scientific programming. I'm also a bit concerned about how limited the compile time facilities seem there at the moment, but I guess we'll just have to wait and see how it develops over the next couple of years.
Re: UFCS not working with alias
On Thursday, 8 September 2016 at 13:38:54 UTC, Steven Schveighoffer wrote: There is a workaround, identified by Vladimir Panteleev (https://blog.thecybershadow.net/2015/04/28/the-amazing-template-that-does-nothing/): import std.algorithm; bool fulfillsKeyPredicate(string s, string t) {return true;} alias I(alias x) = x; void main(string[] args) { alias keyPredicateFilter = filter!(e => e.fulfillsKeyPredicate(args[0])); string[] arr; keyPredicateFilter(arr); arr.I!keyPredicateFilter; } Unfortunately, you can't alias the I!someSymbol, as that has the same problem. -Steve Thanks for this insight. In my case I prepare a presentation about D (audience doesn't now anything about D) and tried to make my D code as beautiful as possible. As solution I created now a free template method and hide it in a library module. T[] filterByKeyPredicate(T)(T[] arr, string[string] keyPredicate) { ...filter! } This way I can use UFCS. Kind regards André
Re: Functions, nothrow and assert
On Thu, Sep 08, 2016 at 12:07:43PM +, Lodovico Giaretta via Digitalmars-d-learn wrote: [...] > To expand on the previous correct answers, nothrow is about not > throwing Exceptions. Exceptions are part of the normal flow of the > program: they are used to signal recoverable errors, much like error > codes. Yes. > Errors, on the other hand, are unrecoverable system failures that > should not be catched (catching them is undefined behaviour, I think) > and will surely lead to a crash. Errors are not covered by nothrow. [...] Yes. Well, you *can* catch Errors, but the program may not be in a consistent state, as dtors and such may not have been invoked, so what you can do in the catch block should generally be limited to spitting out an error message or writing to an error log (though it's arguable whether it's a good idea to open files at this point!), then aborting the program ASAP. It's probably a bad idea to write out data to data files, as the data may be in a corrupted state at that point. Continuing after catching an Error is Undefined Behaviour. T -- Those who don't understand Unix are condemned to reinvent it, poorly.
Re: Templates problem
On Thursday, 8 September 2016 at 10:18:36 UTC, Russel Winder wrote: I am certainly hoping that Chapel will be the language to displace NumPy for serious computation in the Python-sphere. Given it's foundation in the PGAS model, it has all the parallelism needs, both cluster and local, built in. Given Chapel there is no need to look at C++, D, Rust, Cython, etc. I can see where you are coming from, I have taken a look at Chapel and high performance computing is their top priority. I think they hope that it will be the next Fortran, but I think it is very much a domain specific language. They have clearly given plenty of thought to distributed computing, parallelization and concurrency that could yield some very nice performance advantages. However Python's advantage is that it is a dynamic language and can act as a front end to algorithms written in C/C++ for instance as Google has done with TensorFlow. In the future it could even act as a front end to Chapel since they now have a C API. However, I feel as if computer programming languages are still in this static-dynamic partnership, e.g. Python with C/C++, R and Fortran/C/C++. It means language overhead always maintaining code in more than one language and always having to amend your interface every time you change something in one or the other. In essence, nothing fundamentally different is happening with current new languages. I hate to sound like a broken record, but what Sparrow proposes is a unification in such a way that all kinds of overheads go away. Making something like that work with the principles of Sparrow would be a revolution in computing.
Re: [GtkD] How to connect to notify::active signal?
On Saturday, 4 May 2013 at 09:59:12 UTC, Mike Wey wrote: On 05/04/2013 05:20 AM, Alexandr Druzhinin wrote: 04.05.2013 1:18, Mike Wey пишет: On 05/03/2013 06:30 PM, Alexandr Druzhinin wrote: I need to connect to "notify::active" signal for Switch widget to process changing of its state. The guides say I shouldn't use onActivate signal, but "notify:active". But I didn't find a way to do it. Can somebody help with it? Are you referring to gtk.Switch ? yes, gtk.Switch if I connect to activate signal by means addOnActivate nothing works. Documentation says I should use "notify::active" event (it belongs to ObjectG, as I understand?), but I cannot find a way to connect to this signal by means of GtkD. You can use addOnNotify it currently doesn't allow you to specify the property for witch you want to receive the signal (it probably should). For now you could do: Switch sw = new Switch(); sw.addOnNotify(); void notify(ParamSpec param, ObjectG obj) { if(param.getName() == "active") { //Do stuff } } Hi! I would like to share a small example of this: module gtkd_switch; // Compile: ldc -w main.d `pkg-config --cflags --libs gtkd-3` import std.stdio; import gtk.Builder; import gtk.Main, gtk.Window, gtk.Switch, gtk.Widget; import gobject.ObjectG ,gobject.ParamSpec; void on_swt_change(ParamSpec param, ObjectG obj, Switch *obj_switch){ bool state = obj_switch.getActive(); writefln("Changed! %b", state); } void main(string[] args) { Main.init(args); Builder g = new Builder(); g.addFromFile("vista.glade"); // Widgets from glade file "vista.glade": Window w = cast(Window)g.getObject("window1"); w.setDefaultSize(320, 80); w.setTitle("Gtkd Switch addOnNotify"); Switch swt = cast(Switch)g.getObject("swt_test"); // Actions: w.addOnHide( delegate void(Widget aux){ Main.quit(); } ); swt.addOnNotify(delegate void (ParamSpec, ObjectG){on_swt_change(ParamSpec, ObjectG, );}, "active"); w.showAll(); Main.run(); }
Re: UFCS not working with alias
On 9/7/16 4:26 AM, Andre Pany wrote: On Wednesday, 7 September 2016 at 08:08:34 UTC, rikki cattermole wrote: On 07/09/2016 8:06 PM, Andre Pany wrote: Should I open an enhancement request? No. It works outside of the function (part of lookup rules). I simplified my example too much. Yes in the example above I can move the alias outside the main function. Here is a more complex example. As I use the input parameter args in the alias, I cannot move the alias outside the main function. import std.algorithm; bool fulfillsKeyPredicate(string s, string t) {return true;} void main(string[] args) { alias keyPredicateFilter = filter!(e => e.fulfillsKeyPredicate(args[0])); string[] arr; keyPredicateFilter(arr); arr.keyPredicateFilter; } Is there a workaround? Or is still a valid scenario to change the lookup rules? There is a workaround, identified by Vladimir Panteleev (https://blog.thecybershadow.net/2015/04/28/the-amazing-template-that-does-nothing/): import std.algorithm; bool fulfillsKeyPredicate(string s, string t) {return true;} alias I(alias x) = x; void main(string[] args) { alias keyPredicateFilter = filter!(e => e.fulfillsKeyPredicate(args[0])); string[] arr; keyPredicateFilter(arr); arr.I!keyPredicateFilter; } Unfortunately, you can't alias the I!someSymbol, as that has the same problem. -Steve
Re: Classes new'd inside for loop are all the same instance?
On Thursday, 8 September 2016 at 12:36:29 UTC, drug wrote: is address of the variable c, that is allocated on the stack and has the same address on every iteration cast(void*)c return the value of variable c that is address of a class instance and is different for every iteration in other words is address of pointer cast(void*)c is the pointer itself Yes, thank you. I'll just add that in D (as well as in Java and C#), while classes are always reference types and the type of `c` in `C c = new C();` will be reported as C, it's actually more of a hidden type, "reference to a C". These references are always passed by value. c (reference to a C) value pointed at by c on the stack on the heap [0x2450]... [0x8695] |^ || For example: class C { string name; } void setName(C c) { c.name = "bob"; //This change will be seen outside setName c = new C("jim"); //This change will not } void setNameRef(ref C c) { c.name = "bob"; //This change will be seen outside setNameRef c = new C("jim"); //This change will also be seen outside setNameRef } In `setName` c (which is actually a reference to a C) cannot be rebound as the reference is passed by value into the function. However, c.name can still be modified as you are modifying the value pointed at by the reference, not the reference itself. In `setNameRef` you can modify both, because c is passed by ref, meaning that there is now a double-indirection. Thus, you can modify both c and the value pointed at by c.
Re: Templates problem
On Thursday, 8 September 2016 at 10:18:36 UTC, Russel Winder wrote: I am certainly hoping that Chapel will be the language to displace NumPy for serious computation in the Python-sphere. Given it's foundation in the PGAS model, it has all the parallelism needs, both cluster and local, built in. Given Chapel there is no need to look at C++, D, Rust, Cython, etc. I care about performance, but also about productivity. Chapel still has some ways to go on the latter. Also, they are still in the early stages of GPU support, I think.
Re: Classes new'd inside for loop are all the same instance?
08.09.2016 15:24, lobo пишет: I am confused, which is normal, but I'd appreciate some help :-) If I create N classes in a for loop they are all the same instance. I would expect each to be a unique instance of the class. See the code below --- class C {} void main() { import std.stdio; auto c1 = new C(); writefln("c1:%s", ); // OK, instance c1 is unique auto c2 = new C(); // OK, instance c2 is unqiue writefln("c2:%s", ); foreach(a; 0..10) { C c = new C(); // All instances are the same object with the same address? writefln("c:%s", ); } } --- This isn't what I expected. What could I be doing wrong? Thanks, lobo is address of the variable c, that is allocated on the stack and has the same address on every iteration cast(void*)c return the value of variable c that is address of a class instance and is different for every iteration in other words is address of pointer cast(void*)c is the pointer itself
Re: Classes new'd inside for loop are all the same instance?
On Thursday, 8 September 2016 at 12:36:29 UTC, drug wrote: 08.09.2016 15:24, lobo пишет: [...] is address of the variable c, that is allocated on the stack and has the same address on every iteration cast(void*)c return the value of variable c that is address of a class instance and is different for every iteration in other words is address of pointer cast(void*)c is the pointer itself Got it, thank you :)
Re: Classes new'd inside for loop are all the same instance?
On Thursday, 8 September 2016 at 12:28:55 UTC, Meta wrote: On Thursday, 8 September 2016 at 12:24:48 UTC, lobo wrote: [...] I don't have time to explain at the moment, but change the `` to `cast(void*)c` and you will see what you expect. I will post an explanation soon. Thanks for the blazingly quick reply! :) Please post the explanation when you get time because I'd love to know what is really happening. bye, lobo
Re: Classes new'd inside for loop are all the same instance?
On 09/09/2016 12:24 AM, lobo wrote: I am confused, which is normal, but I'd appreciate some help :-) If I create N classes in a for loop they are all the same instance. I would expect each to be a unique instance of the class. See the code below --- class C {} void main() { import std.stdio; auto c1 = new C(); writefln("c1:%s", ); // OK, instance c1 is unique auto c2 = new C(); // OK, instance c2 is unqiue writefln("c2:%s", ); foreach(a; 0..10) { C c = new C(); // All instances are the same object with the same address? writefln("c:%s", ); } } --- This isn't what I expected. What could I be doing wrong? Thanks, lobo Well for starters C is already a pointer ;) cast(void*) should do the trick not &.
Re: Classes new'd inside for loop are all the same instance?
On Thursday, 8 September 2016 at 12:24:48 UTC, lobo wrote: I am confused, which is normal, but I'd appreciate some help :-) If I create N classes in a for loop they are all the same instance. I would expect each to be a unique instance of the class. See the code below --- class C {} void main() { import std.stdio; auto c1 = new C(); writefln("c1:%s", ); // OK, instance c1 is unique auto c2 = new C(); // OK, instance c2 is unqiue writefln("c2:%s", ); foreach(a; 0..10) { C c = new C(); // All instances are the same object with the same address? writefln("c:%s", ); } } --- This isn't what I expected. What could I be doing wrong? Thanks, lobo I don't have time to explain at the moment, but change the `` to `cast(void*)c` and you will see what you expect. I will post an explanation soon.
Classes new'd inside for loop are all the same instance?
I am confused, which is normal, but I'd appreciate some help :-) If I create N classes in a for loop they are all the same instance. I would expect each to be a unique instance of the class. See the code below --- class C {} void main() { import std.stdio; auto c1 = new C(); writefln("c1:%s", ); // OK, instance c1 is unique auto c2 = new C(); // OK, instance c2 is unqiue writefln("c2:%s", ); foreach(a; 0..10) { C c = new C(); // All instances are the same object with the same address? writefln("c:%s", ); } } --- This isn't what I expected. What could I be doing wrong? Thanks, lobo
Re: Functions, nothrow and assert
On Thursday, 8 September 2016 at 11:40:17 UTC, Russel Winder wrote: Is the fact that: void f() nothrow { assert(1 == 0); } int main() { f(); return 0; } compiles fine but at run time f does indeed throw an exception what should happen? If it is what does nothrow actually mean? To expand on the previous correct answers, nothrow is about not throwing Exceptions. Exceptions are part of the normal flow of the program: they are used to signal recoverable errors, much like error codes. Errors, on the other hand, are unrecoverable system failures that should not be catched (catching them is undefined behaviour, I think) and will surely lead to a crash. Errors are not covered by nothrow. Asserts throw Errors, not Exceptions. The reason is that asserts are used to test conditions that must hold, at the point that an optimizing compiler can analyze the expression inside the assert and optimize the executable based on the truthness of that condition. So if an assert is found false at runtime, the code may not be able to work at all. That's why asserts throw Errors and not Exceptions.
Re: Functions, nothrow and assert
On Thursday, 8 September 2016 at 11:45:32 UTC, Basile B. wrote: f() is nothrow because assert() throws an "AssertError" not an "Exception". Since Error descendants are not recoverable the program usually crashes. The program is guaranteed to crash unless you catch the error (not recommended).
Re: Functions, nothrow and assert
On Thursday, 8 September 2016 at 11:40:17 UTC, Russel Winder wrote: Is the fact that: void f() nothrow { assert(1 == 0); } int main() { f(); return 0; } compiles fine but at run time f does indeed throw an exception what should happen? If it is what does nothrow actually mean? f() is nothrow because assert() throws an "AssertError" not an "Exception". Since Error descendants are not recoverable the program usually crashes.
Functions, nothrow and assert
Is the fact that: void f() nothrow { assert(1 == 0); } int main() { f(); return 0; } compiles fine but at run time f does indeed throw an exception what should happen? If it is what does nothrow actually mean? -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder signature.asc Description: This is a digitally signed message part
Re: Templates problem
On Wed, 2016-09-07 at 16:21 +, Kagamin via Digitalmars-d-learn wrote: > On Wednesday, 7 September 2016 at 11:37:44 UTC, Russel Winder > wrote: > > > > The real problem though is the terrifying error message. I am > > having a hard time finding a way of pitching them to > > Pythonistas. > > Do they use single assignment a lot? Python has no notion of single assignment. Exactly the opposite, Python allows everything to be changed at any time. I fear there is a confluence of disjoint subthreads happening here. Probably my fault. -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder signature.asc Description: This is a digitally signed message part
Re: Templates problem
On Wed, 2016-09-07 at 20:29 +, deXtoRious via Digitalmars-d-learn wrote: > […] > More to the general point of the discussion, I find that most > scientifically minded users of Python already appreciate some of > the inherent advantages of lower level statically typed languages > and often rather write C/C++ code than descend into the likes of > Cython. D has considerable advantages over C++ in conciseness and > template facilities for achieving zero cost static polymorphism > without descending into utter unreadability. Personally, I find > myself still forced to write most of my non-Julia high > performance code in C++ due to the available libraries and GPGPU > support (especially CUDA), but in terms of language properties > I'd much rather be writing D. Or Chapel. -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder signature.asc Description: This is a digitally signed message part
Re: Templates problem
On Wed, 2016-09-07 at 20:29 +, jmh530 via Digitalmars-d-learn wrote: > […] > Are you familiar with Chapel at all? The language allows the user > to specify a domain with an array, facilitating sparsity or > arrays distributed across different machines. For some reason I > was reminded of that when you say that asrange returns a range > that enumerates the contents. I am certainly hoping that Chapel will be the language to displace NumPy for serious computation in the Python-sphere. Given it's foundation in the PGAS model, it has all the parallelism needs, both cluster and local, built in. Given Chapel there is no need to look at C++, D, Rust, Cython, etc. -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder signature.asc Description: This is a digitally signed message part
Generate unique members with recursive mixins or another solution?
Is it possible to generate unique fields and members with recursive template mixins? Each mixin has their own scope even if outer scope shadows their scope. So could it be possible to generate template methods that can access members in their own scopes? Assuming the members are dispatches to unique aliases of static functions, methods accessing fields of unique types of both structs and classes. Basically my use case would be something of the nature of the following (ofc I haven't gotten this working so it is mix of pseudo code and some bits of real D): alias Data = AliasSeq!(POD1,POD2,POD3/*etc*/); //List of processed data types alias Callables = AliasSeq!(AliasSeq!(function,another),someClass,SomeStruct); //processors Processor!(Data,Callables) dataProcessor; dataProcessor.simulate!float(1.5f); class SomeClass(Callables) { recursive mixin? } Processor(alias Data, alias Callables) { SomeClass!Callables processors; void simulate(parameterType...)(parameterType param) { foreach(callable; Callables) { static if(/* if right parameters */) { //Generate calls to each applicable processor processors!callable(param); } } } } If this is completely impossible with recursive mixin templates, is there another feasible solution for my use case beyond manual writing?
Re: Instantiating a class with range template parameter
On Thursday, 8 September 2016 at 08:44:54 UTC, Lodovico Giaretta wrote: On Thursday, 8 September 2016 at 08:20:49 UTC, Jon Degenhardt wrote: [snip] I think that auto x = new Derived!(typeof(stdout.lockingTextWriter()))(); // note the parenthesis should work. But usually, you save the writer inside the object and make a free function called `derived` (same as the class, but with lowercase first). You define it this way: auto derived(OutputRange)(auto ref OutputRange writer) { auto result = new Derived!OutputRange(); result.writer = writer; // save the writer in a field of the object return result; } void main() { auto x = derived(stdout.lockingTextWriter); x.writeString("Hello world"); // the writer is saved in the object, no need to pass it } Yes, the form you suggested works, thanks! And thanks for the class structuring suggestion, it has some nice properties.
Re: How compiler detects forward reference errors
Thank you all for your replies. I am trying to learn a bit about compiler and language design and I really like D among many other languages I read about so I am trying to learn from it as well.
Re: Data structures of mixed type
On Thursday, 8 September 2016 at 08:56:13 UTC, Russel Winder wrote: What is the idiomatic way of having an array with a mix of int and float data? Maybe https://dlang.org/phobos/std_variant.html#.Algebraic ? Is relying on automated conversion of int to float acceptable? I don't think so: import std.stdio; void main() { int i = 12345678; float f = i; writeln(f); } Andrea
Data structures of mixed type
What is the idiomatic way of having an array with a mix of int and float data? Is relying on automated conversion of int to float acceptable? -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder signature.asc Description: This is a digitally signed message part
Re: Instantiating a class with range template parameter
On Thursday, 8 September 2016 at 08:20:49 UTC, Jon Degenhardt wrote: I've been generalizing output routines by passing an OutputRange as an argument. This gets interesting when the output routine is an virtual function. Virtual functions cannot be templates, so instead the template parameters need to be part of class definition and specified when instantiating the class. An example is below. It works fine. One thing I can't figure out: how to provide the range parameter without first declaring a variable of the appropriate type. What works is something like: auto writer = stdout.lockingTextWriter; auto x = new Derived!(typeof(writer)); Other forms I've tried fail to compile. For example, this fails: auto x = new Derived!(typeof(stdout.lockingTextWriter)); I'm curious if this can be done without declaring the variable first. Anyone happen to know? --Jon Full example: import std.stdio; import std.range; class Base(OutputRange) { abstract void writeString(OutputRange r, string s); } class Derived(OutputRange) : Base!OutputRange { override void writeString(OutputRange r, string s) { put(r, s); put(r, '\n'); } } void main() { auto writer = stdout.lockingTextWriter; auto x = new Derived!(typeof(writer)); x.writeString(writer, "Hello World"); } I think that auto x = new Derived!(typeof(stdout.lockingTextWriter()))(); // note the parenthesis should work. But usually, you save the writer inside the object and make a free function called `derived` (same as the class, but with lowercase first). You define it this way: auto derived(OutputRange)(auto ref OutputRange writer) { auto result = new Derived!OutputRange(); result.writer = writer; // save the writer in a field of the object return result; } void main() { auto x = derived(stdout.lockingTextWriter); x.writeString("Hello world"); // the writer is saved in the object, no need to pass it }
Instantiating a class with range template parameter
I've been generalizing output routines by passing an OutputRange as an argument. This gets interesting when the output routine is an virtual function. Virtual functions cannot be templates, so instead the template parameters need to be part of class definition and specified when instantiating the class. An example is below. It works fine. One thing I can't figure out: how to provide the range parameter without first declaring a variable of the appropriate type. What works is something like: auto writer = stdout.lockingTextWriter; auto x = new Derived!(typeof(writer)); Other forms I've tried fail to compile. For example, this fails: auto x = new Derived!(typeof(stdout.lockingTextWriter)); I'm curious if this can be done without declaring the variable first. Anyone happen to know? --Jon Full example: import std.stdio; import std.range; class Base(OutputRange) { abstract void writeString(OutputRange r, string s); } class Derived(OutputRange) : Base!OutputRange { override void writeString(OutputRange r, string s) { put(r, s); put(r, '\n'); } } void main() { auto writer = stdout.lockingTextWriter; auto x = new Derived!(typeof(writer)); x.writeString(writer, "Hello World"); }
Re: VisualD core.exception.RangeError@pipedmd(286): Range violation
On 07.09.2016 22:10, Rainer Schuetze wrote: On 07.09.2016 19:28, Rainer Schuetze wrote: On 06.09.2016 06:38, Tofu Ninja wrote: I get "core.exception.RangeError@pipedmd(286): Range violation" whenever I try to build from visual D. Is there any workaround for this? It was reported[1] almost 9 months ago, does not seem like it's going to be fixed anytime soon. Visual D is completely broken for me right now because of it. Only reason I use Visual D is because it's the only useable debugger on windows, now I can't even do that... Lost a day of work trying to fix this, starting to get really annoyed... [1] https://issues.dlang.org/show_bug.cgi?id=15606 Please provide a test case. Without it, there is little that can be done. I now remember having investigated that bug before: https://forum.dlang.org/post/nmkfnm$2f51$1...@digitalmars.com and I did find it happened for symbols of exact length 2048. I even had a fix for it, but can't find it in the log. I'll try to reconstruct what happened... Fixed it again. You can find a prebuilt binary of pipedmd.exe here: https://ci.appveyor.com/project/rainers/visuald/build/1.0.75/job/n9tf67jxcir6kpmg/artifacts
Re: Get all files imported by a D source file
On Thursday, 8 September 2016 at 06:33:00 UTC, Jacob Carlborg wrote: On 2016-09-08 07:39, Yuxuan Shui wrote: Hi, I wonder if there's standardized way to gather which files are imported by a source file. I know I can run "dmd -v" and look for lines start with "import", but I don't know if this is the best way to do it. You can use the "-deps" flag. -deps is even noisier than just -v...
Re: Get all files imported by a D source file
On 2016-09-08 07:39, Yuxuan Shui wrote: Hi, I wonder if there's standardized way to gather which files are imported by a source file. I know I can run "dmd -v" and look for lines start with "import", but I don't know if this is the best way to do it. You can use the "-deps" flag. -- /Jacob Carlborg