Re: Dub platform probes
On Thursday, 28 May 2020 at 02:28:07 UTC, Tim wrote: On Wednesday, 27 May 2020 at 21:17:54 UTC, Andre Pany wrote: I read through the source code. The probe file is created here https://github.com/dlang/dub/blob/master/source/dub/compilers/utils.d#L296 The function getTempFile determines a new random temp file name and stores the file path in a global variable. A module destructor loops through this string array list and deletes the temp files https://github.com/dlang/dub/blob/master/source/dub/internal/utils.d#L98 I wonder why in your case the temp files are not deleted. Kind regards Andre Me too. I have noticed that sometimes I don't need to and other times I do. Maybe it is to do with program crashes where it isn't cleaned up? I'll keep a closer eye on it Is the app you're building a server by any chance ? There's a recurrent problem with `dub`: - https://github.com/dlang/dub/issues/536 There's a fix for it, unmerged though as it needs some work/testing: https://github.com/dlang/dub/pull/1696
Re: Dub platform probes
On Wednesday, 27 May 2020 at 21:17:54 UTC, Andre Pany wrote: I read through the source code. The probe file is created here https://github.com/dlang/dub/blob/master/source/dub/compilers/utils.d#L296 The function getTempFile determines a new random temp file name and stores the file path in a global variable. A module destructor loops through this string array list and deletes the temp files https://github.com/dlang/dub/blob/master/source/dub/internal/utils.d#L98 I wonder why in your case the temp files are not deleted. Kind regards Andre Me too. I have noticed that sometimes I don't need to and other times I do. Maybe it is to do with program crashes where it isn't cleaned up? I'll keep a closer eye on it
Re: Mir Slice Column or Row Major
On Thursday, 28 May 2020 at 00:51:50 UTC, 9il wrote: snip Actually it is a question of notation. For example, mir-lapack uses ndslice as column-major Fortran arrays. This may cause some headaches because the data needs to be transposed in mind. We can think about ndslice as about column-major nd-arrays with the reversed order of indexing. The current template looks like Slice(Iterator, size_t N = 1, SliceKind kind = 1) If we add a special column-major notation, then it will look like Slice(Iterator, size_t N = 1, SliceKind kind = Contiguous, PayloadOrder = RowMajor) A PR that adds this feature will be accepted. Oh, that is news to me. I was under the impression that such a PR would not be accepted. The prototype you have is exactly what I had been thinking (that’s what eigen does). Unfortunately, I don’t think I have the time to ensure everything works properly with column major. I think my time right now is better spent on other mir stuff, but it’s good to know that the only obstacle is someone putting the work in.
Re: Mir Slice Column or Row Major
On Wednesday, 27 May 2020 at 16:53:37 UTC, jmh530 wrote: On Wednesday, 27 May 2020 at 16:07:58 UTC, welkam wrote: On Wednesday, 27 May 2020 at 01:31:23 UTC, data pulverizer wrote: column major Cute puppies die when people access their arrays in column major. Not always true...many languages support column-major order (Fortran, most obviously). The Eigen C++ library allows the user to specify row major or column major. I had brought this up with Ilya early on in mir and he thought it would increase complexity to allow both and could also require more memory. So mir is row major. Actually it is a question of notation. For example, mir-lapack uses ndslice as column-major Fortran arrays. This may cause some headaches because the data needs to be transposed in mind. We can think about ndslice as about column-major nd-arrays with the reversed order of indexing. The current template looks like Slice(Iterator, size_t N = 1, SliceKind kind = 1) If we add a special column-major notation, then it will look like Slice(Iterator, size_t N = 1, SliceKind kind = Contiguous, PayloadOrder = RowMajor) A PR that adds this feature will be accepted.
Re: Dub platform probes
On Wednesday, 27 May 2020 at 04:19:46 UTC, Tim wrote: On Tuesday, 26 May 2020 at 09:17:52 UTC, Andre Pany wrote: Hi, What version of dub do you use? I am not 100 % sure but thought platform probes do not longer write files with recent dub version. Do you use DMD or LDC or GDC? Kind regards Andre Hi there I'm using Dub 1.19.0-1build2 with dmd Thanks I read through the source code. The probe file is created here https://github.com/dlang/dub/blob/master/source/dub/compilers/utils.d#L296 The function getTempFile determines a new random temp file name and stores the file path in a global variable. A module destructor loops through this string array list and deletes the temp files https://github.com/dlang/dub/blob/master/source/dub/internal/utils.d#L98 I wonder why in your case the temp files are not deleted. Kind regards Andre
Re: How to parse enum from a string ?
On Wednesday, 27 May 2020 at 17:36:35 UTC, Dennis wrote: On Wednesday, 27 May 2020 at 17:33:33 UTC, Vinod K Chandran wrote: I am saving this enum values as string in database. So, when i retrieve them from the database, how can i parse the string into TestEnum ? Use `to` from `std.conv`. ``` import std.conv: to; void main() { assert("Received".to!TestEnum == TestEnum.Received); } ``` Hi, Thanks a lot. It worked. :)
Re: How to parse enum from a string ?
On Wednesday, 27 May 2020 at 17:33:33 UTC, Vinod K Chandran wrote: I am saving this enum values as string in database. So, when i retrieve them from the database, how can i parse the string into TestEnum ? Use `to` from `std.conv`. ``` import std.conv: to; void main() { assert("Received".to!TestEnum == TestEnum.Received); } ```
Re: How to parse enum from a string ?
On Wednesday, 27 May 2020 at 17:33:33 UTC, Vinod K Chandran wrote: Hi all, Assume that i have an enum like this. enum TestEnum { Received = 1, Started , Finished , Sent } I am saving this enum values as string in database. So, when i retrieve them from the database, how can i parse the string into TestEnum ? In vb. net, i can use [Enum].Parse(GetType( TestEnum), "Started") How to do this in D ? you can convert an enum to a string using myEnum.to!string and you can similarly convert strings back to the enum using someString.to!TestEnum (import std.conv for both of them) Example: https://run.dlang.io/is/UeLjJS
How to parse enum from a string ?
Hi all, Assume that i have an enum like this. enum TestEnum { Received = 1, Started , Finished , Sent } I am saving this enum values as string in database. So, when i retrieve them from the database, how can i parse the string into TestEnum ? In vb. net, i can use [Enum].Parse(GetType( TestEnum), "Started") How to do this in D ?
Re: Mir Slice Column or Row Major
On Wednesday, 27 May 2020 at 16:07:58 UTC, welkam wrote: On Wednesday, 27 May 2020 at 01:31:23 UTC, data pulverizer wrote: column major Cute puppies die when people access their arrays in column major. Not always true...many languages support column-major order (Fortran, most obviously). The Eigen C++ library allows the user to specify row major or column major. I had brought this up with Ilya early on in mir and he thought it would increase complexity to allow both and could also require more memory. So mir is row major.
Re: Mir Slice Column or Row Major
On Wednesday, 27 May 2020 at 01:31:23 UTC, data pulverizer wrote: column major Cute puppies die when people access their arrays in column major.
Re: [Windows]Need an example: How to read and list names of USB devices via Windows API without using Utilities
On Wednesday, 27 May 2020 at 14:16:56 UTC, BoQsc wrote: I always wanted to know if there is any proven example on how to interface with USB devices by using Windows operating system. Any explanations, snippets in relation to topic would help. What I expect: Being able to detect if a new USB device is connected. Being able to read USB device name. Being able to read USB device partition/s name/s. Being able to list all USB devices. What is required and are there any critical problems with achieving any of this? Hello! I advise you to see the following until others have answered you: [1]: https://code.dlang.org/packages/libusb-d [2]: https://code.dlang.org/packages/serialport I can not say that these links satisfy your needs.
[Windows]Need an example: How to read and list names of USB devices via Windows API without using Utilities
I always wanted to know if there is any proven example on how to interface with USB devices by using Windows operating system. Any explanations, snippets in relation to topic would help. What I expect: Being able to detect if a new USB device is connected. Being able to read USB device name. Being able to read USB device partition/s name/s. Being able to list all USB devices. What is required and are there any critical problems with achieving any of this?
Re: What's the best way to find out which exceptions may be thrown ?
On Wednesday, 27 May 2020 at 11:40:00 UTC, Mike Parker wrote: On Wednesday, 27 May 2020 at 10:30:36 UTC, wjoe wrote: On Wednesday, 27 May 2020 at 10:01:33 UTC, Mike Parker wrote: Could you please elaborate why checked exceptions are more annoying? For me, it's because they require all functions that touch them to either try/catch or include an exception specification in its declaration. In my Java days, I ended up just doing what so many others do and adding `throws Exception` or `catch(Exception)` to avoid having to handle multiple exception types. Most of the time, I didn't care what specific sort of exception was thrown. Johannes, Dennis, Mike that was very insightful. I didn't consider those reasons. Thank you very much for the elaboration :)
Re: Unable to access a variable declared inside an if statement (Error: is shadowing variable)
On Wednesday, 27 May 2020 at 11:13:09 UTC, Simen Kjærås wrote: On Wednesday, 27 May 2020 at 11:03:51 UTC, BoQsc wrote: I'm lacking knowledge on how to achieve what I want and getting an error. What is the correct way to do what I tried to achieve in this code? Everything was intuitive until I started to add notice variable to the writeln. Rdmd says variable `notice` is shadowing variable. if (driveLetter.exists){ auto directory = "/Backup"; if ((driveLetter ~ directory).exists){ auto notice = "Backup directory exists."; } writeln(driveLetter, notice); } Variables only live in a specified scope, starting from where they are declared, and ending when they reach the '}' indicating the end of said scope. In you case, 'notice' only lives inside the if ((driveLetter ~ directory).exists) scope, and doesn't exist outside. In order to fix this, you will need to declare it outside: if (driveLetter.exists) { auto directory = "/Backup"; auto notice = "Backup directory does not exist."; if ((driveLetter ~ directory).exists) { notice = "Backup directory exists."; } writeln(driveLetter, notice); } This also makes it clearer what value 'notice' will have when the backup directory doesn't exist - in your case you haven't assigned it any value in that case. -- Simen That's correct. Thanks Simen. import std.stdio : writeln; import std.file; void main(){ auto drivesLetters = [ "A:", "I:", "Q:", "Y:", "B:", "J:", "R:", "Z:", "C:", "K:", "S:", "D:", "L:", "T:", "E:", "M:", "U:", "F:", "N:", "V:", "G:", "O:", "W:", "H:", "P:", "X:", ]; foreach (string driveLetter; drivesLetters) { if (driveLetter.exists) { auto notice = ""; if ((driveLetter ~ "/Boot").exists) { notice ~= "\\Boot directory exists"; notice ~= " "; } if ((driveLetter ~ "/Windows").exists) { notice ~= "\\Windows folder exists"; notice ~= " "; } writeln(driveLetter, notice); } } }
Re: What's the best way to find out which exceptions may be thrown ?
On Wednesday, 27 May 2020 at 10:30:36 UTC, wjoe wrote: On Wednesday, 27 May 2020 at 10:01:33 UTC, Mike Parker wrote: Could you please elaborate why checked exceptions are more annoying? For me, it's because they require all functions that touch them to either try/catch or include an exception specification in its declaration. In my Java days, I ended up just doing what so many others do and adding `throws Exception` or `catch(Exception)` to avoid having to handle multiple exception types. Most of the time, I didn't care what specific sort of exception was thrown.
Re: Unable to access a variable declared inside an if statement (Error: is shadowing variable)
On Wednesday, 27 May 2020 at 11:03:51 UTC, BoQsc wrote: I'm lacking knowledge on how to achieve what I want and getting an error. What is the correct way to do what I tried to achieve in this code? Everything was intuitive until I started to add notice variable to the writeln. Rdmd says variable `notice` is shadowing variable. if (driveLetter.exists){ auto directory = "/Backup"; if ((driveLetter ~ directory).exists){ auto notice = "Backup directory exists."; } writeln(driveLetter, notice); } Variables only live in a specified scope, starting from where they are declared, and ending when they reach the '}' indicating the end of said scope. In you case, 'notice' only lives inside the if ((driveLetter ~ directory).exists) scope, and doesn't exist outside. In order to fix this, you will need to declare it outside: if (driveLetter.exists) { auto directory = "/Backup"; auto notice = "Backup directory does not exist."; if ((driveLetter ~ directory).exists) { notice = "Backup directory exists."; } writeln(driveLetter, notice); } This also makes it clearer what value 'notice' will have when the backup directory doesn't exist - in your case you haven't assigned it any value in that case. -- Simen
Re: What's the best way to find out which exceptions may be thrown ?
On Wednesday, 27 May 2020 at 09:56:07 UTC, wjoe wrote: The problem with catch(Exception) is that it's run time whereas I'd like to know compile time which exception may possibly be thrown. Note that this is impossible in general due to the nature of classes. A function could at runtime find the latest trending hashtag on twitter, name a class after it that derives from Exception, invoke the compiler to generate a shared library that throws an exception with that class, load that library, and call the newly loaded function that throws the newly created exception class. Obviously there's no way of knowing this class at compile time.
Unable to access a variable declared inside an if statement (Error: is shadowing variable)
I'm lacking knowledge on how to achieve what I want and getting an error. What is the correct way to do what I tried to achieve in this code? Everything was intuitive until I started to add notice variable to the writeln. Rdmd says variable `notice` is shadowing variable. rdmd output: C:\Users\vaida\Desktop>rdmd searchDirectory.d searchDirectory.d(21): Error: variable `notice` is shadowing variable `searchDirectory.main.notice` Failed: ["C:\\D\\dmd2\\windows\\bin\\dmd.exe", "-v", "-o-", "searchDirectory.d", "-I."] searchDirectory.d import std.stdio : writeln; import std.file; void main(){ auto drivesLetters = [ "A:", "I:", "Q:", "Y:", "B:", "J:", "R:", "Z:", "C:", "K:", "S:", "D:", "L:", "T:", "E:", "M:", "U:", "F:", "N:", "V:", "G:", "O:", "W:", "H:", "P:", "X:", ]; foreach (string driveLetter; drivesLetters) { string notice; if (driveLetter.exists){ auto directory = "/Backup"; if ((driveLetter ~ directory).exists){ auto notice = "Backup directory exists."; } writeln(driveLetter, notice); } } }
Re: What's the best way to find out which exceptions may be thrown ?
Am 27.05.20 um 12:30 schrieb wjoe: > > Could you please elaborate why checked exceptions are more annoying? > > The only exposure to checked exceptions I had was with Java and I always > liked and appreciated them. > It's super annoying the fiddle around with catch(Exception) all over the > place and log unhandled Exceptions and never be sure that all exceptions > are properly taken care of. > There are several reasons. Walter elaborates on some of them in the thread regarding the acceptance of DIP1028 in the announce section. Another example is the fact that they don't work with functional interfaces in Java: You cannot pass a function that throws checked exceptions to map etc.
Re: What's the best way to find out which exceptions may be thrown ?
On Wednesday, 27 May 2020 at 10:01:33 UTC, Mike Parker wrote: On Wednesday, 27 May 2020 at 09:56:07 UTC, wjoe wrote: The problem with catch(Exception) is that it's run time whereas I'd like to know compile time which exception may possibly be thrown. So I take it the only way to find out what may be thrown is to read the source code of the called function(s) and the rat tail that follows - and to rely on documentation to be accurate and complete if the source code isn't available. That's sort of annoying. Checked exceptions are much more annoying. Could you please elaborate why checked exceptions are more annoying? The only exposure to checked exceptions I had was with Java and I always liked and appreciated them. It's super annoying the fiddle around with catch(Exception) all over the place and log unhandled Exceptions and never be sure that all exceptions are properly taken care of.
Re: What's the best way to find out which exceptions may be thrown ?
On Wednesday, 27 May 2020 at 09:44:56 UTC, Mike Parker wrote: On Wednesday, 27 May 2020 at 09:42:58 UTC, Mike Parker wrote: I should add that if you're only catching specific exceptions in a `nothrow` function, then it isn't `nothrow`. You have to catch Exception because D does not have exception specifications. I would expect the compiler to complain if you try to do otherwise. I should add that the reason for my question wasn't to make a function nothrow by means of not letting Exceptions escape, for which std.exception.assumeWontThrow could be used, but to be able to find out which exceptions can/should be handled at a particular call site.
Re: What's the best way to find out which exceptions may be thrown ?
On Wednesday, 27 May 2020 at 09:56:07 UTC, wjoe wrote: The problem with catch(Exception) is that it's run time whereas I'd like to know compile time which exception may possibly be thrown. So I take it the only way to find out what may be thrown is to read the source code of the called function(s) and the rat tail that follows - and to rely on documentation to be accurate and complete if the source code isn't available. That's sort of annoying. Checked exceptions are much more annoying. And without them, there's no way (as far as I can see) the compiler can verify what a function may throw without parsing the source of every function a call chain touches. That's rather impractical.
Re: What's the best way to find out which exceptions may be thrown ?
On Wednesday, 27 May 2020 at 09:44:56 UTC, Mike Parker wrote: On Wednesday, 27 May 2020 at 09:42:58 UTC, Mike Parker wrote: On Wednesday, 27 May 2020 at 09:40:08 UTC, wjoe wrote: The compiler will complain that bar(int) isn't nothrow. What's the best way to find out which Exceptions aren't handled inside of foo() for foo to be able to be nothrow without using a 'catch (Exception){}' catch-all? `catch(Exception)`. I should add that if you're only catching specific exceptions in a `nothrow` function, then it isn't `nothrow`. You have to catch Exception because D does not have exception specifications. I would expect the compiler to complain if you try to do otherwise. Thanks for the fast reply, Mike. The problem with catch(Exception) is that it's run time whereas I'd like to know compile time which exception may possibly be thrown. So I take it the only way to find out what may be thrown is to read the source code of the called function(s) and the rat tail that follows - and to rely on documentation to be accurate and complete if the source code isn't available. That's sort of annoying.
Re: What's the best way to find out which exceptions may be thrown ?
On Wednesday, 27 May 2020 at 09:42:58 UTC, Mike Parker wrote: On Wednesday, 27 May 2020 at 09:40:08 UTC, wjoe wrote: The compiler will complain that bar(int) isn't nothrow. What's the best way to find out which Exceptions aren't handled inside of foo() for foo to be able to be nothrow without using a 'catch (Exception){}' catch-all? `catch(Exception)`. I should add that if you're only catching specific exceptions in a `nothrow` function, then it isn't `nothrow`. You have to catch Exception because D does not have exception specifications. I would expect the compiler to complain if you try to do otherwise.
What's the best way to find out which exceptions may be thrown ?
nothrow void foo() { bar(4); } void bar(int a) { if (a ==1) throw new Exception1(); else if (a == 2) throw new Exception2(); baz(); } void baz() { if (whatever) throw new Exception3(); } The compiler will complain that bar(int) isn't nothrow. What's the best way to find out which Exceptions aren't handled inside of foo() for foo to be able to be nothrow without using a 'catch (Exception){}' catch-all?
Re: What's the best way to find out which exceptions may be thrown ?
On Wednesday, 27 May 2020 at 09:40:08 UTC, wjoe wrote: The compiler will complain that bar(int) isn't nothrow. What's the best way to find out which Exceptions aren't handled inside of foo() for foo to be able to be nothrow without using a 'catch (Exception){}' catch-all? `catch(Exception)`.
Re: How to get the pointer of "this" ?
On Tuesday, 26 May 2020 at 22:23:19 UTC, bauss wrote: On Tuesday, 26 May 2020 at 12:08:29 UTC, Johannes Loher wrote: [...] You can just do this to get around it: auto button = this; log(); True, somebody else posted the same idea already. But as explained, it doesn't do the correct thing.