Re: Dynamic / resizable array type, and a crash problem

2015-05-14 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 14 May 2015 at 13:26:27 UTC, ivoras wrote: Is it resizable? You can append with the ~= operator and size down by slicing it. Apparently it doesn't even have an insert method: http://dlang.org/phobos/std_array.html . http://dlang.org/phobos/std_array.html#insertInPlace is the

Re: Dynamic / resizable array type, and a crash problem

2015-05-14 Thread ivoras via Digitalmars-d-learn
On Thursday, 14 May 2015 at 12:46:48 UTC, Adam D. Ruppe wrote: I would just use a regular `string[]` array... Is it resizable? Somehow I didn't get that impression from the docs. Apparently it doesn't even have an insert method: http://dlang.org/phobos/std_array.html .

Re: Dynamic / resizable array type, and a crash problem

2015-05-14 Thread Namespace via Digitalmars-d-learn
On Thursday, 14 May 2015 at 13:26:27 UTC, ivoras wrote: On Thursday, 14 May 2015 at 12:46:48 UTC, Adam D. Ruppe wrote: I would just use a regular `string[]` array... Is it resizable? Somehow I didn't get that impression from the docs. Apparently it doesn't even have an insert method:

Dynamic / resizable array type, and a crash problem

2015-05-14 Thread ivoras via Digitalmars-d-learn
What is the recommended dynamic array type in D? So far I found Array (specifically Array!string, as I need a dynamic array of strings), but my example program crashes: https://gist.github.com/ivoras/2d7737c214c3dc937c28 The crash is at line 20:

Re: Returning an empty range of a given type

2015-05-14 Thread rcorre via Digitalmars-d-learn
So I thought this might work: struct MaybeEmpty(R) if (isInputRange!R) { private bool _isEmpty; private R_input; alias _input this; this(bool isEmpty, R input) { _input = input; _isEmpty = isEmpty; } @property bool empty() { return _isEmpty || _input.empty; } }

Re: Dynamic / resizable array type, and a crash problem

2015-05-14 Thread anonymous via Digitalmars-d-learn
On Thursday, 14 May 2015 at 12:42:01 UTC, ivoras wrote: https://gist.github.com/ivoras/2d7737c214c3dc937c28 The crash is at line 20: core.exception.AssertError@/usr/include/dmd/phobos/std/container/array.d(334): [...] This is on DMD32 D Compiler v2.067.1 Seems to be fixed in git head.

Re: Dynamic / resizable array type, and a crash problem

2015-05-14 Thread Adam D. Ruppe via Digitalmars-d-learn
I would just use a regular `string[]` array...

Re: Cannot Qualify Variadic Functions with Lazy Arguments as nothrow

2015-05-14 Thread via Digitalmars-d-learn
On Thursday, 14 May 2015 at 10:18:13 UTC, Maxim Fomin wrote: On Thursday, 14 May 2015 at 09:53:20 UTC, Per Nordlöw wrote: At https://github.com/nordlow/justd/blob/master/algorithm_ex.d#L43 I've implemented a function either() with behaviour similar to the `or` function/operator in dynamic

Re: problem with parallel foreach

2015-05-14 Thread John Colvin via Digitalmars-d-learn
On Thursday, 14 May 2015 at 10:46:53 UTC, Gerald Jansen wrote: John Colvin's improvements to my D program seem to have resolved the problem. (http://forum.dlang.org/post/ydgmzhlspvvvrbeem...@forum.dlang.org and http://dpaste.dzfl.pl/114d5a6086b7). I have rerun my tests and now the picture is a

Re: Clean way to tell whether a destructor is called by the GC

2015-05-14 Thread ponce via Digitalmars-d-learn
On Wednesday, 13 May 2015 at 11:24:10 UTC, Kagamin wrote: On Tuesday, 12 May 2015 at 12:53:59 UTC, ponce wrote: I already have such a dispose() function. The problem is that to support Unique! and scoped! and friends, the destructor must call dispose(). Thus my need for a way to separate the

How to simulate a new type

2015-05-14 Thread Charles Hixson via Digitalmars-d-learn
What are the downsides to simulating a new type with a struct. What I have in mind is something along the lines of: struct myType { uint64_t value; } The goal of this type is to prevent accidental conversions from myType into ints, uint64_ts, etc.

Re: Cannot Qualify Variadic Functions with Lazy Arguments as nothrow

2015-05-14 Thread anonymous via Digitalmars-d-learn
On Thursday, 14 May 2015 at 09:53:20 UTC, Per Nordlöw wrote: I'm almost satisified with it except that the lazy evaluation at https://github.com/nordlow/justd/blob/master/algorithm_ex.d#L45 cannot be made nothrow. If I qualify the function as nothrow DMD complains as algorithm_ex.d(45,16):

Re: Returning an empty range of a given type

