Re: What about an identifier that is an mixin
On Friday, 13 January 2017 at 21:32:49 UTC, Daniel Kozák wrote: Daniel Kozáknapsal Pá, led 13, 2017 v 10∶29 : André Puel via Digitalmars-d napsal Pá, led 13, 2017 v 10∶15 : One thing that I miss sometimes when doing meta programming is being able to hide that a function should be called with mixin. For example (pardon my lack of creativity): // Instead of string declare_a() { return "int a;" } int func() { mixin(declare_a); return a; } // Could we have? mixin declare_a() { return "int a;"; } int func() { declare_a; return a; } I think this could be useful when one is creating Idiom and Patterns, you could hide implementations details. You can do this: mixin template declare_a() { int a; } int func() { mixin declare_a; return a; } but there is no way to exclude mixin before calling declare_a, there is a good reason for that (it is really important to be able to tell when you use mixin and when not) Right now you can even use template declare_a() {...} there is no difference between template and mixin template That's not true. Templates do not carry context with them, they only have their own scope available. Where as mixin templates can access every member that is in their scope. Consider: template SetXCTFE_Template(int value) { void SetXCTFE_Template() { x = value; } } mixin template SetXCTFE_Mixin_Template(int value) { void handle() { x = value; } } void main() { int x; x = SetXCTFE_Template!10; // Not ok ... mixin SetXCTFE_Mixin_Template!10; // ok ... handle(); // ok ... }
[Issue 3947] Implicit and explicit casting of floating point to bool produces different results
https://issues.dlang.org/show_bug.cgi?id=3947 ZombineDevchanged: What|Removed |Added CC||petar.p.ki...@gmail.com --
Re: Gui in D: I miss this project
On 2017-01-09 22:41, aberba wrote: This seemed to be an effort (among others) to bring GUI cross platform to standard D but some language/compiler/Phobos/Deimos/manpower issues were the drag. https://github.com/Devisualization We now have DLangUI. I wonder what the current drag is. There's DWT [1] as well. Works on Windows and Linux, uses native drawing. [1] https://github.com/d-widget-toolkit/dwt -- /Jacob Carlborg
Re: Gui in D: I miss this project
On 2017-01-16 07:28, Vadim Lopatin wrote: Windows support in DlangUI is not native since it does not use native controls. DlangUI draws widgets itself on all platforms. But on Win32 it's possible to build app which uses Win32 API only, and no additional DLLs will be required to run it. On Linux and Mac, there is extra dependency - libSDL2. For most application on macOS, a non-native GUI library is not interesting. -- /Jacob Carlborg
Re: How to repeat structure C++
On Monday, 16 January 2017 at 00:07:44 UTC, Adam D. Ruppe wrote: That's just interfaces and classes in D, so change struct to those words and go fro there. // --- jd.d: compile: dmd -c jd import std.stdio; extern (C++) interface IHome { int sum(int, int); }; extern (C++) void printIHome(void* ptr) { IHome ob = cast(jd.IHome)ptr; ob.sum(4, 5); } // --- jc.cpp compile: dmc jc.cpp jd.obj phobos.lib #include struct IHome { int sum(int a, int b) { int s = a+b; printf("a = %d, b = %d, sum = %d\n", a, b, s); return s; } }; extern "C" intrt_init(); extern "C" intrt_term(); extern void printIHome(void*); void main() { IHome iMyHome; rt_init(); // --- iMyHome.sum(2, 3); // Call C++ method in C++ IHome* ptriMyHome = printIHome(ptriMyHome);// Call C++ method in D --> ERROR :-( // --- rt_term(); } // compile -- dmd -c jd dmc jc.cpp jd.obj r:\dmd2\windows\lib\phobos.lib // --- Please, help to rewrite jd.d for the correct method call in structure С++.
Re: Quine using strings?
On Sunday, 15 January 2017 at 19:43:22 UTC, Nestor wrote: I was reading some of the examples of writing a quine with D, but apparently the language has evolved and they no longer compiled unchanged. So I tried to program one by myself using strings and std.stdio, but the result seems long and redundant: import std.stdio;void main(){string s=`import std.stdio;void main(){string s=writefln("%s\x60%s\x60;s",s[0..38],s,s[38..$]);}`;writefln("%s\x60%s\x60;%s",s[0..38],s,s[38..$]);} Any ideas for a shorter version (preferably without using pointers)? I remember on Rosetta to have seen this: module quine; import std.stdio; void main(string[] args) { write(import("quine.d")); } compiles with: dmd path/quine.d -Jpath
Re: Gui in D: I miss this project
On Saturday, 14 January 2017 at 10:58:38 UTC, Dukc wrote: Which platforms do dlangui work on? It's console feature is cool, I do that with terminal.d rather than simpledisplay.d. I guess the other difference is probably Mac, I only support it there with the X11 thing installed, which Apple no longer supports. I kinda want to wait till there's Objective-C integration in there though. If I understood the package description correctly, it supports Windows, Linux and Mac. Windows natively, so the complains about non-nativity are only partially true. Plus at least Mac native support is worked on. I also read somewhere, perhaps the official blog, that it works with Android at least to some extent. Windows support in DlangUI is not native since it does not use native controls. DlangUI draws widgets itself on all platforms. But on Win32 it's possible to build app which uses Win32 API only, and no additional DLLs will be required to run it. On Linux and Mac, there is extra dependency - libSDL2.
[Issue 17096] New: many traits accept an invalid parameter count without error
https://issues.dlang.org/show_bug.cgi?id=17096 Issue ID: 17096 Summary: many traits accept an invalid parameter count without error Product: D Version: D2 Hardware: All OS: All Status: NEW Severity: minor Priority: P1 Component: dmd Assignee: nob...@puremagic.com Reporter: b2.t...@gmx.com By error, if you don't know well the spec, this scenario is quite possible: class B{final void foo(){} enum a =__traits(isFinalFunction, B, "foo"); instead of __traits(isFinalFunction, B.foo); // ok --
Re: Gui in D: I miss this project
On Friday, 13 January 2017 at 22:55:03 UTC, Adam D. Ruppe wrote: On Friday, 13 January 2017 at 20:11:08 UTC, Dukc wrote: Does not work on as many platforms as DlangUI, trough. Which platforms do dlangui work on? It's console feature is cool, I do that with terminal.d rather than simpledisplay.d. I guess the other difference is probably Mac, I only support it there with the X11 thing installed, which Apple no longer supports. I kinda want to wait till there's Objective-C integration in there though. DlangUI platforms: Win, Linux, OSX, Android. It's easy to add new platforms (each new platform requires writing 2-3K lines of code).
[Issue 17095] New: Have issues with std.bigint on Ubuntu 32-bit
https://issues.dlang.org/show_bug.cgi?id=17095 Issue ID: 17095 Summary: Have issues with std.bigint on Ubuntu 32-bit Product: D Version: D2 Hardware: x86 OS: Linux Status: NEW Severity: normal Priority: P1 Component: phobos Assignee: nob...@puremagic.com Reporter: virgil_...@yahoo.com Using Ubuntu 14.04, x86 - DMD32 D Compiler v2.072.2 Encountered the following error when trying to compile IP2Location.d codes from https://github.com/ip2location/ip2location-d/blob/master/source/ip2location-d/ip2location.d Error below: ip2location-d 8.0.3: building configuration "library"... /usr/include/dmd/phobos/std/internal/math/biguintx86.d(231,14): Error: asm statements cannot be interpreted at compile time /usr/include/dmd/phobos/std/internal/math/biguintcore.d(1758,52):called from here: multibyteIncrementAssign(data[0..hi], cast(uint)(y & 4294967295LU)) /usr/include/dmd/phobos/std/internal/math/biguintcore.d(448,40):called from here: biguintFromDecimal(tmp, s) /usr/include/dmd/phobos/std/bigint.d(112,40):called from here: this.data.fromDecimalString(filterBidirectional(codeUnits)) ../../../../.dub/packages/ip2location-d-8.0.3/ip2location-d/source/ip2location-d/ip2location.d(78,47): called from here: BigInt(BigUint([0u]), false).this("340282366920938463463374607431768211455") dmd failed with exit code 1. Have tested with Ubuntu 14.04 64-bit and it's working fine. --
[Issue 17080] Can assign member-function-ptr to free-function-ptr
https://issues.dlang.org/show_bug.cgi?id=17080 --- Comment #8 from Sprink--- Why bother fixing this issue by just changing the type to a delegate? You are just making a temporary fix that has the potential to break code out there. Then you are just going to have to cause the same breakage when the actual underlying issue is fixed. This really shouldn't be half-assed. If you are going to do anything, make taking the address of a member function without an object an error. That way it'll cause the same breakage but then people won't continue to use it and won't cause a second breakage. --
[Issue 17094] New: std.container.binaryheap doesn't manage store length consistently when inserting
https://issues.dlang.org/show_bug.cgi?id=17094 Issue ID: 17094 Summary: std.container.binaryheap doesn't manage store length consistently when inserting Product: D Version: D2 Hardware: All URL: http://dlang.org/ OS: All Status: NEW Severity: normal Priority: P3 Component: phobos Assignee: nob...@puremagic.com Reporter: jrdemail2000-dl...@yahoo.com When inserting into a BinaryHeap, the underlying data "store" length may or may not be updated, depending the type of container used and whether there is already capacity. This leaves the data store in a state where cannot be used. This appears to be a bug, described used cases indicate the store can be accessed, implying the length should be correct. A unit test example from the documentation: import std.algorithm.comparison : equal; int[] a = [ 4, 1, 3, 2, 16, 9, 10, 14, 8, 7 ]; auto h = heapify(a); assert(h.front == 16); assert(equal(a, [ 16, 14, 10, 8, 7, 9, 3, 2, 4, 1 ])); The last line is accessing the data store. This program has the above, then follows with the same notion, but done by inserting elements into an existing heap instead: void main(string[] args) { import std.container.binaryheap; import std.algorithm.comparison : equal; /* Current unit test. */ int[] a = [ 4, 1, 3, 2, 16, 9, 10, 14, 8, 7 ]; auto h = heapify(a); assert(h.front == 16); assert(equal(a, [ 16, 14, 10, 8, 7, 9, 3, 2, 4, 1 ])); /* Same, but using insert. Fails on last line. */ int[] vals = [ 4, 1, 3, 2, 16, 9, 10, 14, 8, 7 ]; int[] b; auto h2 = heapify(b); foreach (v; vals) h2.insert(v); assert(h2.front == 16); assert(equal(b, [ 16, 14, 10, 8, 7, 9, 3, 2, 4, 1 ])); // Fails } Documentation for binaryheap implies throughout that structure is being applied to the underlying data store, and that this can be accessed. A specific use case where this is problematic is when extracting the elements to reorder the underlying data store. From the documentation: Extracting elements from the BinaryHeap to completion leaves the underlying store sorted in ascending order but, again, yields elements in descending order. This is useful when identifying a top-k set of elements, then want to access in ascending order, which is the order of the data store in the description above. However, because the data store length is not correctly set, it cannot be accessed normally. The below program has some diagnostics. It inserts in heaps built with both dynamics arrays and std.container.array.Array. It also shows the difference when capacity has and has not been preallocated. When run, it shows that the underlying data store gets updated when an std.container.array.Array is used and preallocated with reserve(), not otherwise the lengths are not updated. --bug_binaryheap.h- void main(string[] args) { import std.container.binaryheap; import std.container.array; import std.stdio; int[] vals = [3, 8, 9, 2, 6, 4, 5, 1, 7]; int[] storeX; int[] storeXRes; Array!int storeY; Array!int storeYRes; storeXRes.reserve(vals.length); storeYRes.reserve(vals.length); writeln(" X XRes Y YRes"); writeln("Before heapify"); writefln(" Store capacity:%2d %2d %2d %2d", storeX.capacity, storeXRes.capacity, storeY.capacity, storeYRes.capacity); auto heapX= heapify(storeX, 0); auto heapXRes = heapify(storeXRes, 0); auto heapY= heapify(storeY, 0); auto heapYRes = heapify(storeYRes, 0); writeln("After heapify"); writefln(" Heap lengths: %2d %2d %2d %2d", heapX.length, heapXRes.length, heapY.length, heapYRes.length); writefln(" Store lengths: %2d %2d %2d %2d", storeX.length, storeXRes.length, storeY.length, storeYRes.length); writefln(" Heap capacity: %2d %2d %2d %2d", heapX.capacity, heapXRes.capacity, heapY.capacity, heapYRes.capacity); writefln(" Store capacity:%2d %2d %2d %2d", storeX.capacity, storeXRes.capacity, storeY.capacity, storeYRes.capacity); foreach (v; vals) { heapX.insert(v); heapXRes.insert(v); heapY.insert(v); heapYRes.insert(v); } writeln("After inserts"); writefln(" Heap lengths %2d %2d %2d %2d", heapX.length, heapXRes.length, heapY.length, heapYRes.length); writefln(" Store lengths: %2d %2d %2d %2d", storeX.length, storeXRes.length, storeY.length, storeYRes.length); writefln(" Heap capacity: %2d %2d %2d %2d", heapX.capacity, heapXRes.capacity, heapY.capacity, heapYRes.capacity); writefln(" Store capacity:%2d %2d %2d %2d", storeX.capacity, storeXRes.capacity,
[Issue 17093] gdc compilation performance on the Raspbery Pi leaves to be desired
https://issues.dlang.org/show_bug.cgi?id=17093 --- Comment #2 from Ion Todirel--- P.S. running Raspbian Jessie --
[Issue 16527] extern( C++ ) Win64 build - return struct by value is broken
https://issues.dlang.org/show_bug.cgi?id=16527 Sprinkchanged: What|Removed |Added CC||sprink.nore...@gmail.com --- Comment #2 from Sprink --- The problem is that there's no way to properly model a pointer to a member function to C++ from D. You can't use a delegate as it isn't supported with extern(C++). So there's no way for it to know that the parameter you are passing is actually a "this". Taking the address of a member function without an object is also broken (#3720). --
[Issue 17093] gdc compilation performance on the Raspbery Pi leaves to be desired
https://issues.dlang.org/show_bug.cgi?id=17093 --- Comment #1 from Ion Todirel--- This is a Raspberry Pi 3 --
[Issue 17093] New: gdc compilation performance on the Raspbery Pi leaves to be desired
https://issues.dlang.org/show_bug.cgi?id=17093 Issue ID: 17093 Summary: gdc compilation performance on the Raspbery Pi leaves to be desired Product: D Version: D2 Hardware: Other OS: Linux Status: NEW Severity: enhancement Priority: P1 Component: tools Assignee: nob...@puremagic.com Reporter: iontodi...@gmail.com gdc seems much slower than gcc on Raspberry Pi, I don't know what other detail to provide --
Re: Quine using strings?
A quine I came up with a while ago, using q{} string notation: enum s = q{enum s = q{%s}; void main() { import std.stdio; writefln(s,s); }}; void main() { import std.stdio; writefln(s,s); }
Re: Is it ok to inherit multiple times same templated interface?
On Sunday, 15 January 2017 at 20:33:30 UTC, Alexandru Ermicioi wrote: Currently doing so is allowed, though, it is impossible to call implemented methods directly from implementation. You should be able to do obj.Wr!(ubyte).get() too.
[Issue 17072] [REG 2.073.0-b1] missing symbols with -inline
https://issues.dlang.org/show_bug.cgi?id=17072 --- Comment #3 from Walter Bright--- https://github.com/dlang/dmd/pull/6452 --
Re: Silvermirror to mirror websites
On Sunday, 15 January 2017 at 23:32:34 UTC, Chris Wright wrote: On Sun, 15 Jan 2017 21:30:47 +, Nick B wrote: I'm still on 2.071.1. Are you experiencing issues on another version? No, just checking. Thanks Nick
[Issue 17072] [REG 2.073.0-b1] missing symbols with -inline
https://issues.dlang.org/show_bug.cgi?id=17072 --- Comment #2 from Walter Bright--- (In reply to Rainer Schuetze from comment #0) > This does not happen with dmd 2.072 or without -inline. It does work if you throw -dip25. Still a regression, though. --
Re: SmartRef: The Smart Pointer In D
On Sunday, 15 January 2017 at 17:24:25 UTC, biozic wrote: On Sunday, 15 January 2017 at 15:56:30 UTC, Dsby wrote: and : In https://github.com/dlang/phobos/blob/master/std/typecons.d#L147 ~this() { debug(Unique) writeln("Unique destructor of ", (_p is null)? null: _p); if (_p !is null) destroy(_p); _p = null; } if the 'T' is a struct, it will not exec the Destory function. Is it a bug? What do you mean? This works for me: --- import std.stdio, std.typecons; struct Foo { ~this() { writeln("I'm destroyed"); } } void main() { Unique!Foo foo = new Foo; } // Prints "I'm destroyed" --- the "writeln("I'm destroyed");" not run the ~this in the Unique destroy function. it run in the app exit , THe GC distroy all memony. it example can show : import std.stdio; import std.typecons; struct Foo { ~this() { writeln("I'm destroyed"); } } void fun(){ Unique!Foo foo = new Foo; writeln("exit the fun."); } void main() { fun(); writeln("exit the Main."); } It is the printf: ~/tmp rdmd ./type.d 2017年01月16日 星期一 09时50分00秒 exit the fun. exit the Main. I'm destroyed ~/tmp if you use the struct in Unique, the struct's Destory function is not run in the Unique destroy, it is also run in the GC collet. I think it is not the Unique should be.
Re: Android LDC in a Container
On Sunday, 15 January 2017 at 17:40:01 UTC, Andre Pany wrote: Hi, on Dockerhub I published a repository which makes it really easy to develop Android applications using LDC and Joakims work. The repository contains Android 1.1.0 beta from https://github.com/joakim-noah/android/releases and also the NDK from google. [...] it is Great!
Re: Pry v0.3.1 is out!
On Sunday, 15 January 2017 at 01:26:07 UTC, Dmitry Olshansky wrote: Pry is a new pragmatic parser combinators library. https://github.com/DmitryOlshansky/pry Interesting. How about left-recursion? (I added support for left-recursive grammars to Pegged.)
Re: How to repeat structure C++
On Sunday, 15 January 2017 at 19:05:06 UTC, MGW wrote: struct IInterface {}; struct IMsgBox : public IInterface { virtual bool Confirm(const wchar* queryText, tVariant* retVal) = 0; virtual bool Alert(const wchar* text) = 0; }; That's just interfaces and classes in D, so change struct to those words and go fro there.
Re: Accessing a function within an object's superclass from the outside
On Sunday, 15 January 2017 at 02:32:29 UTC, Meta wrote: Is this documented anywhere? I had no idea this was a feature. Used in some examples here: http://dlang.org/spec/class.html
Re: Quine using strings?
On Sunday, 15 January 2017 at 22:35:26 UTC, Nestor wrote: You forgot to include the program... or is this a joke? ;) Neither: the empty program compiles and runs, outputting nothing. Since its empty output matches its empty source file, it technically fits the definition of the quine :)
Re: Silvermirror to mirror websites
On Sun, 15 Jan 2017 21:30:47 +, Nick B wrote: > On Sunday, 15 January 2017 at 02:28:34 UTC, Chris Wright wrote: >> Github: https://github.com/dhasenan/silvermirror >> >> Silvermirror is a tool to mirror websites -- download them locally and >> serve copies of them. > > > What is the version of D that Silvermirror is compiled under ? > > Nick I'm still on 2.071.1. Are you experiencing issues on another version?
Re: Is it ok to inherit multiple times same templated interface?
On Sunday, 15 January 2017 at 20:33:30 UTC, Alexandru Ermicioi wrote: Good day, Given following code example, where a templated interface Wr, and an implementation Im is present: interface Wr(T) { T get(); } class Im(T : ubyte) : Wr!ubyte, Wr!ushort, Wr!string { public T t; ubyte get() { return cast(ubyte) this.t; } ushort get() { return cast(ushort) this.t; } string get() { import std.conv; return this.t.to!string ~ " with testings"; } } void main() { auto i = new Im!ubyte; i.t = 20; assert((cast(Wr!ubyte) i).get == 20); assert((cast(Wr!ushort) i).get == 20); assert((cast(Wr!string) i).get == "20 with testings"); } Is it ok (not undefined behavior), to have Im implementing multiple times interface Wr, with different template arguments? Or doing so, will eventually lead to subtle bugs? Currently doing so is allowed, though, it is impossible to call implemented methods directly from implementation. Only by casting i to different implemented interfaces (Wr!ubyte, Wr!ushort, and Wr!string), is possible to call each implemented get method. Thanks. How would overloading work? Overload resolution works based on function/method parameters, not return types. In the example you gave the 3 get functions are indistinguishable. If the template parameter was used for a method parameter type, then they would be distinguishable. See overloading functions here [0]. I think yours only works with the cast because function parameters, including the _this_ pointer is taken into account. [0] https://dlang.org/spec/function.html#function-overloading
[Issue 16483] ICE in expression.d from typeof
https://issues.dlang.org/show_bug.cgi?id=16483 bitter.ta...@gmx.com changed: What|Removed |Added CC||bitter.ta...@gmx.com --- Comment #2 from bitter.ta...@gmx.com --- Covered by DMD's PR https://github.com/dlang/dmd/pull/6451 --
[Issue 15690] [ICE] backend/symbol.c 1032
https://issues.dlang.org/show_bug.cgi?id=15690 b2.t...@gmx.com changed: What|Removed |Added CC||b2.t...@gmx.com --- Comment #1 from b2.t...@gmx.com --- This case is deprecated now, should this issue be closed then ? --
[Issue 15734] Need this for map
https://issues.dlang.org/show_bug.cgi?id=15734 b2.t...@gmx.com changed: What|Removed |Added Status|NEW |RESOLVED CC||b2.t...@gmx.com Resolution|--- |INVALID --- Comment #3 from b2.t...@gmx.com --- foo is a member function but map takes an alias to a function that must be known at compile time. change definition to static int foo(int a) { return a; } and it works --
Re: Convert duration to years?
Thank you all.
Re: Quine using strings?
On Sunday, 15 January 2017 at 22:08:47 UTC, pineapple wrote: On Sunday, 15 January 2017 at 21:37:53 UTC, Nestor wrote: Any ideas for a shorter version (preferably without using pointers)? When compiling with the -main flag, this D program is a quine: You forgot to include the program... or is this a joke? ;)
Re: Quine using strings?
On Sunday, 15 January 2017 at 21:37:53 UTC, Nestor wrote: Any ideas for a shorter version (preferably without using pointers)? When compiling with the -main flag, this D program is a quine:
Re: Pry v0.3.1 is out!
On Sunday, 15 January 2017 at 13:14:45 UTC, Dmitry Olshansky wrote: I could have wasted time by creating nodes and assigning values in the map functions but if you just want the result of calculation it's all moot. Thanks for explanation! This is indeed very promising and much in spirit of D selling point of zero-overhead convenience abstractions.
Re: Pry v0.3.1 is out!
On 1/15/17 2:26 AM, Dmitry Olshansky wrote: Pry is a new pragmatic parser combinators library. [snip] Two key areas of focus are (compared to say Pegged): - performance, on par with hand-written code or die Actually testing the latest version with LDC I found out that handwritten code is a bit *slower*. Beats me, as I spent quite some time laying out that handwritten stuff. All in all, this makes me confident that I soon will never have to write parsers by hand, the last nebulous reason is out. --- Dmitry Olshansky
[Issue 16483] ICE in expression.d from typeof
https://issues.dlang.org/show_bug.cgi?id=16483 b2.t...@gmx.com changed: What|Removed |Added CC||b2.t...@gmx.com --- Comment #1 from b2.t...@gmx.com --- As a workaround it's possible to mark the free function as "static". There's a more interesting error message with this similar example: struct S { enum a = bar!(x=>x)(true); } /*static*/ bool bar(alias foo)(bool b) { return foo(b); } --
Re: Silvermirror to mirror websites
On Sunday, 15 January 2017 at 02:28:34 UTC, Chris Wright wrote: Github: https://github.com/dhasenan/silvermirror Silvermirror is a tool to mirror websites -- download them locally and serve copies of them. What is the version of D that Silvermirror is compiled under ? Nick
Re: Is it ok to inherit multiple times same templated interface?
On Sunday, 15 January 2017 at 20:33:30 UTC, Alexandru Ermicioi wrote: Good day, Given following code example, where a templated interface Wr, and an implementation Im is present: From the standpoint of the compiler they are 3 distinct interfaces, so all is good. interface Wr(T) { T get(); } [...]
[Issue 17055] this(...) hides this() of mixed in template
https://issues.dlang.org/show_bug.cgi?id=17055 b2.t...@gmx.com changed: What|Removed |Added CC||b2.t...@gmx.com --- Comment #1 from b2.t...@gmx.com --- minimal example ? --
[Issue 15603] ICE in cgxmm.c 647
https://issues.dlang.org/show_bug.cgi?id=15603 b2.t...@gmx.com changed: What|Removed |Added Status|NEW |RESOLVED Resolution|--- |FIXED --
Re: Convert duration to years?
On Sunday, January 15, 2017 03:43:32 Nestor via Digitalmars-d-learn wrote: > Hi, > > I would simply like to get someone's age, but I am a little lost > with time and date functions. I can already get the duration, but > after reading the documentation it's unclear to me how to convert > that into years. See following code: > > import std.stdio; > > void getAge(int , int mm, int dd) { >import std.datetime; >SysTime t1 = SysTime(Date(, mm, dd)); >SysTime t2 = Clock.currTime(); >writeln(t2 - t1); > } > > int main() { >try > getAge(1980, 1, 1); >catch(Exception e) { > writefln("%s.\n(%s, line %s)", e.msg, e.file, e.line); >} > } > > Notice getAge should return ubyte instead of void, only I haven't > been able to find how to do it. Any suggestion would be welcome. > > Thanks in advance. Well, there's diffMonths: http://dlang.org/phobos/std_datetime.html#.SysTime.diffMonths However, I doubt that it really does quite what you want. Because of the varying lengths of months and years, you're probably going to have to write code that does what you want with some combination of function. You probably want to do something like void getAge(int , int mm, int dd) { auto birthdate = Date(, mm, dd); auto currDate = cast(Date)Clock.currTime; // This make Feb 29th become March 1st auto birthdayThisYear = Date(currDate.year, mm, 1) + days(dd - 1); auto years = currDate.year - birthdate.year; if(currDate < birthdayThisYear) --years; writeln(years); } I _think_ that that does it, but I'd want to do something like void printAge(int , int mm, int dd) { writeln(getAge(cast(Date)Clock.currTime(), , mm, dd); } int getAge(Date currDate, int , int mm, int dd) { auto birthdate = Date(, mm, dd); auto currDate = cast(Date)Clock.currTime; // This make Feb 29th become March 1st auto birthdayThisYear = Date(currDate.year, mm, 1) + days(dd - 1); auto years = currDate.year - birthdate.year; if(currDate < birthdayThisYear) --years; return years; } and then add unit tests for getAge to verify that it did the correct thing for various dates. It's quite possible that there's something subtley wrong with it. Also, depending on what exactly you're trying to do, it's possible that I didn't quite understand what you're trying to do and that it needs some additional tweaks in order to do what you want. - Jonathan M Davis
Re: Beta 2.073.0-b1
On Sunday, 15 January 2017 at 06:07:23 UTC, Walter Bright wrote: Phobos is next! I can't wait :)
Re: Querying parameter passing semantics for `auto ref const` variables
On Sunday, 15 January 2017 at 17:41:36 UTC, Nordlöw wrote: This struct S { int x, y; } void f()(auto ref const S s) { pragma(msg, "type:", typeof(s), " isRef:", isRef!s); } f(S.init); S s; f(s); prints type:const(S) isRef:false type:const(S) isRef:true given that enum isRef(alias fn) = __traits(isRef, fn); :)
Re: Parsing a UTF-16LE file line by line, BUG?
On Sunday, 15 January 2017 at 16:29:23 UTC, Daniel Kozák wrote: This is because byLine does return range, so until you do something with that it does not cause any harm :) I see. So correcting my original doubt: How could I parse an UTF16LE file line by line (producing a proper string in each iteration) without loading the entire file into memory?
Quine using strings?
I was reading some of the examples of writing a quine with D, but apparently the language has evolved and they no longer compiled unchanged. So I tried to program one by myself using strings and std.stdio, but the result seems long and redundant: import std.stdio;void main(){string s=`import std.stdio;void main(){string s=writefln("%s\x60%s\x60;s",s[0..38],s,s[38..$]);}`;writefln("%s\x60%s\x60;%s",s[0..38],s,s[38..$]);} Any ideas for a shorter version (preferably without using pointers)?
Re: Convert duration to years?
On Sunday, 15 January 2017 at 16:57:35 UTC, biozic wrote: On Sunday, 15 January 2017 at 14:20:04 UTC, Nestor wrote: On second thought, if a baby was born in march 1 of 1999 (non-leap year), in march 1 of 2000 (leap year) the age would have been one year plus one day (because of february 29). No. A baby born on March 1st 1999 is just "one year old" on March 1st 2000, as it also is on March 2nd or any day after during the same year. Perhaps I didn't make myself clear. I was not refering here to age in the conventional sense, but to the actual aging process. In other words, in this particular case the amount of days elapsed would have been 366 instead of 365.
Re: How to repeat structure C++
On Sunday, 15 January 2017 at 19:00:49 UTC, MGW wrote: Hi! struct IInterface {}; struct IMsgBox : public IInterface { virtual bool Confirm(const wchar* queryText, tVariant* retVal) = 0; virtual bool Alert(const wchar* text) = 0; };
How to repeat structure C++
Hi! I write plugin for 1C:Enterprise 8.3 on dmd now. https://youtu.be/apLppufZulI I try to repeat structure C++ (interface) on dmd. But D no inheritance of structures. What it is possible to replace with the D following code on C ++struct IInterface {}; C++ - struct IMsgBox : public IInterface { virtual bool Confirm(const wchar* queryText, tVariant* retVal) = 0; virtual bool Alert(const wchar* text) = 0; };
Re: Beta 2.073.0-b1
On 01/14/2017 09:10 AM, Basile B. wrote: > Forget this, I've realized a bit late that it's already reported: > https://issues.dlang.org/show_bug.cgi?id=17072 The cause is that we build druntime on Windows with -dip25. https://issues.dlang.org/show_bug.cgi?id=17072#c1
Re: Beta 2.073.0-b1
Sorry, this is OT in the beta thread. On 01/15/2017 03:31 PM, Jacob Carlborg wrote: > What about lowering to "exp.tupleof[index]", which already bypass > protection? We also have lots of other stuff to do, and no there is no 1-to-1 mapping between exp.name and exp.tupleof[index].
[Issue 17072] [REG 2.073.0-b1] missing symbols with -inline
https://issues.dlang.org/show_bug.cgi?id=17072 Martin Nowakchanged: What|Removed |Added CC||bugzi...@digitalmars.com, ||c...@dawg.eu --- Comment #1 from Martin Nowak --- There is a difference between the mangling of the symbol included in phobos64.lib and the one requested. phobos64.lib has: _D4core4time8Duration46__T10opOpAssignVAyaa1_2dTS4core4time8DurationZ10opOpAssignMFNaNbNcNiNjNfxS4core4time8DurationZS4core4time8Duration linker wants: _D4core4time8Duration46__T10opOpAssignVAyaa1_2dTS4core4time8DurationZ10opOpAssignMFNaNbNcNiNfxS4core4time8DurationZS4core4time8Duration ddemangle doesn't yet know Nj, it stands for FuncAttrReturn (https://dlang.org/spec/abi.html#FuncAttrReturn). So what we have here is likely a difference in return inference in different compilations, leading the test below to think that the template was already instantiated by druntime, therefor not emitting it itself, but the instantiation in druntime inferred a different STCreturn. It's only reproducible w/ -inline b/c that runs semantic3 on imported functions and templates. Happens because the released library is build with -dip25 which enables return inference and obviously creates ABI incompatibilities. --
[Issue 17092] [REG 2.069.0] cannot get frame pointer from TaskPool.reduce
https://issues.dlang.org/show_bug.cgi?id=17092 Iain Buclawchanged: What|Removed |Added Summary|[REG 2.069.0] cannot access |[REG 2.069.0] cannot get |frame pointer of|frame pointer from |MapResult!(__lambda1, |TaskPool.reduce |Result).MapResult | --
[Issue 17092] [REG 2.069.0] cannot access frame pointer of MapResult!(__lambda1, Result).MapResult
https://issues.dlang.org/show_bug.cgi?id=17092 --- Comment #1 from Iain Buclaw--- (Edited title to match DMD's error message) /usr/include/dmd/phobos/std/parallelism.d(2632): Error: function std.parallelism.TaskPool.reduce!"a + b".reduce!(MapResult!(delegate (int i) => 1.0 / (1.0 + x * x), Result)).reduce cannot get frame pointer to D main --
Re: Querying parameter passing semantics for `auto ref const` variables
On Sunday, 15 January 2017 at 17:00:41 UTC, kinke wrote: On Sunday, 15 January 2017 at 14:33:25 UTC, Nordlöw wrote: A call to `isRef!T` inside the function `f` is always `false` for `l-value` and `r-value` passing. According to https://dlang.org/spec/template.html#auto-ref-parameters, it should be `__traits(isRef, x)`. This struct S { int x, y; } void f()(auto ref const S s) { pragma(msg, "type:", typeof(s), " isRef:", isRef!s); } f(S.init); S s; f(s); prints type:const(S) isRef:false type:const(S) isRef:true I made the mistake of incorrectly using isRef!S when I should have used isRef!s Thanks!
[Issue 17092] [REG 2.069.0] cannot access frame pointer of MapResult!(__lambda1, Result).MapResult
https://issues.dlang.org/show_bug.cgi?id=17092 Iain Buclawchanged: What|Removed |Added Hardware|x86_64 |All --
[Issue 17092] [REG 2.069.0] cannot access frame pointer of MapResult!(__lambda1, Result).MapResult
https://issues.dlang.org/show_bug.cgi?id=17092 Iain Buclawchanged: What|Removed |Added CC||ibuc...@gdcproject.org OS|Linux |All Severity|enhancement |regression --
[Issue 17092] New: [REG 2.069.0] cannot access frame pointer of MapResult!(__lambda1, Result).MapResult
https://issues.dlang.org/show_bug.cgi?id=17092 Issue ID: 17092 Summary: [REG 2.069.0] cannot access frame pointer of MapResult!(__lambda1, Result).MapResult Product: D Version: D2 Hardware: x86_64 OS: Linux Status: NEW Severity: enhancement Priority: P1 Component: phobos Assignee: nob...@puremagic.com Reporter: ibuc...@gdcproject.org >From gdc's own testsuite, this stopped being compilable from 2.069 and onwards. --- void main() { import std.algorithm : map; import std.parallelism : taskPool; import std.range : iota; immutable n = 1; immutable delta = 1.0 / n; immutable pi = 4.0 * delta * taskPool.reduce!"a + b"( map!((int i) { immutable x = (i - 0.5) * delta; return 1.0 / (1.0 + x * x); })(iota(n))); } --- Introduced by: https://github.com/dlang/phobos/pull/3522 Emplacing `RTask.init` instead of `RTask()` fixes the compiler error, however, as per comment in PR: task[] = RTask.init; has two bugs: 1. RTask is a nested struct, so RTask.init contains null context pointer. 2. That is a block assignment, so there is a possibility to call RTask.~this() on garbage objects (stack allocated buf is initialized by void). I'm not totally convinced that (1) is a problem however. --
[Issue 17091] std.range.zip cannot "save" correctly
https://issues.dlang.org/show_bug.cgi?id=17091 --- Comment #1 from Kazuki Komatsu--- (In reply to Kazuki Komatsu from comment #0) > Following code cannot be done correctly. > I tested the following code on DMDv2.072.2. > The line of the 4th `writeln` should output "[Tuple!(int, int)(1, 4), > Tuple!(int, int)(2, 5), Tuple!(int, int)(3, 6)]". > > > import std.range; > import std.algorithm; > import std.stdio; > > void main() > { > auto s1 = [1, 2, 3].inputRangeObject; > auto s2 = [4, 5, 6].inputRangeObject; > > writeln(s1.save); // [1, 2, 3], OK > writeln(s2.save); // [1, 2, 3], OK > > auto added = s1.zip(s2); > writeln(zs.save); // [Tuple!(int, int)(1, 4), Tuple!(int, int)(2, 5), > Tuple!(int, int)(3, 6)], OK > writeln(zs.save); // [], NG > } > Sorry, `auto added = s1.zip(s2);` is wrong. The correct code is following one import std.range; import std.algorithm; import std.stdio; void main() { auto s1 = [1, 2, 3].inputRangeObject; auto s2 = [4, 5, 6].inputRangeObject; writeln(s1.save); // [1, 2, 3], OK writeln(s2.save); // [1, 2, 3], OK auto zs = s1.zip(s2); writeln(zs.save); // [Tuple!(int, int)(1, 4), Tuple!(int, int)(2, 5), Tuple!(int, int)(3, 6)], OK writeln(zs.save); // [], NG } --
[Issue 17091] New: std.range.zip cannot "save" correctly
https://issues.dlang.org/show_bug.cgi?id=17091 Issue ID: 17091 Summary: std.range.zip cannot "save" correctly Product: D Version: D2 Hardware: All OS: All Status: NEW Severity: critical Priority: P1 Component: phobos Assignee: nob...@puremagic.com Reporter: enjouzensyou.bo...@gmail.com Following code cannot be done correctly. I tested the following code on DMDv2.072.2. The line of the 4th `writeln` should output "[Tuple!(int, int)(1, 4), Tuple!(int, int)(2, 5), Tuple!(int, int)(3, 6)]". import std.range; import std.algorithm; import std.stdio; void main() { auto s1 = [1, 2, 3].inputRangeObject; auto s2 = [4, 5, 6].inputRangeObject; writeln(s1.save); // [1, 2, 3], OK writeln(s2.save); // [1, 2, 3], OK auto added = s1.zip(s2); writeln(zs.save); // [Tuple!(int, int)(1, 4), Tuple!(int, int)(2, 5), Tuple!(int, int)(3, 6)], OK writeln(zs.save); // [], NG } --
Re: Using Dub
On Sunday, 15 January 2017 at 13:23:25 UTC, Russel Winder wrote: Is there any way of setting dub to default to ldc2 rather than dmd as the compiler of use? (I do not want to have to put --compiler ldc2 on every dub command.) I have never used dub, but I know it's now also bundled with ldc2. I would assume that if your PATH to ldc2 comes before that of dmd, it would find the ldc2 bundled version of dub and it would do the smart thing(if not, that's a bug).
Re: SmartRef: The Smart Pointer In D
On Sunday, 15 January 2017 at 15:56:30 UTC, Dsby wrote: and : In https://github.com/dlang/phobos/blob/master/std/typecons.d#L147 ~this() { debug(Unique) writeln("Unique destructor of ", (_p is null)? null: _p); if (_p !is null) destroy(_p); _p = null; } if the 'T' is a struct, it will not exec the Destory function. Is it a bug? What do you mean? This works for me: --- import std.stdio, std.typecons; struct Foo { ~this() { writeln("I'm destroyed"); } } void main() { Unique!Foo foo = new Foo; } // Prints "I'm destroyed" ---
Re: Querying parameter passing semantics for `auto ref const` variables
On Sunday, 15 January 2017 at 14:33:25 UTC, Nordlöw wrote: A call to `isRef!T` inside the function `f` is always `false` for `l-value` and `r-value` passing. According to https://dlang.org/spec/template.html#auto-ref-parameters, it should be `__traits(isRef, x)`.
Re: Convert duration to years?
On Sunday, 15 January 2017 at 14:20:04 UTC, Nestor wrote: On Sunday, 15 January 2017 at 14:04:39 UTC, Nestor wrote: ... For example, take a baby born in february 29 of year 2000 (leap year). In february 28 of 2001 that baby was one day short to one year. Family can make a concession and celebrate birthdays in february 28 of non-leap years, but march 1 is the actual day when the year of life completes. Which one to choose? On second thought, if a baby was born in march 1 of 1999 (non-leap year), in march 1 of 2000 (leap year) the age would have been one year plus one day (because of february 29). No. A baby born on March 1st 1999 is just "one year old" on March 1st 2000, as it also is on March 2nd or any day after during the same year. So perhaps the best thing is to always perform a "relaxed" calculation. I guess the problem of people born on February 29th is really application-dependent, and it also depends on the use of the calculated age. A social web app: users probably would like to see their age change on the 28th of non-leap years. A regulation-aware software: just follow what the law says. Etc.
Re: Parsing a UTF-16LE file line by line, BUG?
V Sun, 15 Jan 2017 14:48:12 + Nestor via Digitalmars-d-learnnapsáno: > On Friday, 6 January 2017 at 11:42:17 UTC, Mike Wey wrote: > > On 01/06/2017 11:33 AM, pineapple wrote: > >> On Friday, 6 January 2017 at 06:24:12 UTC, rumbu wrote: > > I'm not sure if this works quite as intended, but I was at > least able > to produce a UTF-16 decode error rather than a UTF-8 decode > error by > setting the file orientation before reading it. > > import std.stdio; > import core.stdc.wchar_ : fwide; > void main(){ > auto file = File("UTF-16LE encoded file.txt"); > fwide(file.getFP(), 1); > foreach(line; file.byLine){ > writeln(file.readln); > } > } > >>> > >>> fwide is not implemented in Windows: > >>> https://msdn.microsoft.com/en-us/library/aa985619.aspx > >> > >> That's odd. It was on Windows 7 64-bit that I put together and > >> tested > >> that example, and calling fwide definitely had an effect on > >> program > >> behavior. > > > > Are you compiling a 32bit binary? Because in that case you > > would be using the digital mars c runtime which might have an > > implementation for fwide. > > After some testing I realized that byLine was not the one > failing, but any string manipulation done to the obtained line. > Compile the following example with and without -debug and run to > see what I mean: > > import std.stdio, std.string; > > enum >EXIT_SUCCESS = 0, >EXIT_FAILURE = 1; > > int main() { >version(Windows) { > import core.sys.windows.wincon; > SetConsoleOutputCP(65001); >} >auto f = File("utf16le.txt", "r"); >foreach (line; f.byLine()) try { > string s; > debug s = cast(string)strip(line); // this is the one causing > problems > if (1 > s.length) continue; > writeln(s); >} catch(Exception e) { > writefln("Error. %s\nFile \"%s\", line %s.", e.msg, e.file, > e.line); > return EXIT_FAILURE; >} >return EXIT_SUCCESS; > } This is because byLine does return range, so until you do something with that it does not cause any harm :)
Re: Silvermirror to mirror websites
On Sun, 15 Jan 2017 09:53:16 +, Dukc wrote: > You forgot to add a license/unlicense... Thanks, fixed! MIT licensed, unless someone needs it under another.
Re: SmartRef: The Smart Pointer In D
On Sunday, 15 January 2017 at 15:42:19 UTC, Dsby wrote: On Saturday, 14 January 2017 at 17:35:09 UTC, Nordlöw wrote: On Friday, 13 January 2017 at 16:50:37 UTC, Dsby wrote: I write the ref count pointer and the scoped point in D. How do two of these differ from - https://dlang.org/phobos/std_typecons.html#.RefCounted - https://dlang.org/phobos/std_typecons.html#.Unique under https://dlang.org/phobos/std_typecons.html ? The RefCount not support class or inteface, and the ref count is not atomic , it not thread safe. The Unique is base of GC. It can not @nogc. And it use the 'delete' keyword , it will be deprcated(http://dlang.org/deprecate.html). The SmartRef is Base std.experimental.allocator. You can control where the memony allocator. And the smartref.sharedref use the atomic default, you alse can not use atomic。 And have the smartref.weakref with sharedref to fix circular reference. Sorry,In the new phobos, THe Unique is not used the 'delete' keyword. But , it only destroy, not free the memony. and : In https://github.com/dlang/phobos/blob/master/std/typecons.d#L147 ~this() { debug(Unique) writeln("Unique destructor of ", (_p is null)? null: _p); if (_p !is null) destroy(_p); _p = null; } if the 'T' is a struct, it will not exec the Destory function. Is it a bug?
Re: SmartRef: The Smart Pointer In D
On Saturday, 14 January 2017 at 17:35:09 UTC, Nordlöw wrote: On Friday, 13 January 2017 at 16:50:37 UTC, Dsby wrote: I write the ref count pointer and the scoped point in D. How do two of these differ from - https://dlang.org/phobos/std_typecons.html#.RefCounted - https://dlang.org/phobos/std_typecons.html#.Unique under https://dlang.org/phobos/std_typecons.html ? The RefCount not support class or inteface, and the ref count is not atomic , it not thread safe. The Unique is base of GC. It can not @nogc. And it use the 'delete' keyword , it will be deprcated(http://dlang.org/deprecate.html). The SmartRef is Base std.experimental.allocator. You can control where the memony allocator. And the smartref.sharedref use the atomic default, you alse can not use atomic。 And have the smartref.weakref with sharedref to fix circular reference.
Re: Parsing a UTF-16LE file line by line, BUG?
On Sunday, 15 January 2017 at 14:48:12 UTC, Nestor wrote: After some testing I realized that byLine was not the one failing, but any string manipulation done to the obtained line. Compile the following example with and without -debug and run to see what I mean: import std.stdio, std.string; enum EXIT_SUCCESS = 0, EXIT_FAILURE = 1; int main() { version(Windows) { import core.sys.windows.wincon; SetConsoleOutputCP(65001); } auto f = File("utf16le.txt", "r"); foreach (line; f.byLine()) try { string s; debug s = cast(string)strip(line); // this is the one causing problems if (1 > s.length) continue; writeln(s); } catch(Exception e) { writefln("Error. %s\nFile \"%s\", line %s.", e.msg, e.file, e.line); return EXIT_FAILURE; } return EXIT_SUCCESS; } By the way, when caught, the exception says it's in file src/phobos/std/utf.d line 1217, but that file only has 784 lines. That's quite odd. (I am compiling with dmd 2.072.2)
Re: GSoC 2017 Ideas!
On 1/15/17 7:43 AM, Jack Stouffer wrote: On Saturday, 14 January 2017 at 15:19:23 UTC, Craig Dillabaugh wrote: So the ideas page is up for the 2017 GSoC. Its a bit light on content. Please feel free to use this forum thread to discuss any ideas you might have for appropriate projects. https://wiki.dlang.org/GSOC_2017_Ideas Cheers Craig Fully implementing the C++ STL integration. According to Walter, everything that's needed in DMD is there. It just requires someone who knows the in's and out's of the STL to sit down and create the equivalent structs to get the right mangling. I think this would become a killer selling point of D if this were to happen. We have Alexandru working on that. BTW stuff from https://wiki.dlang.org/Project_Ideas should be merged into GSoC, too. Andrei
Re: Parsing a UTF-16LE file line by line, BUG?
On Friday, 6 January 2017 at 11:42:17 UTC, Mike Wey wrote: On 01/06/2017 11:33 AM, pineapple wrote: On Friday, 6 January 2017 at 06:24:12 UTC, rumbu wrote: I'm not sure if this works quite as intended, but I was at least able to produce a UTF-16 decode error rather than a UTF-8 decode error by setting the file orientation before reading it. import std.stdio; import core.stdc.wchar_ : fwide; void main(){ auto file = File("UTF-16LE encoded file.txt"); fwide(file.getFP(), 1); foreach(line; file.byLine){ writeln(file.readln); } } fwide is not implemented in Windows: https://msdn.microsoft.com/en-us/library/aa985619.aspx That's odd. It was on Windows 7 64-bit that I put together and tested that example, and calling fwide definitely had an effect on program behavior. Are you compiling a 32bit binary? Because in that case you would be using the digital mars c runtime which might have an implementation for fwide. After some testing I realized that byLine was not the one failing, but any string manipulation done to the obtained line. Compile the following example with and without -debug and run to see what I mean: import std.stdio, std.string; enum EXIT_SUCCESS = 0, EXIT_FAILURE = 1; int main() { version(Windows) { import core.sys.windows.wincon; SetConsoleOutputCP(65001); } auto f = File("utf16le.txt", "r"); foreach (line; f.byLine()) try { string s; debug s = cast(string)strip(line); // this is the one causing problems if (1 > s.length) continue; writeln(s); } catch(Exception e) { writefln("Error. %s\nFile \"%s\", line %s.", e.msg, e.file, e.line); return EXIT_FAILURE; } return EXIT_SUCCESS; }
Re: Querying parameter passing semantics for `auto ref const` variables
On Sunday, 15 January 2017 at 14:33:25 UTC, Nordlöw wrote: Is there a way to query at compile-time whether a call to Further, overloading such as struct S { int x, y; } static f(in S s) {} static f(const ref S s) {} f(S.init); S s; f(s); fails as declaration f is already defined
Querying parameter passing semantics for `auto ref const` variables
Is there a way to query at compile-time whether a call to f(T)(auto ref const T x) passed the variable `x` from a l-value or r-value? A call to `isRef!T` inside the function `f` is always `false` for `l-value` and `r-value` passing. I need this to detect automatic delayed evaluation of sub-expressions in my GNU MP wrapper at https://github.com/nordlow/gmp-d
Re: std.traits vcs __traits
On Sunday, 15 January 2017 at 13:45:52 UTC, Jack Stouffer wrote: If it's faster and passes all of the tests, then sure. Great!
Re: Convert duration to years?
On Sunday, 15 January 2017 at 14:04:39 UTC, Nestor wrote: ... For example, take a baby born in february 29 of year 2000 (leap year). In february 28 of 2001 that baby was one day short to one year. Family can make a concession and celebrate birthdays in february 28 of non-leap years, but march 1 is the actual day when the year of life completes. Which one to choose? On second thought, if a baby was born in march 1 of 1999 (non-leap year), in march 1 of 2000 (leap year) the age would have been one year plus one day (because of february 29). So perhaps the best thing is to always perform a "relaxed" calculation.
Re: Convert duration to years?
On Sunday, 15 January 2017 at 11:01:28 UTC, biozic wrote: On Sunday, 15 January 2017 at 08:40:37 UTC, Nestor wrote: I cleaned up the function a little, but it still feels like a hack: uint getAge(uint , uint mm, uint dd) { import std.datetime; SysTime t = Clock.currTime; ubyte correction = 0; if( (t.month < mm) || ( (t.month == mm) && (t.day < dd) ) ) correction += 1; return (t.year - - correction); } Isn't there anything better? It doesn't feel like a hack to me, because it's simple and correct code that comply with the common definition of a person's age. The only inaccuracy I can think of is about people born on February 29th... I know. I thought about it as well, but it's not something you can deal with cleanly. For example, take a baby born in february 29 of year 2000 (leap year). In february 28 of 2001 that baby was one day short to one year. Family can make a concession and celebrate birthdays in february 28 of non-leap years, but march 1 is the actual day when the year of life completes. Which one to choose? Another way to deal with this is modifying the function to take a parameter which allows to do a relaxed calculation in non-leap years if one so desires.
Re: std.traits vcs __traits
On Sunday, 15 January 2017 at 12:53:04 UTC, Nordlöw wrote: Why is there both http://dlang.org/phobos/std_traits.html and the builtin https://dlang.org/spec/traits.html Several reasons, including usability in meta-templates like allSatisfy and the fact that it's way more user friendly and clear as a template. Should we modify std.traits to make use of __traits? If it's faster and passes all of the tests, then sure.
Re: std.container.array.Array is not @nogc?
On Sunday, 15 January 2017 at 13:08:52 UTC, drug007 wrote: Thanks for answer. Looking forward for your PR. https://github.com/dlang/phobos/pull/5036
Re: What about an identifier that is an mixin
V Sat, 14 Jan 2017 01:28:51 + André Puel via Digitalmars-dnapsáno: > On Friday, 13 January 2017 at 23:13:43 UTC, Daniel Kozak wrote: > > On Friday, 13 January 2017 at 22:12:55 UTC, André Puel wrote: > >> > >> Could you elaborate on why you consider it important to be > >> able to tell when you use mixin and when not? > > > > because it is something really different, so it is nice to know > > when you call something and when you mixin some code into > > curent scope. > > Yes, please, elaborate on that. Why is it really different? What > are your thoughts on C macros? > > > > > Btw. I was on a same side as you are now (I am still in some > > way, I would prefer some shortcuts) > > > >> In D, you don't know if a member is a function call or an > >> attribute when you access it without parenthesis: > >> > >> myObj.a; //Is it a function call or an attribute? > >> > > > > Not completly true: > > > > class MyClass > > { > > int a; > > void b() {} > > } > > > > void main() > > { > > auto myObj = new MyClass; > > myObj.a; // this does not compile > > myObj.b; > > } > > I meant the property pattern. You access an attribute and it > could be a direct access in the memory or it could be a request > to a remote database. One happens instantly, the other got a lot > of complex things in the way. You could even get a thrown > exception by just accessing an "attribute". I do not like C macros. It is different because when anyone see something like this: someNameOfFunction(); He or she would expect that this call something and it could not interact with current scope (declare new local variables, change theirs values and so on). but if we allow use same call convention for mixins we end up with something like this string someMixin() { return `a = 5;`; } void main() { import std.stdio; int a = 4; someMixin(); writeln(a); // wow 5 insted of 4 } right now when I see mixin(someMixin()); I know I need to introspect someMixin to be sure what can happend
Using Dub
Is there any way of setting dub to default to ldc2 rather than dmd as the compiler of use? (I do not want to have to put --compiler ldc2 on every dub command.) -- 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: std.container.array.Array is not @nogc?
On 15.01.2017 15:49, Jack Stouffer wrote: No you're not. Array was designed before the @nogc attribute was created, so it wasn't coded with it's requirements in mind. Looking at the code, Array allocates GC memory for exception throwing in some cases. These can and should be changed to asserts. I am writing a PR now to fix this. There doesn't seem to be too many cases to fix. Thanks for answer. Looking forward for your PR.
std.traits vcs __traits
Why is there both http://dlang.org/phobos/std_traits.html and the builtin https://dlang.org/spec/traits.html ? Should we modify std.traits to make use of __traits? I've noticed measurably faster compilations with __traits instead of std.traits for simple things such as isIntegral, isUnsigned, etc. If so, I'll happily make that happen!
Re: std.container.array.Array is not @nogc?
On Sunday, 15 January 2017 at 11:47:06 UTC, drug007 wrote: Is there a way to use Array in @nogc code: ``` import std.container.array : Array; @nogc: void main(string[ ] args) { Array!int ai; ai ~= 1; assert(ai[0] == 1); } ``` fails: ``` main.d(8): Error: @nogc function 'D main' cannot call non-@nogc function 'std.container.array.Array!int.Array.opOpAssign!("~", int).opOpAssign' main.d(9): Error: @nogc function 'D main' cannot call non-@nogc function 'std.container.array.Array!int.Array.opIndex' ``` am I doing something wrong? No you're not. Array was designed before the @nogc attribute was created, so it wasn't coded with it's requirements in mind. Looking at the code, Array allocates GC memory for exception throwing in some cases. These can and should be changed to asserts. I am writing a PR now to fix this. There doesn't seem to be too many cases to fix.
[Issue 6227] Comparison of different enums
https://issues.dlang.org/show_bug.cgi?id=6227 bitter.ta...@gmx.com changed: What|Removed |Added CC||bitter.ta...@gmx.com --- Comment #2 from bitter.ta...@gmx.com --- Covered by DMD's PR https://github.com/dlang/dmd/pull/6444 --
std.container.array.Array is not @nogc?
Is there a way to use Array in @nogc code: ``` import std.container.array : Array; @nogc: void main(string[ ] args) { Array!int ai; ai ~= 1; assert(ai[0] == 1); } ``` fails: ``` main.d(8): Error: @nogc function 'D main' cannot call non-@nogc function 'std.container.array.Array!int.Array.opOpAssign!("~", int).opOpAssign' main.d(9): Error: @nogc function 'D main' cannot call non-@nogc function 'std.container.array.Array!int.Array.opIndex' ``` am I doing something wrong?
Re: Pry v0.3.1 is out!
Sounds intriguing! On 01/15/2017 01:26 AM, Dmitry Olshansky wrote: > - versatility, generating some goofy parse tree is not a goal, the goal > is extraction of data the way the user specifies Can you show an example of what you have in mind for this? signature.asc Description: OpenPGP digital signature
Re: Convert duration to years?
On Sunday, 15 January 2017 at 08:40:37 UTC, Nestor wrote: I cleaned up the function a little, but it still feels like a hack: uint getAge(uint , uint mm, uint dd) { import std.datetime; SysTime t = Clock.currTime; ubyte correction = 0; if( (t.month < mm) || ( (t.month == mm) && (t.day < dd) ) ) correction += 1; return (t.year - - correction); } Isn't there anything better? It doesn't feel like a hack to me, because it's simple and correct code that comply with the common definition of a person's age. The only inaccuracy I can think of is about people born on February 29th...
Re: Convert duration to years?
On 01/15/2017 07:58 AM, Nestor wrote: I eventually came up with this, but it seems an ugly hack: import std.stdio; uint getAge(int , ubyte mm, ubyte dd) { ubyte correction; import std.datetime; SysTime t = Clock.currTime(); if (t.month < mm) correction = 1; else if (t.month == mm) correction = (t.day < dd) ? 1 : 0; else correction = 0; return (t.year - - correction); } void main() { try writefln("Edad: %s años.", getAge(1958, 1, 21)); catch(Exception e) { writefln("%s.\n(%s, line %s)", e.msg, e.file, e.line); } } That's the better approach, I think. Years have variable lengths. Determining "age" in years works by comparing dates, not durations. I would write it like this, but as far as I see yours does the same thing: int getAge(int , int mm, int dd) { import std.datetime; immutable SysTime now = Clock.currTime(); immutable int years = now.year - ; return mm > now.month || mm == now.month && dd > now.day ? years - 1 // birthday hasn't come yet this year : years; // birthday has already been this year } void main() { import std.stdio; /* Day of writing: 2017-01-15 */ writeln(getAge(1980, 1, 1)); /* 37 */ writeln(getAge(1980, 1, 15)); /* 37 (birthday is today) */ writeln(getAge(1980, 1, 30)); /* 36 */ writeln(getAge(1980, 6, 1)); /* 36 */ } Isn't there a built-in function to do this? If there is, finding it in std.datetime would take me longer than writing it myself.
Re: Silvermirror to mirror websites
You forgot to add a license/unlicense...
[Issue 6400] opDispatch with WithStatement
https://issues.dlang.org/show_bug.cgi?id=6400 --- Comment #9 from github-bugzi...@puremagic.com --- Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/2c8008781a23f807be89dfaf858814a1308c9f43 Fix issue 6400 - Better interaction between with() and opDispatch https://github.com/dlang/dmd/commit/c49fb860d507f75556cfb2108986a8b901d15920 Merge pull request #6439 from LemonBoy/b6400 Fix issue 6400 - Better interaction between with() and opDispatch --
[Issue 6400] opDispatch with WithStatement
https://issues.dlang.org/show_bug.cgi?id=6400 github-bugzi...@puremagic.com changed: What|Removed |Added Status|NEW |RESOLVED Resolution|--- |FIXED --
Re: Convert duration to years?
I cleaned up the function a little, but it still feels like a hack: uint getAge(uint , uint mm, uint dd) { import std.datetime; SysTime t = Clock.currTime; ubyte correction = 0; if( (t.month < mm) || ( (t.month == mm) && (t.day < dd) ) ) correction += 1; return (t.year - - correction); } Isn't there anything better?
Re: template instance does not match template declaration
On Sunday, 8 January 2017 at 05:45:52 UTC, Meta wrote: On Sunday, 8 January 2017 at 03:27:26 UTC, Fabrice Marie wrote: void main() { Cache!(BasicObject, string, lookupBasicObject); } In addition to what Nicholas Wilson said, what you're doing here is the equivalent of writing `int;`. It doesn't make any sense as Cache!(...) is a type, and you are declaring a variable of that type... except you're not providing a variable name so the syntax is wrong. After you've fixed the other problem change it to this: Cache!(BasicObject, string, lookupBasicObject) c; Thanks a lot! exactly what I needed.
Re: Convert duration to years?
On Sunday, 15 January 2017 at 07:25:26 UTC, rikki cattermole wrote: So I had a go at this and found I struggled looking at "magic" functions and methods. Turns out there is a much simpler answer. int getAge(int , int mm, int dd) { import std.datetime; auto t1 = cast(DateTime)SysTime(Date(, mm, dd)); auto t2 = cast(DateTime)Clock.currTime(); int numYears; while(t2 > t1) { t1.add!"years"(1); numYears++; } return numYears; } Well... correct me if I am wrong, but isn't t1.add!"years"(1) simply adding one year to t1?