Re: scope(~this)

2017-03-16 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 15 March 2017 at 19:34:32 UTC, Ali Çehreli wrote: On 03/15/2017 03:23 AM, Basile B. wrote: > you can use a mixin template because > they can introduce destructors that are called automatically with the > aggregate destrcutor Wow! Is this specified anywhere or have you come across

Re: scope(~this)

2017-03-16 Thread Basile B. via Digitalmars-d-learn
On Thursday, 16 March 2017 at 07:49:19 UTC, Basile B. wrote: On Wednesday, 15 March 2017 at 19:34:32 UTC, Ali Çehreli wrote: On 03/15/2017 03:23 AM, Basile B. wrote: > you can use a mixin template because > they can introduce destructors that are called automatically with the > aggregate destrc

Re: debug mixins

2017-03-16 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, March 15, 2017 13:01:36 Inquie via Digitalmars-d-learn wrote: > On Wednesday, 15 March 2017 at 03:50:21 UTC, Jonathan M Davis > > wrote: > > On Wednesday, March 15, 2017 03:43:20 Inquie via > > > > Digitalmars-d-learn wrote: > >> [...] > > > > Related: https://issues.dlang.org/show_bu

Cannot compile dmd2

2017-03-16 Thread Hussien via Digitalmars-d-learn
I downloaded dmd2 nightly and tried to compile the compiler using the visual studio project. Using VS2014 I got several errors. There seems to be issue with locations of things in the project. 1. I had to download default_ddoc_theme.ddoc from the net and put it in /dmd2/src/dmd/vcbuild so t

How delegate context work?

2017-03-16 Thread Eko Wahyudin via Digitalmars-d-learn
I'm writing promise library, and perform testing like this.. app = new Application(); Promise p = app.exec(delegate void(){ // first delegate write("Hello"); std.stdio.stdout.flush; int xxx = 777;

Re: How delegate context work?

2017-03-16 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 16 March 2017 at 14:53:27 UTC, Eko Wahyudin wrote: How D access xxx variable? where context pointer refer to? How D keep xxx variable persistent? Why xxx is not swapped out when we leave first delegate? The compiler sees that you are going to reference the variable, and copies it

Sorting Assosiative Arrays and Finding Largest Common Substring

2017-03-16 Thread helxi via Digitalmars-d-learn
I was looking for ways to find the largest common substring between two given substrings and have learnt 1. .length is of type ulong 2. writing string[int] will not give me a sorted array 3. ulong cannot be sorted by sorted What's the trick to sort the associative array by their keys? Code snip

std.digest toHexString

2017-03-16 Thread Carl Sturtivant via Digitalmars-d-learn
What's going on here? ``` import std.digest.md, std.stdio; void main() { string ans = hex("qwertyuiop"); writeln(ans); } string hex(string arg) { string ans = md5Of(arg).toHexString(); writeln(ans); return ans; } ``` This compiles, and when run writes out corrupt nonsense fro

Re: std.digest toHexString

2017-03-16 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 16 March 2017 at 16:13:33 UTC, Carl Sturtivant wrote: string ans = md5Of(arg).toHexString(); That is a major D design flaw biting you the same way it has bitten so many others. See the red box in my documentation fork: http://dpldocs.info/experimental-docs/std.digest.digest

Re: Sorting Assosiative Arrays and Finding Largest Common Substring

2017-03-16 Thread thedeemon via Digitalmars-d-learn
On Thursday, 16 March 2017 at 16:02:13 UTC, helxi wrote: I was looking for ways to find the largest common substring between two given substrings and have learnt 1. .length is of type ulong Only when compiling to 64 bits. On 32-bit target it's different. 2. writing string[int] will not give

Re: Sorting Assosiative Arrays and Finding Largest Common Substring

2017-03-16 Thread XavierAP via Digitalmars-d-learn
On Thursday, 16 March 2017 at 16:02:13 UTC, helxi wrote: 1. .length is of type ulong Either use auto or if needed size_t. As Thedeemon says this is an alias of ulong on 64-bit and uint on 32. https://dlang.org/spec/hash-map.html

Re: std.digest toHexString

2017-03-16 Thread Carl Sturtivant via Digitalmars-d-learn
On Thursday, 16 March 2017 at 16:21:08 UTC, Adam D. Ruppe wrote: On Thursday, 16 March 2017 at 16:13:33 UTC, Carl Sturtivant wrote: string ans = md5Of(arg).toHexString(); That is a major D design flaw biting you the same way it has bitten so many others. See the red box in my documentat

Re: std.digest toHexString

2017-03-16 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Mar 16, 2017 at 04:21:08PM +, Adam D. Ruppe via Digitalmars-d-learn wrote: > On Thursday, 16 March 2017 at 16:13:33 UTC, Carl Sturtivant wrote: > > string ans = md5Of(arg).toHexString(); > > That is a major D design flaw biting you the same way it has bitten so > many others. > >

Re: std.digest toHexString

2017-03-16 Thread Carl Sturtivant via Digitalmars-d-learn
On Thursday, 16 March 2017 at 16:21:08 UTC, Adam D. Ruppe wrote: If I replace md5Of(arg).toHexString() with toHexString(md5Of(arg)) That works for me though... maybe it is just a version mismatch or something, since toHexString is in a different module than md5of. I have this problem on

Re: std.digest toHexString

2017-03-16 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 16 March 2017 at 16:47:14 UTC, Carl Sturtivant wrote: Silently cast to immutable without copying!??!! This is so wrong. It is the implicit slicing that I really want removed from the language, it serves no real benefit and brings a lot of accidental complexity. Casting the stati

Re: std.digest toHexString

2017-03-16 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 16 March 2017 at 16:56:11 UTC, Carl Sturtivant wrote: "toHexString.d(11): Error: function expected before (), not module toHexString of type void" Module??? huh idk. use my search engine btw! http://dpldocs.info/toHexString it is in `std.digest.digest` but that should be public

Re: std.digest toHexString

2017-03-16 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 16 March 2017 at 16:46:43 UTC, H. S. Teoh wrote: WAT?! Why does the language allow implicitly casting from static array to string?! How is that even remotely correct? Is there a bug filed for this? Yeah, somewhere, bugzilla search sucks but I know it is in there somewhere. We'

Re: std.digest toHexString

2017-03-16 Thread Carl Sturtivant via Digitalmars-d-learn
On Thursday, 16 March 2017 at 17:01:56 UTC, Adam D. Ruppe wrote: On Thursday, 16 March 2017 at 16:56:11 UTC, Carl Sturtivant wrote: "toHexString.d(11): Error: function expected before (), not module toHexString of type void" Module??? huh idk. use my search engine btw! http://dpldocs.info/t

Re: std.digest toHexString

2017-03-16 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 16 March 2017 at 17:12:08 UTC, Carl Sturtivant wrote: I did that, and it made no difference. :( wait a minute i just realized: toHexString.d(11) in the error message You named the file toHexString which means the *module* will be named toHexString by default... So using the na

Re: std.digest toHexString

2017-03-16 Thread Carl Sturtivant via Digitalmars-d-learn
On Thursday, 16 March 2017 at 16:59:40 UTC, Adam D. Ruppe wrote: Yet the documentation says there's a toHexString that returns a string. Yes, indeed, it returns a string if it is passed a dynamic array. Ah, that's the distinction, should have noticed. Remember though, like I warned on my do

Re: std.digest toHexString

2017-03-16 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Mar 16, 2017 at 04:59:40PM +, Adam D. Ruppe via Digitalmars-d-learn wrote: > On Thursday, 16 March 2017 at 16:47:14 UTC, Carl Sturtivant wrote: > > Silently cast to immutable without copying!??!! > > This is so wrong. > > It is the implicit slicing that I really want removed from the

Re: std.digest toHexString

2017-03-16 Thread Carl Sturtivant via Digitalmars-d-learn
On Thursday, 16 March 2017 at 17:18:30 UTC, Adam D. Ruppe wrote: On Thursday, 16 March 2017 at 17:12:08 UTC, Carl Sturtivant wrote: I did that, and it made no difference. :( wait a minute i just realized: toHexString.d(11) in the error message You named the file toHexString which means the *

Re: std.digest toHexString

2017-03-16 Thread Carl Sturtivant via Digitalmars-d-learn
On Thursday, 16 March 2017 at 17:20:45 UTC, H. S. Teoh wrote: I'm not convinced casting static array to immutable is OK. Check this out: import std.stdio; char[32] func() { char[32] staticArr = "A123456789abcdefB123456789abcdef"; return staticArr; // OK,

Re: std.digest toHexString

2017-03-16 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Mar 16, 2017 at 05:06:39PM +, Adam D. Ruppe via Digitalmars-d-learn wrote: [...] > In isolation, implicit slicing can make sense but not with > templates. In isolation, implicit immutable can make sense... but not > with implicit slicing. [...] Is implicit slicing the culprit in t

Re: std.digest toHexString

2017-03-16 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 16 March 2017 at 17:20:45 UTC, H. S. Teoh wrote: I'm not convinced casting static array to immutable is OK. Check this out: You aren't casting static array to immutable there, it is being implicitly sliced AND cased to immutable. What I mean is: char[32] s; immutable(char)[32]

Re: std.digest toHexString

2017-03-16 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 16 March 2017 at 17:40:51 UTC, H. S. Teoh wrote: Seems like the real cause of bug 17261 is implicit slicing. Yes, sorry, it took me 10 mins to type it up (I like to double check the current behavior before posting) but I think we both see it the same way now.

Re: std.digest toHexString

2017-03-16 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Mar 16, 2017 at 10:40:51AM -0700, H. S. Teoh via Digitalmars-d-learn wrote: [...] > Is implicit slicing the culprit in the issue I just filed? (Bug 17261) > > In retrospect, perhaps implicit casting to immutable is OK if we don't > allow implicit slicing: > > char[32] func() { char

Using packages: undefined reference to main

2017-03-16 Thread cloutiy via Digitalmars-d-learn
I'd like to try making a simple web app using vibrant.d, however I don't think I'm using it correctly since I'm getting a linking error when compiling. Below is my SDL with added vibrant.d dependency: name "cvmaker" description "A simple vibe.d server application." authors "drifter" copyright

Re: std.digest toHexString

2017-03-16 Thread via Digitalmars-d-learn
On Thursday, 16 March 2017 at 17:51:41 UTC, Adam D. Ruppe wrote: On Thursday, 16 March 2017 at 17:40:51 UTC, H. S. Teoh wrote: Seems like the real cause of bug 17261 is implicit slicing. Yes, sorry, it took me 10 mins to type it up (I like to double check the current behavior before posting)

Re: std.digest toHexString

2017-03-16 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 16 March 2017 at 17:20:10 UTC, Carl Sturtivant wrote: OK, but if I try to do this, char[2] u; string s = u; Yeah, that's because `u` is not necessarily unique like a function return value: char[2] u; char[] mutable = u[]; string s = u[]; char before = s[0]; mutable[0] = 'n';

Re: std.digest toHexString

2017-03-16 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 16 March 2017 at 17:47:34 UTC, H. S. Teoh wrote: Actually, the bug still exists even if you explicitly slice it: string x = func()[]; // still compiles, but shouldn't I don't call that a bug, once it is explicitly done it means the programmer realized something is up and

Re: std.digest toHexString

2017-03-16 Thread via Digitalmars-d-learn
On Thursday, 16 March 2017 at 18:07:09 UTC, Petar Kirov [ZombineDev] wrote: On Thursday, 16 March 2017 at 17:51:41 UTC, Adam D. Ruppe wrote: On Thursday, 16 March 2017 at 17:40:51 UTC, H. S. Teoh wrote: Seems like the real cause of bug 17261 is implicit slicing. Yes, sorry, it took me 10 mins

Re: std.digest toHexString

2017-03-16 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Mar 16, 2017 at 06:09:52PM +, Adam D. Ruppe via Digitalmars-d-learn wrote: > On Thursday, 16 March 2017 at 17:47:34 UTC, H. S. Teoh wrote: > > Actually, the bug still exists even if you explicitly slice it: > > > > string x = func()[]; // still compiles, but shouldn't > > I don't

Re: Using executeShell in multiple thread causes access violation error

2017-03-16 Thread Gomen via Digitalmars-d-learn
On Sunday, 19 July 2015 at 13:41:19 UTC, ketmar wrote: On Fri, 17 Jul 2015 22:53:55 +, Minas Mina wrote: bump sorry, i was wrong about GC non-calling. yet we still need more info: how long it works before crashing, how much threads it runs, how many "git clone" commands were ok before c

Re: std.digest toHexString

2017-03-16 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 16 March 2017 at 18:10:43 UTC, H. S. Teoh wrote: But in that case, wouldn't that mean implicit slicing isn't to blame here? (Not that I'm arguing for implicit slicing -- I think it needs to go, too, having been bitten by it before -- but this particular case wouldn't constitute as

Re: std.digest toHexString

2017-03-16 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 16 March 2017 at 18:07:09 UTC, Petar Kirov [ZombineDev] wrote: Why don't you use -dip1000??? Because it isn't the default. But even if it was, people would ask "why is this giving me an error?" and the same explanation would need to be given. Certainly, a compile error is better

Re: std.digest toHexString

2017-03-16 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Mar 16, 2017 at 06:41:40PM +, Adam D. Ruppe via Digitalmars-d-learn wrote: > On Thursday, 16 March 2017 at 18:10:43 UTC, H. S. Teoh wrote: > > But in that case, wouldn't that mean implicit slicing isn't to blame > > here? (Not that I'm arguing for implicit slicing -- I think it needs >

Re: std.digest toHexString

2017-03-16 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 16 March 2017 at 19:00:08 UTC, H. S. Teoh wrote: Actually, https://issues.dlang.org/show_bug.cgi?id=12625 shows that implicit slicing is still a problem: Oh yikes, I figured it would still be copied onto the local stack even though it is an rvalue. But you know, the fact that so

Re: std.digest toHexString

2017-03-16 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Mar 16, 2017 at 07:17:41PM +, Adam D. Ruppe via Digitalmars-d-learn wrote: > On Thursday, 16 March 2017 at 19:00:08 UTC, H. S. Teoh wrote: > > Actually, https://issues.dlang.org/show_bug.cgi?id=12625 shows that > > implicit slicing is still a problem: > > Oh yikes, I figured it would

Re: What is PostgreSQL driver is most stable?

2017-03-16 Thread Jacob Carlborg via Digitalmars-d-learn
On 2017-03-14 14:32, Suliman wrote: Does it work fine on Linux with x64 Postgres? I've tested it on macOS and Linux 64bit. Works great. -- /Jacob Carlborg

Re: std.digest toHexString

2017-03-16 Thread Carl Sturtivant via Digitalmars-d-learn
On Thursday, 16 March 2017 at 18:51:45 UTC, Adam D. Ruppe wrote: Phobos could have been written to avoid this problem too, there's a few solutions that work, but right now, using the standard library in a way people expect to work will be silently disastrous. Yes, and as an outsider I find th

Re: std.digest toHexString

2017-03-16 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, March 16, 2017 20:42:21 Carl Sturtivant via Digitalmars-d-learn wrote: > Implicitly slicing rvalue arrays is too much like implicitly > taking the address of an rvalue. Well, that's just it. That's _exactly_ what's happening. It's just that it ends up in a struct with a length member

Implementing casting outside of the target struct

2017-03-16 Thread David Zhang via Digitalmars-d-learn
Hi, I have two structs and want to cast between them. The cast is generalizable, so I want to keep it outside of the structs themselves (I'll be adding more later). How can I do this? I've tried the following so far: struct Event { EventID id; ubyte[32 - EventID.sizeof] p

Re: std.digest toHexString

2017-03-16 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Mar 16, 2017 at 02:36:15PM -0700, Jonathan M Davis via Digitalmars-d-learn wrote: [...] > Honestly, I think that it was a big mistake to have implicit slicing > of static arrays in the language at all. That makes at least 3 of us -- Adam, you, me. I'm sure there are more. > Unfortunatel

Re: Implementing casting outside of the target struct

2017-03-16 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Mar 16, 2017 at 09:36:31PM +, David Zhang via Digitalmars-d-learn wrote: > Hi, > > I have two structs and want to cast between them. The cast is > generalizable, so I want to keep it outside of the structs themselves > (I'll be adding more later). How can I do this? AFAIK, the opXXX(

Re: std.digest toHexString

2017-03-16 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Mar 16, 2017 at 06:51:45PM +, Adam D. Ruppe via Digitalmars-d-learn wrote: > On Thursday, 16 March 2017 at 18:07:09 UTC, Petar Kirov [ZombineDev] wrote: > > Why don't you use -dip1000??? > > Because it isn't the default. But even if it was, people would ask > "why is this giving me an

How to get inner most nested struct

2017-03-16 Thread Hussien via Digitalmars-d-learn
struct VARIANT { union { struct { VARTYPE vt; WORD wReserved1; WORD wReserved2; WORD wReserved3; union { int lVal; LONGLONG llVal; ubyte bVal; short iVal;

first try

2017-03-16 Thread Philip Miess via Digitalmars-d-learn
This is my first 100+ line D program. https://gitlab.com/pmiess/101gamesDlangComputerGames/blob/master/ aceyducy.d Its a translation/refactor of aceyducy from 101 basic programs. Could someone look over it and see if I've made any glaring mistakes. Suggestions are welcome also. Thanks, Phil

multi compare

2017-03-16 Thread Hussien via Digitalmars-d-learn
Instead of if (x == a || x == b || x = c || ) is there an easier way stuff like if (x in [a,b,c,..]) doesn't work.

Re: How to get inner most nested struct

2017-03-16 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 17 March 2017 at 00:34:22 UTC, Hussien wrote: Anyway to do this? I don't think you can, the inner anonymous structs are just to organize the members and group them inside the union.

Re: multi compare

2017-03-16 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 17 March 2017 at 00:39:15 UTC, Hussien wrote: if (x in [a,b,c,..]) import std.algorithm.comparison; x.among(a, b, c); http://dpldocs.info/experimental-docs/std.algorithm.comparison.among.1.html

bug in foreach continue

2017-03-16 Thread Hussien via Digitalmars-d-learn
foreach (y; aliasSeqOf!["a", "b", "c"]) { static if (y == "a") { } else pragma(msg, y); } works but foreach (y; aliasSeqOf!["a", "b", "c"]) { static if (y == "a") continue pragma(msg, y); } fails. Seems like continue needs to be static aware. This leads to subtle bugs where one thinks the co

Re: multi compare

2017-03-16 Thread Hussien via Digitalmars-d-learn
On Friday, 17 March 2017 at 01:27:01 UTC, Adam D. Ruppe wrote: On Friday, 17 March 2017 at 00:39:15 UTC, Hussien wrote: if (x in [a,b,c,..]) import std.algorithm.comparison; x.among(a, b, c); http://dpldocs.info/experimental-docs/std.algorithm.comparison.among.1.html thanks

Re: bug in foreach continue

2017-03-16 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 17 March 2017 at 01:34:52 UTC, Hussien wrote: Seems like continue needs to be static aware. That's not a bug, pragma is triggered when the code is *compiled*, not when it is run. The code is compiled, even if it is skipped over by a continue.

Re: How to get inner most nested struct

2017-03-16 Thread Hussien via Digitalmars-d-learn
On Friday, 17 March 2017 at 01:19:54 UTC, Adam D. Ruppe wrote: On Friday, 17 March 2017 at 00:34:22 UTC, Hussien wrote: Anyway to do this? I don't think you can, the inner anonymous structs are just to organize the members and group them inside the union. ;/ D should retain the structure in

Re: bug in foreach continue

2017-03-16 Thread Hussien via Digitalmars-d-learn
On Friday, 17 March 2017 at 01:41:47 UTC, Adam D. Ruppe wrote: On Friday, 17 March 2017 at 01:34:52 UTC, Hussien wrote: Seems like continue needs to be static aware. That's not a bug, pragma is triggered when the code is *compiled*, not when it is run. The code is compiled, even if it is ski

Re: first try

2017-03-16 Thread Ali Çehreli via Digitalmars-d-learn
I remember this game from many many years ago. :) On 03/16/2017 05:35 PM, Philip Miess wrote: This is my first 100+ line D program. https://gitlab.com/pmiess/101gamesDlangComputerGames/blob/master/ aceyducy.d Its a translation/refactor of aceyducy from 101 basic programs. Could someone look over

Re: first try

2017-03-16 Thread Jordan Wilson via Digitalmars-d-learn
On Friday, 17 March 2017 at 00:35:32 UTC, Philip Miess wrote: This is my first 100+ line D program. https://gitlab.com/pmiess/101gamesDlangComputerGames/blob/master/ aceyducy.d Its a translation/refactor of aceyducy from 101 basic programs. Could someone look over it and see if I've made any glar

Re: How to get inner most nested struct

2017-03-16 Thread bauss via Digitalmars-d-learn
On Friday, 17 March 2017 at 01:52:20 UTC, Hussien wrote: On Friday, 17 March 2017 at 01:19:54 UTC, Adam D. Ruppe wrote: On Friday, 17 March 2017 at 00:34:22 UTC, Hussien wrote: Anyway to do this? I don't think you can, the inner anonymous structs are just to organize the members and group th

Re: bug in foreach continue

2017-03-16 Thread Daniel Kozak via Digitalmars-d-learn
Dne 17.3.2017 v 02:34 Hussien via Digitalmars-d-learn napsal(a): foreach (y; aliasSeqOf!["a", "b", "c"]) { static if (y == "a") { } else pragma(msg, y); } works but foreach (y; aliasSeqOf!["a", "b", "c"]) { static if (y == "a") continue pragma(msg, y); } fails. Seems like continue needs to