Re: Looking for a language to hang my hat on.

2015-11-16 Thread Chris Wright via Digitalmars-d-learn
On Monday, 16 November 2015 at 22:39:17 UTC, Dan wrote: I have been lurking on this site over the past few weeks trying to decide when (and if) to make the transition. Can anyone here who has already made that transition tell me how smoothly it went? Any major unexpected problems? Advice?

Re: Looking for a language to hang my hat on.

2015-11-17 Thread Chris Wright via Digitalmars-d-learn
On Tue, 17 Nov 2015 10:53:04 +, bachmeier wrote: > On Tuesday, 17 November 2015 at 00:33:44 UTC, Chris Wright wrote: >> This might change, but that's a gamble, and not one I'd take. >> For projects where you need specific libraries to exist already, D >> probably won't serve your needs. (It's

Re: Real Time-ing

2015-12-08 Thread Chris Wright via Digitalmars-d-learn
On Tue, 08 Dec 2015 15:35:18 +, Taylor Hillegeist wrote: > So, I mostly do programming that is of run to completion verity. > But I have a dream of calling functions periodically. So my question is: > > What is the best (most time accurate) way to call a function every n > time units?

Struct initializers as expressions

2015-12-02 Thread Chris Wright via Digitalmars-d-learn
I can initialize a struct with named values: --- struct Foo { int i, j, k, l, m, n; } Foo f = {k: 12}; // other fields get default initialization --- I can initialize it with call syntax: --- auto f = Foo(0, 0, 12, 0, 0, 0); // works --- I can use the latter as an expression: --- void

Re: Which type it better to use for array's indices?