2015-05-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/13/15 10:58 PM, rcorre wrote: Actually, this doesn't even seem to work with a custom range: import std.range; import std.stdio; import std.algorithm; struct MyContainer { @nogc auto opSlice() { struct Range { @property bool empty() { return true; }

Re: Returning an empty range of a given type

2015-05-14 Thread Idan Arye via Digitalmars-d-learn
On Thursday, 14 May 2015 at 12:40:57 UTC, rcorre wrote: So I thought this might work: struct MaybeEmpty(R) if (isInputRange!R) { private bool _isEmpty; private R_input; alias _input this; this(bool isEmpty, R input) { _input = input; _isEmpty = isEmpty; } @property

Re: Array of objects and their inheritance

2015-05-14 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 14 May 2015 at 19:00:16 UTC, tired_eyes wrote: First, I don't understand why we see array[2] as 'Child'. While it is a 'Child', shouldn't it be shown as a 'Parent' due to we explicitly create an array of 'Parents'? It is getting the name through a virtual interface (a hidden one

Re: Dynamic / resizable array type, and a crash problem

2015-05-14 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 14 May 2015 at 20:03:16 UTC, ivoras wrote: Where would I look for documentation on the ~= operator? http://dlang.org/arrays.html under the heading array concatenation What would be the difference between Array!string and string[] ? Array!string takes ownership of its own

Re: How to simulate a new type

2015-05-14 Thread Laeeth Isharc via Digitalmars-d-learn
On Thursday, 14 May 2015 at 18:42:56 UTC, Charles Hixson wrote: What are the downsides to simulating a new type with a struct. What I have in mind is something along the lines of: struct myType { uint64_t value; } The goal of this type is to prevent accidental conversions from myType into

Re: Dynamic / resizable array type, and a crash problem

2015-05-14 Thread ivoras via Digitalmars-d-learn
On Thursday, 14 May 2015 at 20:32:28 UTC, rumbu wrote: On Thursday, 14 May 2015 at 20:03:16 UTC, ivoras wrote: What would be the difference between Array!string and string[] ? std.array is used to manipulate or create built-in arrays from various sources (ranges). For basic needs, you

Array of objects and their inheritance

2015-05-14 Thread tired_eyes via Digitalmars-d-learn
Hi. I'm having a hard time understanding D's inheritance. Consider the following code: class Parent { public int x = 10; } class Child : Parent { public int y = 20; } void main() { import std.stdio; Parent[] array; auto obj1 = new Parent(); auto obj2 = new Child();

Re: What wrong?

2015-05-14 Thread sclytrack via Digitalmars-d-learn
On Tuesday, 5 May 2015 at 07:41:04 UTC, sclytrack wrote: On Monday, 4 May 2015 at 01:03:43 UTC, Fyodor Ustinov wrote: On Saturday, 2 May 2015 at 20:46:32 UTC, Dennis Ritchie wrote: On Saturday, 2 May 2015 at 19:38:01 UTC, Fyodor Ustinov wrote: I see it by the lack of 42. :) But why is this

Re: Dynamic / resizable array type, and a crash problem

2015-05-14 Thread ivoras via Digitalmars-d-learn
On Thursday, 14 May 2015 at 13:50:17 UTC, Adam D. Ruppe wrote: On Thursday, 14 May 2015 at 13:26:27 UTC, ivoras wrote: Is it resizable? You can append with the ~= operator and size down by slicing it. Apparently it doesn't even have an insert method: http://dlang.org/phobos/std_array.html .

Re: Dynamic / resizable array type, and a crash problem

2015-05-14 Thread rumbu via Digitalmars-d-learn
On Thursday, 14 May 2015 at 20:03:16 UTC, ivoras wrote: What would be the difference between Array!string and string[] ? std.array is used to manipulate or create built-in arrays from various sources (ranges). For basic needs, you can safely use built-in arrays:

Re: Feature or bug: print braces

2015-05-14 Thread Ali Çehreli via Digitalmars-d-learn
On 05/14/2015 03:39 PM, Dennis Ritchie wrote: On Thursday, 14 May 2015 at 21:55:40 UTC, Alex Parrill wrote: On Thursday, 14 May 2015 at 00:39:25 UTC, Dennis Ritchie wrote: On Thursday, 14 May 2015 at 00:33:33 UTC, Brian Schott wrote: You told it to output a function literal, so it did. Yes,

Re: Feature or bug: print braces

2015-05-14 Thread Alex Parrill via Digitalmars-d-learn
On Thursday, 14 May 2015 at 00:39:25 UTC, Dennis Ritchie wrote: On Thursday, 14 May 2015 at 00:33:33 UTC, Brian Schott wrote: You told it to output a function literal, so it did. Yes, but it would be logical to deduce something like: - writeln({}); // prints literal[{}] Or the compiler

Re: Feature or bug: print braces

2015-05-14 Thread Dennis Ritchie via Digitalmars-d-learn
On Thursday, 14 May 2015 at 21:55:40 UTC, Alex Parrill wrote: On Thursday, 14 May 2015 at 00:39:25 UTC, Dennis Ritchie wrote: On Thursday, 14 May 2015 at 00:33:33 UTC, Brian Schott wrote: You told it to output a function literal, so it did. Yes, but it would be logical to deduce something

Re: How to simulate a new type

2015-05-14 Thread Charles Hixson via Digitalmars-d-learn
On 05/14/2015 01:42 PM, Laeeth Isharc via Digitalmars-d-learn wrote: On Thursday, 14 May 2015 at 18:42:56 UTC, Charles Hixson wrote: What are the downsides to simulating a new type with a struct. What I have in mind is something along the lines of: struct myType { uint64_t value; } The

Re: How to simulate a new type

2015-05-14 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 15 May 2015 at 01:03:32 UTC, Charles Hixson wrote: Yes, that looks as if it would do the job, but what are its advantages over a simple struct? None really, except perhaps automatic forwarding of operators which is easy enough to do on a struct too (and with a struct, you can do

Re: Feature or bug: print braces

2015-05-14 Thread Dennis Ritchie via Digitalmars-d-learn
On Thursday, 14 May 2015 at 22:55:43 UTC, Ali Çehreli wrote: Yes, it is weird but that value happens to be the address of the function. Here is another test: import std.stdio; void foo() pure nothrow @nogc @safe {} void main() { void printInfo(T)(T t) { writefln(%s %s,

Re: Returning an empty range of a given type

2015-05-14 Thread rcorre via Digitalmars-d-learn
On Thursday, 14 May 2015 at 06:41:45 UTC, Ali Çehreli wrote: I am lucky because although the returned type is opaque to me, I know that it is constructed by a void lambda. Yeah, in this case I control the container so I may just add an emptySlice property, but it does seem like it might be

Re: Returning an empty range of a given type

2015-05-14 Thread Ali Çehreli via Digitalmars-d-learn
On 05/13/2015 07:47 PM, rcorre wrote: I've run into this situation a lot: I have a function that returns a range (in this case, a slice of a custom container). In some cases, the function needs to return an empty range. It sounded like takeNone was what I wanted: @nogc auto fun() { return

Re: problem with parallel foreach

2015-05-14 Thread Gerald Jansen via Digitalmars-d-learn
John Colvin's improvements to my D program seem to have resolved the problem. (http://forum.dlang.org/post/ydgmzhlspvvvrbeem...@forum.dlang.org and http://dpaste.dzfl.pl/114d5a6086b7). I have rerun my tests and now the picture is a bit different (see tables below). In the middle table I have

Cannot Qualify Variadic Functions with Lazy Arguments as nothrow

2015-05-14 Thread via Digitalmars-d-learn
At https://github.com/nordlow/justd/blob/master/algorithm_ex.d#L43 I've implemented a function either() with behaviour similar to the `or` function/operator in dynamic languages such as Python and Lisp. I'm almost satisified with it except that the lazy evaluation at

Re: Cannot Qualify Variadic Functions with Lazy Arguments as nothrow

2015-05-14 Thread Maxim Fomin via Digitalmars-d-learn
On Thursday, 14 May 2015 at 09:53:20 UTC, Per Nordlöw wrote: At https://github.com/nordlow/justd/blob/master/algorithm_ex.d#L43 I've implemented a function either() with behaviour similar to the `or` function/operator in dynamic languages such as Python and Lisp. I'm almost satisified with

Re: Returning an empty range of a given type

2015-05-14 Thread rcorre via Digitalmars-d-learn
On Thursday, 14 May 2015 at 14:57:26 UTC, Idan Arye wrote: How about a more flexible solution? http://dpaste.dzfl.pl/2f99cc270651 Neat, thanks! On Thursday, 14 May 2015 at 18:44:58 UTC, Steven Schveighoffer wrote: It depends on the guts of MyContainer.Range. I'm assuming

Linking to Dynamic Library on Mac OS X

2015-05-14 Thread TJB via Digitalmars-d-learn
I have built a toy dynamic shared library on Mac OS X (in C), and I have verified that it works from C. Now I would like to call it from D. So I have created the following interface file: $ cat hello.di extern (C): void printHelloWorld(); which I try to compile and run. But I get the

Re: Returning an empty range of a given type

2015-05-14 Thread rcorre via Digitalmars-d-learn
On Friday, 15 May 2015 at 03:22:43 UTC, rcorre wrote: On Thursday, 14 May 2015 at 14:57:26 UTC, Idan Arye wrote: How about a more flexible solution? http://dpaste.dzfl.pl/2f99cc270651 Neat, thanks! The range I don't pick may be an expression that would fail, so I tweaked it to: