Re: Access visibility and linkage
On Thursday, 15 February 2018 at 06:43:52 UTC, Arun Chandrasekaran wrote: I was reading through https://wiki.dlang.org/Access_specifiers_and_visibility#What_is_missing [...] DMD v2.077.1 exhibits the same behavior. Is this is already being worked on? Or is there any plan to address this? Can this be fixed? If so how? If not, why not? AFAICT it's a feature as the article correctly explains this doesn't work well with serialization: Compile-time reflection, i.e. serialization libraries or @attribute scanners. Limiting access for __traits may forbid certain currently working idioms. Use Voldemort types if you want to truly encapsulate something. [...] Also, why is the default visibility of global variables at module level public Shouldn't they be private by default to provide better encapsulation guarantee (and linkage guarantee if the above is addressed in future)? From readability point of view as well, for instance, if I want to know all the functions "exposed" by the current module, I can simply grep for public. It's a sensible default for most libraries and problems. Simply use `private:` if you think otherwise.
Access visibility and linkage
I was reading through https://wiki.dlang.org/Access_specifiers_and_visibility#What_is_missing There is currently no way in D to mark symbols for internal linkage, saying "this an implementation detail, you should not even know this one exists". This is an important module-level encapsulation tool which also somewhat guarantees that those symbols can't be linked to by accident by some other module and you are free to change them keeping binary interface same. DMD v2.077.1 exhibits the same behavior. Is this is already being worked on? Or is there any plan to address this? Can this be fixed? If so how? If not, why not? Name clash between public and private symbols has also been stated as unneeded and useless feature that makes possible to break a compilation of a project by changing private name. It is also impossible to use an UFCS function now if class already has private one with same signature. Also, why is the default visibility of global variables at module level public Shouldn't they be private by default to provide better encapsulation guarantee (and linkage guarantee if the above is addressed in future)? From readability point of view as well, for instance, if I want to know all the functions "exposed" by the current module, I can simply grep for public.
Re: Disk space used and free size of a Network share folder in Windows
On Wednesday, 14 February 2018 at 15:24:42 UTC, Vino wrote: ...the only problem is i am not sure hot to get the out put without the headings(Caption FreeSpace,Size) any help on same is much appreciated. writeln(result.output[38..$]);
Re: opCast cannot implicitly convert a.opCast of type X to Y
On Thursday, 15 February 2018 at 00:34:33 UTC, Meta wrote: On Thursday, 15 February 2018 at 00:27:40 UTC, Meta wrote: On Wednesday, 14 February 2018 at 23:46:30 UTC, aliak wrote: On Wednesday, 14 February 2018 at 15:14:24 UTC, Meta wrote: Ooh yes, of course! Thank you :) Even better: import std.conv; auto b = a.map!(to!float); Actually, that won't quite work without redefining map a little: Optional!U map(alias f, U = typeof(f(t.init)))() { etc... } Ah yes, true, also auto return would work. But then you'd still need to do the typeof(f(T.init)) evaluation in the body... plus you lose being able to see an explicit return type i guess... hmm. So nevermind :) Though a free function would be good me thinks. Then you could use it seamlessly with std.algorithm.map. Optional!U map(alias f, T, U = typeof(f(T.init)))(Optional!T opt) { return Optional!U(f(opt.t)); } Cheers, - Ali
Re: opCast cannot implicitly convert a.opCast of type X to Y
On Thursday, 15 February 2018 at 00:27:40 UTC, Meta wrote: On Wednesday, 14 February 2018 at 23:46:30 UTC, aliak wrote: On Wednesday, 14 February 2018 at 15:14:24 UTC, Meta wrote: Ooh yes, of course! Thank you :) Even better: import std.conv; auto b = a.map!(to!float); Actually, that won't quite work without redefining map a little: Optional!U map(alias f, U = typeof(f(t.init)))() { etc... }
Re: opCast cannot implicitly convert a.opCast of type X to Y
On Wednesday, 14 February 2018 at 23:46:30 UTC, aliak wrote: On Wednesday, 14 February 2018 at 15:14:24 UTC, Meta wrote: I think the best way to do this is to implement `map` for your optional type. Optional!U map(U, alias f)() { return empty? no!U : some!U(f(t)); } Optional!int a = 3; auto b = a.map!(v => cast(float)v); assert(is(typeof(b) == Optional!float)); Ooh yes, of course! Thank you :) Even better: import std.conv; auto b = a.map!(to!float);
Re: opCast cannot implicitly convert a.opCast of type X to Y
On Wednesday, 14 February 2018 at 15:14:24 UTC, Meta wrote: I think the best way to do this is to implement `map` for your optional type. Optional!U map(U, alias f)() { return empty? no!U : some!U(f(t)); } Optional!int a = 3; auto b = a.map!(v => cast(float)v); assert(is(typeof(b) == Optional!float)); Ooh yes, of course! Thank you :)
Re: Disk space used and free size of a Network share folder in Windows
On Wednesday, 14 February 2018 at 15:24:42 UTC, Vino wrote: On Wednesday, 14 February 2018 at 12:29:13 UTC, rikki cattermole wrote: [...] Hi Rikki, Wouldn't this be easy to use with std.process: execute package and calling wmic.exe, the only problem is i am not sure hot to get the out put without the headings(Caption FreeSpace,Size) any help on same is much appreciated. import std.process: execute; import std.stdio : writeln; void main () { version(Windows) { auto result = execute(["wmic.exe", "logicaldisk", "get", "size,freespace,caption"]); writeln(result.output); } } Output : Caption FreeSpaceSize C: 19702837248 180043665408 H: 85580382208 824633720832 From, Vino.B Don't call external processes when you can call a function. Running another process is overhead and not reliable.
Re: vib.d suppress 404 for no content written
On Wednesday, 14 February 2018 at 21:16:23 UTC, aberba wrote: Seb, are you the one doing the vibe.d demo collections? Do you mean this? https://github.com/wilzbach/vibe-d-by-example Yes, that's me, but it still needs a lot of work and I haven't got around polishing it for an alpha "release", but the examples there should be fully functional with ~>vibe.d-0.8.3-alpha.1 BTW I also have a fork of vibe.web.web at https://github.com/teamhackback/hb-web which adds all the convenience features that I haven't been able to get upstream so far [1]. A short overview of what I miss in vibe.web.web: --- class Service { // Returning strings (instead of res.writeBody) string getString() { return "string"; } // https://github.com/vibe-d/vibe.d/pull/1854 // Access to Json auto postJson(Json _json) { return _json; } // https://github.com/vibe-d/vibe.d/pull/1853 // Automatically serialize data types auto postStruct(MyStruct st) { return st.foo + 3; } // https://github.com/vibe-d/vibe.d/pull/1697 // https://github.com/vibe-d/vibe.d/pull/1698 // @path is automatically set to /user/:id // works for all _-prefixed variables that don't have any inference yet (i.e. _error still works) void getUser(string _id, HTTPServerResponse res) { res.writeBody("User: " ~ _id); } } --- Though to be fair, things improved a bit in Vibe.d 0.8.2 and `request` and `response` are now available. They refer to current request. [1] https://github.com/vibe-d/vibe.d/pulls/wilzbach
Re: vib.d suppress 404 for no content written
On Wednesday, 14 February 2018 at 14:58:14 UTC, Seb wrote: On Wednesday, 14 February 2018 at 14:30:19 UTC, Nicholas Wilson wrote: I have an endpoint that is a post: void postStuff(HTTPServerRequest req, HTTPServerResponse res) { // do some stuff with req res.statusCode = 200; } I do not write anything to res (deliberately) but want to set the status code. However it returns 404, because no content is written. How can I make it return 200? FWIW its a member of a web interface class. Thanks Nic You mean `writeVoidBody` See Also: https://github.com/vibe-d/vibe.d/issues/2065 Seb, are you the one doing the vibe.d demo collections?
Re: unable to fork: Cannot allocate memory / core.checkedint / gtkd
On Tuesday, 13 February 2018 at 21:46:31 UTC, Stefan Koch wrote: On Tuesday, 13 February 2018 at 14:10:44 UTC, number wrote: Ok, thanks for the info. I guess I'll just use printf then for larger enums. To get the same convince you can use. the enumToString from: https://forum.dlang.org/post/pnggoabnnkojdonyz...@forum.dlang.org and writeln the result oft that. however it'll cause an error if there are two enum memebrs with the same value. Thanks!
Re: vib.d suppress 404 for no content written
On Wednesday, 14 February 2018 at 14:58:14 UTC, Seb wrote: On Wednesday, 14 February 2018 at 14:30:19 UTC, Nicholas Wilson wrote: I have an endpoint that is a post: void postStuff(HTTPServerRequest req, HTTPServerResponse res) { // do some stuff with req res.statusCode = 200; } I do not write anything to res (deliberately) but want to set the status code. However it returns 404, because no content is written. How can I make it return 200? FWIW its a member of a web interface class. Thanks Nic You mean `writeVoidBody` See Also: https://github.com/vibe-d/vibe.d/issues/2065 Thanks!
Re: Disk space used and free size of a Network share folder in Windows
On Wednesday, 14 February 2018 at 12:29:13 UTC, rikki cattermole wrote: On 14/02/2018 12:22 PM, Vino wrote: Hi All, Request your help on how to get the disk space used and free size of a Network share folder in Windows, tried with getSize but it return 0; eg: Share Name :\\server1\dir1$ From, Vino.B See: https://msdn.microsoft.com/en-us/library/windows/desktop/aa364935(v=vs.85).aspx Hi Rikki, Wouldn't this be easy to use with std.process: execute package and calling wmic.exe, the only problem is i am not sure hot to get the out put without the headings(Caption FreeSpace,Size) any help on same is much appreciated. import std.process: execute; import std.stdio : writeln; void main () { version(Windows) { auto result = execute(["wmic.exe", "logicaldisk", "get", "size,freespace,caption"]); writeln(result.output); } } Output : Caption FreeSpaceSize C: 19702837248 180043665408 H: 85580382208 824633720832 From, Vino.B
Re: opCast cannot implicitly convert a.opCast of type X to Y
On Monday, 12 February 2018 at 02:05:16 UTC, aliak wrote: From spec: Cast expression: "cast ( Type ) UnaryExpression" converts UnaryExpresssion to Type. And https://dlang.org/spec/operatoroverloading.html#cast makes no mention of the return type of opCast. One could think that the return type of opCast would be the return type. But it seems it must be the same as the template parameter of opCast else you get a compile error that seems like it can be much better. --- import std.stdio; struct B(T) { T t; } struct A(T) { T t; auto opCast(U)() { return B!U(cast(U)t); } } void main() { auto a = A!int(3); auto b = cast(float)a; // error } Error: cannot implicitly convert expression a.opCast() of type B!float to float Is this deliberate? The use case I have is making an optional type that you can cast to a different type: auto opCast(U)() const { static if (isOptional!U) { alias V = OptionalTarget!U; return empty ? no!V : some!V(cast(V)front); // it's a range so "front" is the raw value } else { return empty ? no!U : some!U(cast(U)front); } } It would allow for scenarios like: Optional!int a = 3; auto b = cast(float)a; // b == some!float Cheers - Ali I think the best way to do this is to implement `map` for your optional type. Optional!U map(U, alias f)() { return empty? no!U : some!U(f(t)); } Optional!int a = 3; auto b = a.map!(v => cast(float)v); assert(is(typeof(b) == Optional!float));
Re: vib.d suppress 404 for no content written
On Wednesday, 14 February 2018 at 14:30:19 UTC, Nicholas Wilson wrote: I have an endpoint that is a post: void postStuff(HTTPServerRequest req, HTTPServerResponse res) { // do some stuff with req res.statusCode = 200; } I do not write anything to res (deliberately) but want to set the status code. However it returns 404, because no content is written. How can I make it return 200? FWIW its a member of a web interface class. Thanks Nic You mean `writeVoidBody` See Also: https://github.com/vibe-d/vibe.d/issues/2065
vib.d suppress 404 for no content written
I have an endpoint that is a post: void postStuff(HTTPServerRequest req, HTTPServerResponse res) { // do some stuff with req res.statusCode = 200; } I do not write anything to res (deliberately) but want to set the status code. However it returns 404, because no content is written. How can I make it return 200? FWIW its a member of a web interface class. Thanks Nic
Re: Disk space used and free size of a Network share folder in Windows
On 14/02/2018 1:52 PM, psychoticRabbit wrote: On Wednesday, 14 February 2018 at 12:29:13 UTC, rikki cattermole wrote: See: https://msdn.microsoft.com/en-us/library/windows/desktop/aa364935(v=vs.85).aspx any idea on how I'd convert this C# code to D? == public class Program { [DllImport("kernel32.dll")] [return:MarshalAs(UnmanagedType.Bool)] static extern bool GetDiskFreeSpaceEx(string lpDirectoryName, out ulong lpFreeBytesAvailable, out ulong lpTotalNumberOfBytes, out ulong lpTotalNumberOfFreeBytes); static void Main() { string dir = "C:\\"; ulong lpFreeBytesAvailable; ulong lpTotalNumberOfBytes; ulong lpTotalNumberOfFreeBytes; GetDiskFreeSpaceEx(dir, out lpFreeBytesAvailable, out lpTotalNumberOfBytes, out lpTotalNumberOfFreeBytes); Console.WriteLine(lpFreeBytesAvailable"); Console.WriteLine(lpTotalNumberOfBytes"); Console.WriteLine(lpFreeBytesAvailable"); } } = import core.sys.windows.winbase : GetDiskFreeSpaceEx; Use wstring's and .ptr them and everything should work.
Re: Disk space used and free size of a Network share folder in Windows
On Wednesday, 14 February 2018 at 12:29:13 UTC, rikki cattermole wrote: See: https://msdn.microsoft.com/en-us/library/windows/desktop/aa364935(v=vs.85).aspx any idea on how I'd convert this C# code to D? == public class Program { [DllImport("kernel32.dll")] [return:MarshalAs(UnmanagedType.Bool)] static extern bool GetDiskFreeSpaceEx(string lpDirectoryName, out ulong lpFreeBytesAvailable, out ulong lpTotalNumberOfBytes, out ulong lpTotalNumberOfFreeBytes); static void Main() { string dir = "C:\\"; ulong lpFreeBytesAvailable; ulong lpTotalNumberOfBytes; ulong lpTotalNumberOfFreeBytes; GetDiskFreeSpaceEx(dir, out lpFreeBytesAvailable, out lpTotalNumberOfBytes, out lpTotalNumberOfFreeBytes); Console.WriteLine(lpFreeBytesAvailable"); Console.WriteLine(lpTotalNumberOfBytes"); Console.WriteLine(lpFreeBytesAvailable"); } } =
Re: Disk space used and free size of a Network share folder in Windows
On 14/02/2018 12:22 PM, Vino wrote: Hi All, Request your help on how to get the disk space used and free size of a Network share folder in Windows, tried with getSize but it return 0; eg: Share Name :\\server1\dir1$ From, Vino.B See: https://msdn.microsoft.com/en-us/library/windows/desktop/aa364935(v=vs.85).aspx
Disk space used and free size of a Network share folder in Windows
Hi All, Request your help on how to get the disk space used and free size of a Network share folder in Windows, tried with getSize but it return 0; eg: Share Name :\\server1\dir1$ From, Vino.B
Re: rdmd main.d leads to Segmentation fault
On Wednesday, 14 February 2018 at 10:28:51 UTC, Kagamin wrote: On Tuesday, 13 February 2018 at 06:53:46 UTC, Martin Tschierschke wrote: I am unfamiliar with debugging (gdb etc.) so any hint would be appreciated! https://issues.dlang.org/show_bug.cgi?id=18350 - maybe adjust bug severity. I added a comment and increased prio, OK to do it like this? I may post my gdb results in the MET evening later, should I?
Re: dmd-2.078.2 problems with Ubuntu 17.10 32Bit
On Wednesday, 14 February 2018 at 11:16:25 UTC, Martin Tschierschke wrote: Ok, good to know! I started with 16.04 and made the initial mistake to take the 32 Bit version, do you use 32 or 64 Bit? 64bit of course! Andrea
Re: dmd-2.078.2 problems with Ubuntu 17.10 32Bit
On Wednesday, 14 February 2018 at 10:57:47 UTC, Andrea Fontana wrote: On Tuesday, 13 February 2018 at 22:21:18 UTC, Martin Tschierschke wrote: I will downgrade to 16.04., the dist-upgrade to 17.10 was a mistake, resulting in problems with startx and newer kernels so I have to use 4.10. In my experience dist-upgrade are long and messy :) Usually I create a partition on disk; install a fresh (K)ubuntu on that partition; move data / config from old partition to new; delete (or backup) old partition. I have both kubuntu 17.04 and 17.10 and dmd works fine. Andrea Ok, good to know! I started with 16.04 and made the initial mistake to take the 32 Bit version, do you use 32 or 64 Bit?
Re: dmd-2.078.2 problems with Ubuntu 17.10 32Bit
On Tuesday, 13 February 2018 at 22:21:18 UTC, Martin Tschierschke wrote: I will downgrade to 16.04., the dist-upgrade to 17.10 was a mistake, resulting in problems with startx and newer kernels so I have to use 4.10. In my experience dist-upgrade are long and messy :) Usually I create a partition on disk; install a fresh (K)ubuntu on that partition; move data / config from old partition to new; delete (or backup) old partition. I have both kubuntu 17.04 and 17.10 and dmd works fine. Andrea
Re: rdmd main.d leads to Segmentation fault
On Tuesday, 13 February 2018 at 06:53:46 UTC, Martin Tschierschke wrote: I am unfamiliar with debugging (gdb etc.) so any hint would be appreciated! https://issues.dlang.org/show_bug.cgi?id=18350 - maybe adjust bug severity.