2015-12-04 Thread Chris Wright via Digitalmars-d-learn
On Fri, 04 Dec 2015 13:24:16 +, ref2401 wrote: > It seem like `size_t` suites well because 'is large enough to represent > an offset into all addressible memory.' > (http://dlang.org/spec/type.html#size_t) > However sometimes I want index to be less the 0 to represent a > particular case.

Re: Struct initializers as expressions

2015-12-04 Thread Chris Wright via Digitalmars-d-learn
On Fri, 04 Dec 2015 15:07:01 +0100, Jacob Carlborg wrote: > But I do see a problem, which I'm guessing Walter would point out as > well. It might/will complicate the overloading rules. What if "a" and > "b" in T would be integers instead. I think that would be ambiguous. Right. I would much

Re: Reset all Members of a Aggregate Instance

2015-12-05 Thread Chris Wright via Digitalmars-d-learn
On Sat, 05 Dec 2015 07:48:16 -0800, Ali Çehreli wrote: > On 12/05/2015 01:32 AM, Observer wrote: > >> Won't clear(c); do the trick? ((pp187-188 of TDPL) > > clear() has been renamed as destroy() but it won't work by itself > because the OP wants a reusable object. I think, in addition to >

Re: Do a class invariants affect -release builds?

2015-12-05 Thread Chris Wright via Digitalmars-d-learn
On Sat, 05 Dec 2015 23:06:22 +, Andrew LaChance wrote: > I was reading a blog post here: http://3d.benjamin-thaut.de/?p=20 which > mentions: > > "Calls to the druntime invariant handler are emitted in release build > also and there is no way to turn them off. Even if the class does not >

Re: Struct initializers as expressions

2015-12-03 Thread Chris Wright via Digitalmars-d-learn
On Thu, 03 Dec 2015 06:38:20 +, Mike Parker wrote: > AFAIK, your only option is to use a struct constructor. This is the sort > of thing they're used for. Which brings be back to positional arguments, which means that someone wishing to supply a limit on the number of query results must

Re: Reset all Members of a Aggregate Instance

2015-12-03 Thread Chris Wright via Digitalmars-d-learn
On Thu, 03 Dec 2015 21:55:04 +, Nordlöw wrote: > On Thursday, 3 December 2015 at 21:38:48 UTC, Chris Wright wrote: >> The terrible way is something like: >> >> void reset(Object o) >> in { >> assert(!(o is null)); >> } >> body { >> auto p = cast(ubyte*)*cast(void**) >> auto ci =

Re: Reset all Members of a Aggregate Instance

2015-12-03 Thread Chris Wright via Digitalmars-d-learn
The terrible way is something like: void reset(Object o) in { assert(!(o is null)); } body { auto p = cast(ubyte*)*cast(void**) auto ci = o.classinfo; auto init = cast(ubyte)ci.init; p[0..init.length] = init[]; if (ci.defaultConstructor) { ci.defaultConstructor(o); } else {

Re: Reset all Members of a Aggregate Instance

2015-12-07 Thread Chris Wright via Digitalmars-d-learn
On Tue, 08 Dec 2015 14:12:02 +1100, Daniel Murphy wrote: > On 4/12/2015 8:38 AM, Chris Wright wrote: >> An object reference is just a pointer, but we can't directly cast it. >> So we make a pointer to it and cast that; the type system allows it. >> Now we can access the data that the object

Must ranges have value semantics?

2015-12-15 Thread Chris Wright via Digitalmars-d-learn
I noticed that some methods in Phobos will have very different behavior with forward ranges that have reference semantics and those that have value semantics. Example: auto range = getSomeRange(); auto count = range.walkLength; foreach (element; range) { writeln(element); } If getSomeRange

Re: Balanced match with std.regex

2015-12-14 Thread Chris Wright via Digitalmars-d-learn
On Tue, 15 Dec 2015 00:16:41 +, Jakob Ovrum wrote: > Is there a way to do balanced match with std.regex? > > Example (from [1]): > > test -> funcPow((3),2) * (9+1) > > I want to match the funcPow((3),2) bit, regardless of the depth of the > expression in funcPow(*). > >

Re: How to check if result of request to DB is empty?

2015-12-12 Thread Chris Wright via Digitalmars-d-learn
On Sat, 12 Dec 2015 07:44:40 +, Suliman wrote: >>> string query_string = (`SELECT user, password FROM otest.myusers where >>> user LIKE ` ~ `'%` ~ request["username"].to!string ~ `%';`); >> >> Don't piece queries together without escaping the dynamic parts. >> Imagine what happens when the

Re: Implicit Interface Deduction

2015-12-13 Thread Chris Wright via Digitalmars-d-learn
On Sun, 13 Dec 2015 23:09:47 +0100, Faux Amis wrote: > interface IA {} > interface IB {} > interface IC {} > interface IAB : IA, IB {} interface IBC : IB, IC {} > > class C : IA, IB, IC {} > // Defining C as : IAB, IBC // is not really scalable ;) > > void main() > { > IAB c = new C(); //

Re: Very very noobie question about how imports work.

2015-12-10 Thread Chris Wright via Digitalmars-d-learn
On Fri, 11 Dec 2015 03:20:29 +, J Smith wrote: > How do I make it so that I can import and use the contents of lib.d > inside of testlib.d. If you are not compiling everything in one step, the -I flag allows you to specify paths to look for imports. For instance: $ dmd -lib

Re: Are there any D scripting engines for use with D?

2016-01-05 Thread Chris Wright via Digitalmars-d-learn
On Mon, 04 Jan 2016 20:04:48 +0100, Max Klyga wrote: > Croc (previously miniD, a scripting language implemented in D) - > http://jfbillingsley.com/croc/ Croc is written in C++. Jarrett got annoyed with D around the D2 switch. MiniD is written for D1 and Tango. It would be nontrivial to port it

Re: Password Storage

2015-11-27 Thread Chris Wright via Digitalmars-d-learn
On Fri, 27 Nov 2015 08:09:49 -0800, H. S. Teoh via Digitalmars-d-learn wrote: > On Fri, Nov 27, 2015 at 02:51:30PM +, Adam D. Ruppe via > Digitalmars-d-learn wrote: >> On Friday, 27 November 2015 at 07:46:33 UTC, H. S. Teoh wrote: >> >1) The server stores password01 in the user database. >>

Formatting dates

2015-11-28 Thread Chris Wright via Digitalmars-d-learn
Is there a way to format a DateTime struct similar to strftime(3)? None is documented, and none is immediately obvious in the source code. Or is the recommended way to convert a DateTime to a Unix timestamp and then use strftime?

Locale package?

2015-11-28 Thread Chris Wright via Digitalmars-d-learn
Is there a package for locale data? I'm looking for things like month names and days of the week and default date and time formats, specifically.

Re: DateTime.opBinary

2015-11-29 Thread Chris Wright via Digitalmars-d-learn
On Sun, 29 Nov 2015 23:25:14 +, bachmeier wrote: > I was just reading through the documentation for std.datetime. > DateTime.opBinary looks pretty interesting: > > http://dlang.org/phobos/std_datetime.html#.DateTime.opBinary > > Does anyone know how to use it? You certainly can't learn

Re: DateTime.opBinary

2015-11-30 Thread Chris Wright via Digitalmars-d-learn
On Mon, 30 Nov 2015 01:30:28 -0800, Jonathan M Davis via Digitalmars-d-learn wrote: > On Sunday, November 29, 2015 23:53:41 Chris Wright via > Digitalmars-d-learn wrote: >> Unfortunately, ddoc doesn't automatically cross-reference these for >> you, >> which results in conf

Re: char[] == null

2015-11-18 Thread Chris Wright via Digitalmars-d-learn
On Wed, 18 Nov 2015 20:57:06 +, Spacen Jasset wrote: > Should this be allowed? What is it's purpose? It could compare two > arrays, but surely not that each element of type char is null? > > char[] buffer; > if (buffer == null) {} 'null' is a value of ambiguous type. The compiler finds a

Re: char[] == null

2015-11-18 Thread Chris Wright via Digitalmars-d-learn
On Thu, 19 Nov 2015 03:53:46 +, Meta wrote: > On Wednesday, 18 November 2015 at 23:53:01 UTC, Chris Wright wrote: >> --- >> char[] buffer; >> if (buffer.length == 0) {} >> --- > > This is not true. Consider the following code: > > import std.stdio; > > void main() > { > int[] a = [0,

Re: char[] == null

2015-11-19 Thread Chris Wright via Digitalmars-d-learn
On Thu, 19 Nov 2015 07:28:28 +0100, anonymous wrote: > On 19.11.2015 06:18, Chris Wright wrote: >> Just for fun, is an array ever not equal to itself? > > Yes, when it contains an element that's not equal to itself, e.g. NaN. Exactly. If NaN-like cases didn't exist, TypeInfo_Array could have

Re: `finally` is redundant?

2015-11-21 Thread Chris Wright via Digitalmars-d-learn
On Sat, 21 Nov 2015 11:15:22 +0530, Shriramana Sharma wrote: > The page http://dlang.org/exception-safe.html says: > > "It's try-finally that becomes redundant." > > IIUC this is because we have scope(exit). > > Does this mean that `finally` should eventually be removed from the > language?

Re: `finally` is redundant?

2015-11-21 Thread Chris Wright via Digitalmars-d-learn
On Sat, 21 Nov 2015 16:10:45 -0800, Jonathan M Davis via Digitalmars-d-learn wrote: > Getting rid of finally would mean > reimplementing scope(exit) differently Well, we could keep try/finally as a concept inside the compiler but change the parser so it rejects finally blocks.

Re: Dub pre-build hook

2016-01-10 Thread Chris Wright via Digitalmars-d-learn
On Sun, 10 Jan 2016 16:34:51 +, Chris Wright wrote: > Is there a way to write a pre-build hook in Dub? > > Specifically, I want to write unittests in a separate package to the > rest of my source code. This requires a module that imports all my > unittest modules. It's safer to automatically

Dub pre-build hook

2016-01-10 Thread Chris Wright via Digitalmars-d-learn
Is there a way to write a pre-build hook in Dub? Specifically, I want to write unittests in a separate package to the rest of my source code. This requires a module that imports all my unittest modules. It's safer to automatically generate this than to rely on my memory. My other alternative

Re: Java wildcards... in D

2016-01-18 Thread Chris Wright via Digitalmars-d-learn
On Mon, 18 Jan 2016 19:19:22 +, Voitech wrote: > Hi. I'm trying to parse an simple string expression to something like > Element array. Each Element can have a value of unknown type, which will > be further combined and calculated to let say real/double/float value, > no mather. In Java,

Re: Things that keep D from evolving?

2016-02-08 Thread Chris Wright via Digitalmars-d-learn
On Mon, 08 Feb 2016 11:22:45 +, thedeemon wrote: > On Saturday, 6 February 2016 at 08:07:42 UTC, NX wrote: >> What language semantics prevent precise & fast GC implementations? > > easy type casting prevent precise GC. To expand on this point: A GC makes a tradeoff between allocating

Re: Things that keep D from evolving?

2016-02-09 Thread Chris Wright via Digitalmars-d-learn
On Tue, 09 Feb 2016 14:35:48 +, Ola Fosheim Grøstad wrote: > On Tuesday, 9 February 2016 at 13:41:30 UTC, NX wrote: >> There are several reasons I want to use D rather than C# / Go / >> something else: >> - Interfacing with native API without jumping through hoops > > Well, but the hoops are

opApply @safety

2016-01-29 Thread Chris Wright via Digitalmars-d-learn
I want to create an opApply for a type. I've marked my code @safe, because everything I wrote was @safe. The body of opApply is @safe, but it calls a delegate that may or may not be @safe. How do I make it so I can iterate through this type safely and systemly? I want to support iteration

Re: Getting the body of a HTTP Request

2016-01-27 Thread Chris Wright via Digitalmars-d-learn
On Wed, 27 Jan 2016 23:42:54 +, brian wrote: > Body: vibe.stream.counting.EndCallbackInputStream Body to String: > Body to String: HTTP/1.1 302 Found You got an HTTP redirect as a response. There should be a header called Location containing a URL. Redo the request with that URL. Most HTTP

Re: Getting the body of a HTTP Request

2016-01-27 Thread Chris Wright via Digitalmars-d-learn
On Thu, 28 Jan 2016 00:16:12 +, brian wrote: > On Wednesday, 27 January 2016 at 23:50:34 UTC, Chris Wright wrote: >> On Wed, 27 Jan 2016 23:42:54 +, brian wrote: >>> Body: vibe.stream.counting.EndCallbackInputStream Body to String: Body >>> to String: HTTP/1.1 302 Found >> >> You got an

Re: opApply @safety

2016-01-29 Thread Chris Wright via Digitalmars-d-learn
On Fri, 29 Jan 2016 23:35:35 +, Basile B. wrote: > You can implement an input range and annotate all the primitives as > @safe. I hadn't realized that if front() returns a tuple, it's automatically expanded. Works for me.

Re: casting & templates

2016-01-31 Thread Chris Wright via Digitalmars-d-learn
On Sun, 31 Jan 2016 19:59:01 +0100, Robert M. Münch wrote: > I have: > > class OperatorV(T) : Value { > T impl; > > this(T impl) { > this.impl = impl; > } > ... This expands to: template OperatorV(T) { class OperatorV { ... } } If you're just typing `OperatorV` with no

Re: Use the D dylib in my C++ program,when the D's GC(in the dylib runtime) run. will not my program stop?

2016-01-30 Thread Chris Wright via Digitalmars-d-learn
On Sat, 30 Jan 2016 14:41:18 +, Dsby wrote: > Use the D dylib in my C++ program,when the D's GC(in the dylib runtime) > run. will not my program stop? The GC will stop every thread it knows about. If you have a C++ thread that you want to run while the GC is running, you can get that by not

Re: How do you initialize a class instance which has static storage within another class?

2016-01-30 Thread Chris Wright via Digitalmars-d-learn
On Sat, 30 Jan 2016 22:02:10 +, Enjoys Math wrote: > On Saturday, 30 January 2016 at 21:52:20 UTC, Enjoys Math wrote: >> >> class A { static B b; } class B {} >> >> doing b = new B() does NOT work. >> >> Nor could I create a this() {} at module level > > More info: > > B : A > > so I can't

Re: How would you implement this in D? (signals & slots)

2016-02-02 Thread Chris Wright via Digitalmars-d-learn
On Tue, 02 Feb 2016 15:59:06 +, Atila Neves wrote: > struct String1 { string s; } > struct String2 { string s; } I've seen this sort of thing before. A blogger I used to follow, Jeremy Miller, implemented an event broker using this pattern. I don't like it. It requires a new type for each

Re: opApply @safety

2016-01-29 Thread Chris Wright via Digitalmars-d-learn
On Fri, 29 Jan 2016 14:00:08 -0500, Steven Schveighoffer wrote: > On 1/29/16 12:44 PM, Chris Wright wrote: >> I want to create an opApply for a type. >> >> I've marked my code @safe, because everything I wrote was @safe. The >> body of opApply is @safe, but it calls a delegate that may or may not

Re: Why we cannot use string in mixins?

2016-02-27 Thread Chris Wright via Digitalmars-d-learn
On Sat, 27 Feb 2016 23:29:49 +, mahdi wrote: > I read this criticism about D on Reddit and it claims that you cannot > use strings in mixins. Can you please elaborate about this and the > reason behind it? > > QUOTE: > Look at strings: they are defined as immutable(char []). That would be

Re: dub: how to reference a compiled package

2016-02-25 Thread Chris Wright via Digitalmars-d-learn
On Thu, 25 Feb 2016 12:15:42 +, mahdi wrote: > Hi, > > Suppose I have a package `mypack` in `~/mypack`. I run `dub` command on > this package and have the compiled `mypack` file (OS is Linux). > > Now I am working on my project. I know how to use the source-code of > `mypack` package in the

Re: How to detect if an array if dynamic or static

2016-02-24 Thread Chris Wright via Digitalmars-d-learn
On Wed, 24 Feb 2016 21:48:14 +, mahdi wrote: > Suppose we have a function like this: > > void diss(int[] array) ... > > How can we detect is `array` is static (fixed size) or dynamic, > inside the function body? Static arrays point to memory on the stack, inside an aggregate type on the

Re: ErrnoException

2016-02-29 Thread Chris Wright via Digitalmars-d-learn
On Mon, 29 Feb 2016 21:55:49 +, Jirka wrote: > Yes, that I understand, but the "new" operator can lead to other system > calls (?), could they overwrite it? Yes. Most obviously, the GC uses malloc, which will set errno to ENOMEM on failure.

Re: Can D "prevents segfaults, and guarantees thread safety"?

2016-02-22 Thread Chris Wright via Digitalmars-d-learn
On Tue, 23 Feb 2016 04:28:14 +, mahdi wrote: > A selling point of Rust language is that it "prevents segfaults, > and guarantees thread safety". Is there a library in D language which > provides same features? D is more for providing safe defaults than for entirely preventing problems. The

Re: Minimise and collect by GC when OutOfMemory

2016-02-26 Thread Chris Wright via Digitalmars-d-learn
On Fri, 26 Feb 2016 05:47:08 +, tcak wrote: > Would it be a good idea to call "collect" and "minimize" methods of > core.memory.GC when OutOfMemory error is received FOR A LONG RUNNING > PROGRAM? or there won't be any benefit of that? > > Example program: A web server that allocates and

Re: dub: how to reference a compiled package

2016-02-26 Thread Chris Wright via Digitalmars-d-learn
On Fri, 26 Feb 2016 03:19:26 +, mahdi wrote: > Great! Thanks. > > I was looking for a feature like `jar` files in Java or `assemblies` in > C# where all compiled code and metadata/symbols are stored together > inside a single binary file. C# and Java provide their own linkers and specify

Re: How to detect if an array if dynamic or static

2016-02-25 Thread Chris Wright via Digitalmars-d-learn
On Thu, 25 Feb 2016 02:08:18 +, Adam D. Ruppe wrote: > On Thursday, 25 February 2016 at 01:31:17 UTC, Chris Wright wrote: >> When you get to GC-allocated stuff, there's no way to tell. > > The GC is easy, you can simply ask it: > >

Re: Disabling GC in D

2016-01-21 Thread Chris Wright via Digitalmars-d-learn
On Thu, 21 Jan 2016 21:54:36 +, Dibyendu Majumdar wrote: > Is there a way to disable GC in D? > I am aware of the @nogc qualifier but I would like to completely disable > GC for the whole app/library. > > Regards Dibyendu In order to suppress GC collections, you can call

Re: writeln wipes contents of variables ?

2016-01-21 Thread Chris Wright via Digitalmars-d-learn
On Thu, 21 Jan 2016 14:07:16 +, W.J. wrote: > So writeln consumes the values in an InputRange. That leads me to > believe that if I feed an InputRange to foreach, it will consume the > values, too. > Did I get that right ? In general, yes. Some ranges have value semantics and can be saved

Re: How to represent struct with trailing array member

2016-01-21 Thread Chris Wright via Digitalmars-d-learn
On Thu, 21 Jan 2016 21:52:06 +, Dibyendu Majumdar wrote: > Hi > > I have C code where the struct has a trailing array member: > > struct matrix { >int rows; >int cols; >double data[1]; > }; > > In C code this is allocated dynamically to be variable size. The array > is used

Is memory-safe IO possible?

2016-01-21 Thread Chris Wright via Digitalmars-d-learn
I want everything I do to be memory-safe insofar as possible. One of the things I'm doing is communicating to REST services using std.net.curl. std.net.curl isn't marked @safe or @trusted. Is it possible to have properly memory-safe IO?

Re: Is memory-safe IO possible?

2016-01-22 Thread Chris Wright via Digitalmars-d-learn
On Fri, 22 Jan 2016 11:38:51 -0800, H. S. Teoh via Digitalmars-d-learn wrote: > @safe still isn't quite there yet, because it doesn't quite prevent all > of the things it ought to prevent. Well, that makes it suboptimal, certainly. But having almost no existing IO options that are @safe makes it

Re: Error using templates: "cannot use template to add field to aggregate ''"

2016-01-25 Thread Chris Wright via Digitalmars-d-learn
On Mon, 25 Jan 2016 14:51:21 +, pineapple wrote: > I'm getting several of these since I'm trying to do the same thing in a > few places. Here's a complete error: > > path\to\file.d(55): Error: variable > units.unitvalue.opmethod!("sum(in unitvalue value)", > "add(value)").methodtemplate

Re: Can't add ubytes together to make a ubyte... bug or feature?

2016-01-19 Thread Chris Wright via Digitalmars-d-learn
On Tue, 19 Jan 2016 23:32:57 +0100, Daniel Kozak wrote: > Soviet Friend píše v Út 19. 01. 2016 v 22:12 +: >> I just attempted to add one ubyte to another and store the result in a >> ubyte but apparently ubytes get converted to ints when being added... >> and converting what becomes an int

Re: Define "createXXX" functions for the constructors of class XXX

2016-01-23 Thread Chris Wright via Digitalmars-d-learn
On Sat, 23 Jan 2016 19:42:29 +, Johan Engelen wrote: > // Somehow define these guys automatically, "genCreateCtors!(XXX)" ? >XXX createXXX(int a, int b) { return new XXX(a, b); } >XXX createXXX(bool flag) { return new XXX(flag); } Check out http://dpaste.dzfl.pl/430dabf25935 I used

Re: Speed of csvReader

2016-01-26 Thread Chris Wright via Digitalmars-d-learn
On Tue, 26 Jan 2016 18:16:28 +, Gerald Jansen wrote: > On Thursday, 21 January 2016 at 21:24:49 UTC, H. S. Teoh wrote: >> >> While this is no fancy range-based code, and one might say it's more >> hackish and C-like than idiomatic D, the problem is that current D >> compilers can't quite

Re: Is memory-safe IO possible?

2016-01-22 Thread Chris Wright via Digitalmars-d-learn
On Fri, 22 Jan 2016 08:36:14 +, Kagamin wrote: > Should be possible. Why not? Because almost no IO routines in Phobos are marked @safe, which implies that it's difficult in practice or that people simply haven't done it. I checked std.file, std.net.curl, and std.stdio; a handful of things

Re: First project: questions on how-to, and on language features

2016-01-24 Thread Chris Wright via Digitalmars-d-learn
On Sun, 24 Jan 2016 06:07:13 +, Alex Vincent wrote: > Source code: > https://alexvincent.us/d-language/samples/intervalmap-rev1.d.txt There is no documentation, so I have no idea what you're trying to achieve here. So your questions about why this isn't in Phobos, whether there are any

Re: Create an empty json object with std.json

2016-01-22 Thread Chris Wright via Digitalmars-d-learn
On Fri, 22 Jan 2016 17:34:58 +, userABCabc123 wrote: > It's true that it can be problematic, for example with an input > contract, or for subtyping a JSONValue as something like struct > JSONValueThatAlwayObject{}... > > But there is only 3 ways in std.json, from a literal, using the >

Re: Running task once a day in vibe.d

2016-02-16 Thread Chris Wright via Digitalmars-d-learn
On Tue, 16 Feb 2016 18:30:43 +, Nick wrote: > Hey folks > > I'm making a vibe.d application. Once a day it needs to download some > data. How do i get the program to perform this task once a day? > > Regards, Nick http://vibed.org/api/vibe.core.core/runTask

Re: Coverage

2016-02-16 Thread Chris Wright via Digitalmars-d-learn
On Tue, 16 Feb 2016 10:35:38 -0200, Leandro Motta Barros via Digitalmars-d-learn wrote: > You probably already though of it, but: can't you create a unittest that > calls your code as many times as desired, passing different input each > time? dmd -cov doesn't look specifically at unittests, so

Re: Running task once a day in vibe.d

2016-02-17 Thread Chris Wright via Digitalmars-d-learn
On Wed, 17 Feb 2016 18:55:42 +, Zardoz wrote: > On Tuesday, 16 February 2016 at 18:30:43 UTC, Nick wrote: >> Hey folks >> >> I'm making a vibe.d application. Once a day it needs to download some >> data. How do i get the program to perform this task once a day? >> >> Regards, Nick > > Why

Re: Modify Function Pointer to Take Additional Parameters

2016-02-19 Thread Chris Wright via Digitalmars-d-learn
On Fri, 19 Feb 2016 20:45:23 +, jmh530 wrote: > I tried to use a cast (below) to modify the function pointer, but it is > printing the second number instead of the first. I find this behavior > strange... If you want to cast function pointers successfully, you have to know the D calling

Re: Modify Function Pointer to Take Additional Parameters

2016-02-19 Thread Chris Wright via Digitalmars-d-learn
On Fri, 19 Feb 2016 21:57:46 +, Yuxuan Shui wrote: > I don't think it's safe to convert between function pointer with > different number of arguments... It's possible to mess up the stack > frame. I tested this a fair bit today, and I haven't been able to do any of the nefarious things I

Re: 111

2016-02-19 Thread Chris Wright via Digitalmars-d-learn
On Sat, 20 Feb 2016 00:04:04 +, Lisa wrote: > On Saturday, 20 February 2016 at 00:01:47 UTC, cym13 wrote: >> On Friday, 19 February 2016 at 23:56:29 UTC, Lisa wrote: >>> Can you please help me and explain how to create a program, >>> which would find area of triangle and its perimeter? >> >>

Re: 111

2016-02-19 Thread Chris Wright via Digitalmars-d-learn
On Sat, 20 Feb 2016 00:17:28 +, Lisa wrote: > On Saturday, 20 February 2016 at 00:15:16 UTC, Chris Wright wrote: >> On Sat, 20 Feb 2016 00:04:04 +, Lisa wrote: >> >>> On Saturday, 20 February 2016 at 00:01:47 UTC, cym13 wrote: On Friday, 19 February 2016 at 23:56:29 UTC, Lisa wrote:

Status icon on Linux

2016-02-19 Thread Chris Wright via Digitalmars-d-learn
I want a status icon for a Linux application. gtk.StatusIcon notes that it's deprecated (and doesn't work on MATE 1.8.2). What should I be using?

Re: Why does partial ordering of overloaded functions not take return type into account?

2016-02-20 Thread Chris Wright via Digitalmars-d-learn
On Sat, 20 Feb 2016 15:47:27 +, Jeremy DeHaan wrote: > If there are multiple overloads that have the same number of parameters, > a very simple addition to the rules of function overloading would be > "does it compile?" If only one overload compiles, use it. If more than > one compile, there

Re: What happens if memory allocation fails?

2016-02-20 Thread Chris Wright via Digitalmars-d-learn
On Sat, 20 Feb 2016 16:58:02 +, Adam D. Ruppe wrote: > On Saturday, 20 February 2016 at 14:21:28 UTC, tcak wrote: >> What happens if memory allocation fails with "new" keyword? > > Be aware that memory allocation might never actually fail. It really > depends on the operating system. > >

Re: GC scan for pointers

2016-03-09 Thread Chris Wright via Digitalmars-d-learn
On Wed, 09 Mar 2016 15:50:43 +, Adam D. Ruppe wrote: > Or static > arrays of int on the stack will also be scanned, since the GC doesn't > actually know much about local variables It's especially tricky because compilers can reuse memory on the stack -- for instance, if I use one variable

Re: How to sort a range

2016-03-09 Thread Chris Wright via Digitalmars-d-learn
On Wed, 09 Mar 2016 14:28:11 +, cym13 wrote: > Note that an input range isn't even remotely a container Which is why sort() has template constraints beyond isInputRange. The constraints ensure that it is possible to swap values in the range.

Re: Is D a good choice for embedding python/octave/julia

2016-03-13 Thread Chris Wright via Digitalmars-d-learn
On Sun, 13 Mar 2016 13:02:16 +, Bastien wrote: > The sticking point is unless I commit the rest of my life to maintaining > this software, I can't write it all in D. The algorithms change/are > improved yearly; the output format from the instrument changes once in a > while and therefore these

Re: How to return a const handle (view) to a mutable member of an agregate

2016-03-13 Thread Chris Wright via Digitalmars-d-learn
On Sun, 13 Mar 2016 21:14:59 +, anonymous wrote: > On Sunday, 13 March 2016 at 20:10:57 UTC, Basile B. wrote: >> ref const(Array!Type) view(){} >> >> Unless the result is explicitly cast later it can't me modified. > > No, it can't be modified, period. Casting away const and then mutating >

Re: static if else behavior and is type comparison

2016-03-11 Thread Chris Wright via Digitalmars-d-learn
On Fri, 11 Mar 2016 00:21:33 -0800, Ali Çehreli wrote: > You've been bitten by a common usability issue. :) > > On 03/11/2016 12:02 AM, Fynn Schröder wrote: > > static if (is(U == ubyte)) { > > pragma(msg, "is ubyte"); > > return fnUbyte(); > > } else if (is(U ==

Re: Can DUB --combined builds be faster?

2016-03-14 Thread Chris Wright via Digitalmars-d-learn
On Tue, 15 Mar 2016 01:54:51 +, thedeemon wrote: > On Monday, 14 March 2016 at 11:50:38 UTC, Rene Zwanenburg wrote: > >> When building in release mode the call to foo() gets inlined just fine >> without --combined. > > How does it work? Is it because the source of foo() is visible to the >

Re: Variant.type bug ?

2016-03-23 Thread Chris Wright via Digitalmars-d-learn
Consider the `coerce` method: http://dpldocs.info/experimental-docs/std.variant.VariantN.coerce.html Example: import std.variant; class A {} class B : A {} void main() { A b = new B; auto bb = Variant(b).coerce!B; assert (bb !is null); }

Re: Updating D-based apps without recompiling it

2016-03-23 Thread Chris Wright via Digitalmars-d-learn
On Wed, 23 Mar 2016 12:21:33 +, Ozan wrote: > Enterprise applications in productive environments requires smooth > updating mechanisms without recompiling or reinstalling. The industry standard is to build on a build server and stop the application to update, but to have enough redundancy

Re: byChunk odd behavior?

2016-03-23 Thread Chris Wright via Digitalmars-d-learn
On Wed, 23 Mar 2016 03:17:05 +, Hanh wrote: > In Scala, 'take' consumes bytes from the iterator. So the same code > would be buffer = range.take(N).toArray import std.range, std.array; auto bytes = byteRange.takeExactly(N).array; There's also take(N), but if the range contains fewer than N

Re: Randomized unittests

2016-07-24 Thread Chris Wright via Digitalmars-d-learn
On Mon, 25 Jul 2016 01:49:25 +, Gorge Jingale wrote: > Is there any leverage in the D library for doing randomized unit > testing? Testing things with a range of possibilities instead of fixed. > Each time the test is ran a different version is executed. > This provides more coverage. > >