Re: Question about operations on class/struct properties
All you said makes sense. If there is a direct connection between getter, setter and member than yes, returning it by reference is usually more convenient: private T _member; @property ref inout(T) member() inout {return _member;} However, sometimes, there is no direct connection between field and mutators. Sometimes, it is calculated on the fly. Date { ... @property auto hour() {return magic / someNumber;} @property void hour(int newHour) {//complicated algorithm to set the hour.} } Now, assuming we have these two mutators, operators could be automagically implemented. Date myDate; myDate.hour += 4; //myDate.hour(myDate.hour() + 4)
Re: Static function at module level
On Monday, 18 August 2014 at 17:42:37 UTC, ketmar via Digitalmars-d-learn wrote: On Mon, 18 Aug 2014 06:46:02 + bearophile via Digitalmars-d-learn wrote: accepting useless code confuses newbies i think that i'm not really a newbie now ;-), but i'm still used to declare various private module functions and variables as 'static'. yes, sometimes this confuses me (as to "do i need to make this sta... ah, scrap that, it's D!"), but sometimes this is handy. why? i'm still have to use C sometimes, and i'm writing 'static' automatically. having compiler to accept it for anything high-level saves me one regexp search-and-replace. ;-) I don't think he meant you personally. Well, I hope not. I was confused by it too and I don't consider myself a D newbie. I get that it is convenient for you. I have done a lot of C myself. However, convenience loses to misleading in my book. Consider that in the future, for example, "static interface Toto{}" means something different than "interface Toto{}". I am not debating whether or not that would ever happen or what would even be the meaning of a static interface (even though I have an idea), the point is more like this: every compiler version will accept both versions of said interface, but some of those compiler will interpret it differently. Now that's a problem. Philz
Re: Static function at module level
On Monday, 18 August 2014 at 14:23:47 UTC, bearophile wrote: H. S. Teoh: Is there a bug filed for this? Probably there is. But I stopped filing similar bugs because they seem to have a very low priority. Bye, bearophile I looked around for it but didn't find it. I filed this one: https://issues.dlang.org/show_bug.cgi?id=13322 As you'll see, every type of module level declaration accepts static. static int x; static void myFunc(){} static interface MyInterface{} static class MyClass{} static struct MyStruct{} static template myTemplate{} And maybe I am missing some.
Re: Static function at module level
On Monday, 18 August 2014 at 05:29:53 UTC, Jonathan M Davis via Digitalmars-d-learn wrote: On Mon, 18 Aug 2014 01:32:40 + Phil Lavoie via Digitalmars-d-learn wrote: Ok, so after years of D usage I just noticed that this is valid D (compiles anyways): static void myFunc() {} What is a static function at module level exactly? In C, that means private, in D, that means ___? I'm pretty sure that it means nothing. It's just one of those cases where an attribute is ignored, because it doesn't apply rather than resulting in an error. - Jonathan M Davis All right thanks!
Re: Static function at module level
On Monday, 18 August 2014 at 06:46:03 UTC, bearophile wrote: ketmar: other function declarations (methods, nested functions) accepts 'static', so why free functions shouldn't? For various reasons, one of them is that accepting useless code confuses newbies and doesn't allow them to build a correct model of the D semantics in their head. Bye, bearophile Agreed. I was misled for a minute. I don't think it should compile.
Static function at module level
Ok, so after years of D usage I just noticed that this is valid D (compiles anyways): static void myFunc() {} What is a static function at module level exactly? In C, that means private, in D, that means ___? Thanks, Phil
Re: Nullable instantiator anyone?
On Sunday, 17 August 2014 at 19:05:11 UTC, Nordlöw wrote: On Sunday, 17 August 2014 at 18:51:38 UTC, bearophile wrote: It could be sufficient, but note that in Phobos there are two different versions of Nullable, one of them doesn't require extra memory, it uses one value as the "null" value. Ok, thanks for the reminder. Do you have a suggestion of an instantiator for this variant? I'm not sure how to define this. So far I have Nullable!T nullable(T nullValue, T)(T a, T nullValue) { return Nullable!nullValue(a); } unittest { auto x = nullable!(int.max)(3); } but it fails as mangling.d(50,21): Error: undefined identifier T How do I make the template parameter nullValue infer type T with a single template parameter? Is it even possible? Hi Nordlöw, I'm not sure I fully understand your question but I'll try and answer it. First of all, yes, you can have everything inferred as long as your produce a default value for your null value, a.k.a: Nullable!(T, nullValue) nullable(T, T nullValue = T.init)(T val) { return Nullable!(T, nullValue)(val); } unittest{ auto myNullableInt = nullable(5); assert(!myNullableInt.isNull() && myNullableInt == 5); } However, keep in mind that using a sentinel value as the null value can produce surprises: unittest{ auto myNullableInt = nullable(0); assert(myNullableInt.isNull()); //Since T.init == 0 } Phil
Re: Need help with building dmd
On Thursday, 7 August 2014 at 02:13:38 UTC, Brad Anderson wrote: On Thursday, 7 August 2014 at 01:50:50 UTC, Phil Lavoie wrote: On Thursday, 7 August 2014 at 01:37:46 UTC, Brad Anderson wrote: On Thursday, 7 August 2014 at 01:27:55 UTC, Phil Lavoie wrote: Nope, still not working, but thx. Hmm, are you in the src directory? Yes and ls *.mak shows three makefiles: osmodel.mak posix.mak win32.mak ls? If you're not, I recommend using the cmd.exe terminal. optlink has had problems with using other terminals. You may want to look at this guide if you haven't already: http://wiki.dlang.org/Building_DMD Yeah I read that thx. Well, it seems like it was indeed the powershell that was troubling it. Just tried it with cmd and it seems to work. Thx Brad, Phil
Re: Need help with building dmd
On Thursday, 7 August 2014 at 01:37:46 UTC, Brad Anderson wrote: On Thursday, 7 August 2014 at 01:27:55 UTC, Phil Lavoie wrote: Nope, still not working, but thx. Hmm, are you in the src directory? Yes and ls *.mak shows three makefiles: osmodel.mak posix.mak win32.mak
Re: Need help with building dmd
On Thursday, 7 August 2014 at 01:18:52 UTC, Brad Anderson wrote: On Thursday, 7 August 2014 at 01:15:36 UTC, Phil Lavoie wrote: [...] make release -fwin32 Here is the output: Error: can't read makefile 'win32' I'm building on Windows btw. Thanks, Phil Close. You need the extension, I believe. make -f win32.mak release Nope, still not working, but thx.
Need help with building dmd
I'm trying to build dmd from source but "make" can't open the makefile. I checked out the source and everything and the make version I use is the one that comes with the distribution: Digital Mars Make Version 5.06 So I'm in the source folder (...\dmd2\src\dmd\src), I can clearly see that there is the file win32.mak present and I run: make release -fwin32 Here is the output: Error: can't read makefile 'win32' I'm building on Windows btw. Thanks, Phil