Re: Is D suitable for my latest project?

2015-09-09 Thread Atila Neves via Digitalmars-d-learn
On Sunday, 6 September 2015 at 14:36:53 UTC, chris stevens wrote: Hi All, I am considering using D for my latest project and there are a few features I would like and am not entirely sure at this point whether D has them. They are: - dynamic creation of classes/structs at runtime (think I

Re: What is "FilterResult" type?

2015-09-09 Thread Atila Neves via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 07:19:06 UTC, Bahman Movaqar wrote: On Tuesday, 8 September 2015 at 18:45:33 UTC, Jonathan M Davis wrote: If you're returning a range, you should be returning auto. @Jonathan, @cym13 and @Meta It's reasonable to use `auto`. However there are times when you

Re: Why 1f.iota(100f).array returns double[] not float[]?

2015-09-09 Thread Ali Çehreli via Digitalmars-d-learn
On 09/08/2015 06:37 AM, Steven Schveighoffer wrote: I think this warrants a bug report, iota with only floats as parameters should result in floats. https://issues.dlang.org/show_bug.cgi?id=15033 Ali

Re: What's the "right" way to do openmp-style parallelism?

2015-09-09 Thread Russel Winder via Digitalmars-d-learn
On Tue, 2015-09-08 at 07:33 +, Dominikus Dittes Scherkl via Digitalmars-d-learn wrote: > On Tuesday, 8 September 2015 at 05:50:30 UTC, Russel Winder wrote: > > void main() { > > immutable imax = 10; > > immutable jmax = 10; > > float[imax][jmax] x; > > foreach(int

Re: class destruction

2015-09-09 Thread ponce via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 07:19:58 UTC, Q wrote: Hi. I'm playing around with D for a while and I would like to switch. But here is one thing, I need an answer for. In the Docs is mentioned that it is not sure that the DTor of a class is called. But what if I have struct, which holds a

Re: What is "FilterResult" type?

2015-09-09 Thread Sebastiaan Koppe via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 07:19:06 UTC, Bahman Movaqar wrote: The only way to make it work is `.array.idup` the output of `filter`. For example: auto result = reduce!( (acc, num) => acc.filter!( fb => (fb.x < num && fb.y < num) && (fb.x * fb.y > num)

Re: Is D suitable for my latest project?

2015-09-09 Thread Kagamin via Digitalmars-d-learn
On Tuesday, 8 September 2015 at 20:01:15 UTC, chris stevens wrote: Thanks for the reply Kagamin, just had a quick look at dparse and not sure how I could use it in the way you describe. Any examples of this? As I understand, you wanted to build an AST tree and format it to string?

Re: class destruction

2015-09-09 Thread Kagamin via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 07:19:58 UTC, Q wrote: Besides, we live in 2015 and that is not C where I have to clean my code manually, so this option would be ridiculous :D The difference is that in C you need to manage POD memory too. Manual management of non-POD resources is a problem

Re: What is "FilterResult" type?

2015-09-09 Thread cym13 via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 07:19:06 UTC, Bahman Movaqar wrote: On Tuesday, 8 September 2015 at 18:45:33 UTC, Jonathan M Davis wrote: [...] @Jonathan, @cym13 and @Meta It's reasonable to use `auto`. However there are times when you need to pass the `auto` value to another function and

Re: What is "FilterResult" type?

2015-09-09 Thread Bahman Movaqar via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 07:59:57 UTC, Sebastiaan Koppe wrote: What is going wrong is that the types aren't the same. That is, the type of the seed you supplied - `typeof(foobars)` - isn't the type that your function returns - `typeof(acc.filter!...)`. Alright. So, `reduce` initial

Re: What is "FilterResult" type?

2015-09-09 Thread Bahman Movaqar via Digitalmars-d-learn
On Tuesday, 8 September 2015 at 18:45:33 UTC, Jonathan M Davis wrote: If you're returning a range, you should be returning auto. @Jonathan, @cym13 and @Meta It's reasonable to use `auto`. However there are times when you need to pass the `auto` value to another function and the receiving

class destruction

2015-09-09 Thread Q via Digitalmars-d-learn
Hi. I'm playing around with D for a while and I would like to switch. But here is one thing, I need an answer for. In the Docs is mentioned that it is not sure that the DTor of a class is called. But what if I have struct, which holds a C Handle which is destroyed as soon as the struct gets

C++ Interop -- Two Questions

2015-09-09 Thread Mike Parker via Digitalmars-d-learn
Given a C++ class that looks like this: class Foo { static void Initialize(const SomeObject&); virtual void func1(); } The documentation at [1] doesn't say anything about how to handle static member functions like Initialize, nor do I see anything about references. I assume I can

Re: Is D suitable for my latest project?

2015-09-09 Thread chris stevens via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 08:24:06 UTC, Kagamin wrote: As I understand, you wanted to build an AST tree and format it to string? Thanks again. So I can build an AST and convert it to full D source from that? I think that's what i'm likely going need to do.

Re: C++ Interop -- Two Questions

2015-09-09 Thread Mike Parker via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 09:55:21 UTC, Mike Parker wrote: The documentation at [1] doesn't say anything about how to [1] http://dlang.org/cpp_interface.html

Re: Is D suitable for my latest project?

2015-09-09 Thread chris stevens via Digitalmars-d-learn
On Tuesday, 8 September 2015 at 21:51:03 UTC, wobbles wrote: "Previously undefined". As far as I know, this is impossible in D. Thr compiler has to know how much memory to allocate/request and it has to know that at compiletime (else it wouldn't be the compiler!)

Re: What is "FilterResult" type?

2015-09-09 Thread Bahman Movaqar via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 08:29:20 UTC, cym13 wrote: You are using reduce in a weird way here... Oh? Perhaps it was all because of the lame example I used :-) The real problem I was trying to solve, source of which I just pushed[1], was the `select` method on line 130. Is this

Re: Is D suitable for my latest project?

2015-09-09 Thread chris stevens via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 09:14:30 UTC, Atila Neves wrote: So, if your use-case depends on information from the file-system, user interaction, networking, etc. then your only choice is to generate text files with D code and compile it. If, on the other hand, it's all defined by the

Re: Is D suitable for my latest project?

2015-09-09 Thread chris stevens via Digitalmars-d-learn
On Tuesday, 8 September 2015 at 21:51:03 UTC, wobbles wrote: "Previously undefined". As far as I know, this is impossible in D. Thr compiler has to know how much memory to allocate/request and it has to know that at compiletime (else it wouldn't be the compiler!) There was also this:

Re: C++ Interop -- Two Questions

2015-09-09 Thread Jacob Carlborg via Digitalmars-d-learn
On 2015-09-09 11:55, Mike Parker wrote: Given a C++ class that looks like this: class Foo { static void Initialize(const SomeObject&); virtual void func1(); } The documentation at [1] doesn't say anything about how to handle static member functions like Initialize, nor do I see

Re: Is D suitable for my latest project?

2015-09-09 Thread Ali Çehreli via Digitalmars-d-learn
On 09/08/2015 12:30 PM, chris stevens wrote: > create new > (previously undefined) classes in D at runtime that I could then use > with Object.factory to create instances of. SDC is a D compiler as a library but as far as I know, it's not complete yet: https://github.com/SDC-Developers/SDC

Re: Why 1f.iota(100f).array returns double[] not float[]?

2015-09-09 Thread Nordlöw
On Wednesday, 9 September 2015 at 06:37:17 UTC, Ali Çehreli wrote: https://issues.dlang.org/show_bug.cgi?id=15033 Ali https://github.com/D-Programming-Language/phobos/pull/3641

Re: What is "FilterResult" type?

2015-09-09 Thread Bahman Movaqar via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 09:08:28 UTC, Atila Neves wrote: No, it doesn't. It needs to know what the compile-time interface is, i.e. what it can do with that type. If the type in question happens to be an InputRange, then the consumer function would be: void func(R)(R range)

Re: C++ Interop -- Two Questions

2015-09-09 Thread Kagamin via Digitalmars-d-learn
Static functions are declared with `static` storage class. This looks so basic, it's even not documented in language spec, lol. In D classes are reference types by default.

Re: What is "FilterResult" type?

2015-09-09 Thread cym13 via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 11:30:26 UTC, Bahman Movaqar wrote: For the lame example I gave, something similar occurred to me at first; but then I thought 4 `filter`s (assuming `all` is simply a `filter`) might be non-idiomatic as it might incur some performance penalty. As those are

Re: C++ Interop -- Two Questions

2015-09-09 Thread Mike Parker via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 11:49:33 UTC, Kagamin wrote: Static functions are declared with `static` storage class. This looks so basic, it's even not documented in language spec, lol. Yes, I get that. But how does that work when you're linking to a C++ library and the translation of

Re: class destruction

2015-09-09 Thread Q via Digitalmars-d-learn
But if others use my code they must think about finalizing the classes? That is very awkward. I'll take a look at Rust and otherwise I will stick with C++. Thanks for you answer. :)

Re: class destruction

2015-09-09 Thread ponce via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 14:36:24 UTC, Q wrote: But if others use my code they must think about finalizing the classes? That is very awkward. classes, yes but structs, no. I'll take a look at Rust and otherwise I will stick with C++. Thanks for you answer. :) Well, resource

Re: class destruction

2015-09-09 Thread Q via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 15:32:58 UTC, Adam D. Ruppe wrote: On Wednesday, 9 September 2015 at 15:24:57 UTC, Q wrote: I thought that is not guaranteed, according to the docs? It is possible that the GC will never actually run, but you can force it to if you need it to by calling

Re: Is D suitable for my latest project?

2015-09-09 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 10:23:55 UTC, chris stevens wrote: http://wiki.dlang.org/Dynamic_typing This is what I saw that made me think that I could. Have had another closer look and I do believe it's possible. These are things I wrote, so let me explain how they work: they do not

Re: class destruction

2015-09-09 Thread Q via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 14:57:26 UTC, Adam D. Ruppe wrote: On Wednesday, 9 September 2015 at 07:19:58 UTC, Q wrote: Can I be sure that the Handle is destroyed as soon as the class is destroyed? It will do that automatically. Like the others said, you won't be sure when the class is

Re: class destruction

2015-09-09 Thread Q via Digitalmars-d-learn
And sorry if that sounds rude, I'm just in a hurry. I just think D is not mature enough for serious stuff. :) That is of course only my personal opinion.

Re: class destruction

2015-09-09 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 15:24:57 UTC, Q wrote: I thought that is not guaranteed, according to the docs? It is possible that the GC will never actually run, but you can force it to if you need it to by calling GC.collect at any time.

Re: class destruction

2015-09-09 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 15:37:50 UTC, Q wrote: Yes, but according to the specs it is not guaranteed that the GC calls the DTor if the Object is collected. Where? This page says pretty plainly: http://dlang.org/class.html#destructors "The garbage collector calls the destructor

Re: class destruction

2015-09-09 Thread Meta via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 15:37:50 UTC, Q wrote: Yes, but according to the specs it is not guaranteed that the GC calls the DTor if the Object is collected. Note that I believe this is the same as in Java (though not C#, interestingly enough). In Java an object's destructor is not

Re: C++ Interop -- Two Questions

2015-09-09 Thread Kagamin via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 13:17:53 UTC, Mike Parker wrote: Yes, I get that. But how does that work when you're linking to a C++ library and the translation of the C++ class to D is an interface? Or is it possible now to link D classes directly with C classes? Classes and templates

Re: class destruction

2015-09-09 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 07:19:58 UTC, Q wrote: Can I be sure that the Handle is destroyed as soon as the class is destroyed? It will do that automatically. Like the others said, you won't be sure when the class is destroyed unless you have the user code take ownership of it. (This

Re: class destruction

2015-09-09 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 15:10:33 UTC, Q wrote: But since D has a GC and (per default) force to heap allocate a class. So IMO the GC should also destroy it, everything else is just awkward. Well, it *does* by default. If that's what you want, just do it the plain way with simple

Re: class destruction

2015-09-09 Thread Q via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 15:19:04 UTC, Adam D. Ruppe wrote: On Wednesday, 9 September 2015 at 15:10:33 UTC, Q wrote: But since D has a GC and (per default) force to heap allocate a class. So IMO the GC should also destroy it, everything else is just awkward. Well, it *does* by

Re: What is the difference between D and C++ regarding Unique, RefCounted and Scoped?

2015-09-09 Thread ponce via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 20:17:44 UTC, cym13 wrote: This is subtly missing the main question: isn't C++-like memory management of D classes possible with Unique, RefCounted and Scoped? - Unique C++ has move semantics which make moves explicit. D's Unique is more like the

Re: friends with phobos, workaround?

2015-09-09 Thread Idan Arye via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 20:19:44 UTC, Daniel N wrote: For the record, I think D made the right decision... omitting friends. However there's one case in particular which I find useful, anyone see a good workaround for this? #include class Friendly { private: int val;

Re: using std.algorithm to find intersection of DateTime[][] arg

2015-09-09 Thread Sebastiaan Koppe via Digitalmars-d-learn
Couldn't you use setIntersection together with reduce? Doesn't seem like the most efficient solution, but its less typing and most likely will have no bugs.

friends with phobos, workaround?

2015-09-09 Thread Daniel N via Digitalmars-d-learn
For the record, I think D made the right decision... omitting friends. However there's one case in particular which I find useful, anyone see a good workaround for this? #include class Friendly { private: int val; Friendly(int&& val) : val(val) {} friend std::unique_ptr

using std.algorithm to find intersection of DateTime[][] arg

2015-09-09 Thread Laeeth Isharc via Digitalmars-d-learn
I have a DateTime[][] arg (actually my own date type, but that shouldnt matter). Ordered by time series ticker (eg a stock) and then the date. eg arg[0] might be the dates relating to IBM and arg[0][0] would be the date of the first point in IBM time series. I would like to find the

Re: What is the difference between D and C++ regarding Unique, RefCounted and Scoped?

2015-09-09 Thread via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 20:17:44 UTC, cym13 wrote: This is subtly missing the main question: isn't C++-like memory management of D classes possible with Unique, RefCounted and Scoped? I understand the limitations you mentioned, but it I don't think it is a good idea to tell C++

Re: ref parameter qualifier and static arrays

2015-09-09 Thread anonymous via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 20:18:57 UTC, Paul wrote: Is it possible to call a function like this... void foo(ref int[] anArray) ...with slices of static arrays? I thought I might be able to use [0..$-1] but to no avail - I get an error like this (which is confusing!): Note that the

Re: ref parameter qualifier and static arrays

2015-09-09 Thread anonymous via Digitalmars-d-learn
On Wednesday 09 September 2015 22:18, Paul wrote: > > Is it possible to call a function like this... > > void foo(ref int[] anArray) > > ...with slices of static arrays? I thought I might be able to use > [0..$-1] but to no avail - I get an error like this (which is > confusing!): > > (ref

Re: What is the difference between D and C++ regarding Unique, RefCounted and Scoped?

2015-09-09 Thread cym13 via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 20:34:03 UTC, Ola Fosheim Grøstad wrote: On Wednesday, 9 September 2015 at 20:17:44 UTC, cym13 wrote: This is subtly missing the main question: isn't C++-like memory management of D classes possible with Unique, RefCounted and Scoped? I understand the

Re: char[] ported from C to char[0] in the D core library

2015-09-09 Thread badlink via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 16:59:09 UTC, Adam D. Ruppe wrote: That's typically right, but since this case does it in-place instead of pointed, the zero length array is most accurate. I didn't consider that the name is placed right after the struct. Thanks !

Re: What is "FilterResult" type?

2015-09-09 Thread deed via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 11:30:26 UTC, Bahman Movaqar wrote: On Wednesday, 9 September 2015 at 08:29:20 UTC, cym13 wrote: The way I would have written it is: auto result = foobars.filter!(fb => nums.all!(n => (fb.x * fb.y) > n)) .filter!(fb => nums.all!(n => fb.x

char[] ported from C to char[0] in the D core library

2015-09-09 Thread badlink via Digitalmars-d-learn
The struct core.sys.linux.sys.inotify.inotify_event contains the field "char[0] name" which corresponds to "char name[]" in C. Why it has been translated to "char[0]" ? For me "char*" would have been more appropriate.

Re: char[] ported from C to char[0] in the D core library

2015-09-09 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 16:49:39 UTC, badlink wrote: The struct core.sys.linux.sys.inotify.inotify_event contains the field "char[0] name" which corresponds to "char name[]" in C. Why it has been translated to "char[0]" ? In that structure, the name is appended directly to the end

Re: OSX prompt limit

2015-09-09 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 01:35:26 UTC, Joel wrote: auto line = terminal.getline("your prompt: "); Huh, that should work unless your terminal is outrageously narrow or maybe output starting on the right side of the screen already. But I can't look much further without having a

Re: OSX prompt limit

2015-09-09 Thread Adam D. Ruppe via Digitalmars-d-learn
Maybe you can try gnu readline instead: extern(C) char* readline(const(char)* prompt); pragma(lib, "readline"); pragma(lib, "curses"); void main() { auto line = readline("your line: "); import std.stdio, std.conv; writeln(to!string(line)); }

Re: What is the difference between D and C++ regarding Unique, RefCounted and Scoped?

2015-09-09 Thread ponce via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 19:53:55 UTC, ponce wrote: Oops, posted by mistake. On Wednesday, 9 September 2015 at 19:48:00 UTC, cym13 wrote: Hi, I know C++ and D without being a C++ or D guru (I know way more about D though). When talking about memory management the problem of RAII is

Re: What is the difference between D and C++ regarding Unique, RefCounted and Scoped?

2015-09-09 Thread cym13 via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 20:05:06 UTC, ponce wrote: C++ only has a D struct equivalent so all destructors are called deterministically. It's the addition of classes that create the problems in D. C++ can also throw by value, something that D can't really do. C++ objects can be: -

ref parameter qualifier and static arrays

2015-09-09 Thread Paul via Digitalmars-d-learn
Is it possible to call a function like this... void foo(ref int[] anArray) ...with slices of static arrays? I thought I might be able to use [0..$-1] but to no avail - I get an error like this (which is confusing!): (ref int[] anArray) is not callable using argument types (int[]) I've

What is the difference between D and C++ regarding Unique, RefCounted and Scoped?

2015-09-09 Thread cym13 via Digitalmars-d-learn
Hi, I know C++ and D without being a C++ or D guru (I know way more about D though). When talking about memory management the problem of RAII is often mentioned along with the fact that classes use the GC. I know well the difference between structs and classes and don't want to talk about

Re: char[] ported from C to char[0] in the D core library

2015-09-09 Thread Alex Parrill via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 16:49:39 UTC, badlink wrote: The struct core.sys.linux.sys.inotify.inotify_event contains the field "char[0] name" which corresponds to "char name[]" in C. Why it has been translated to "char[0]" ? For me "char*" would have been more appropriate. It's a

Re: What is the difference between D and C++ regarding Unique, RefCounted and Scoped?

2015-09-09 Thread ponce via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 19:48:00 UTC, cym13 wrote: Hi, I know C++ and D without being a C++ or D guru (I know way more about D though). When talking about memory management the problem of RAII is often mentioned along with the fact that classes use the GC. I know well the

Re: What is the difference between D and C++ regarding Unique, RefCounted and Scoped?

2015-09-09 Thread via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 20:37:40 UTC, cym13 wrote: Hence my question: in what? (I assume you are talking about Unique RefCounted etc and not about classes). I think you should just refer them to the relevant man pages. Explanations are just going to be confusing as they are

Re: OSX prompt limit

2015-09-09 Thread Joel via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 17:47:44 UTC, Adam D. Ruppe wrote: Maybe you can try gnu readline instead: extern(C) char* readline(const(char)* prompt); pragma(lib, "readline"); pragma(lib, "curses"); void main() { auto line = readline("your line: "); import std.stdio,

Re: OSX prompt limit

2015-09-09 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 21:27:05 UTC, Joel wrote: Thanks Adam. That works better than normal. Up and down don't work though. There's another function called add_history for that. Readline is a pretty popular library (also GPL though, keep that in mind if you distribute your