D Beginner Trying Manual Memory Management

2015-01-12 Thread jmh530 via Digitalmars-d-learn
I'm new to D. I have some modest knowledge of C++, but am more familiar with scripting languages (Matlab, Python, R). D seems so much easier than C++ in a lot of ways (and I just learned about rdmd today, which is pretty cool). I am concerned about performance of D vs. C++, so I wanted to

Re: D Beginner Trying Manual Memory Management

2015-01-12 Thread jmh530 via Digitalmars-d-learn
was trying to do is more like make_unique than unique_ptr. On Monday, 12 January 2015 at 19:42:14 UTC, ketmar via Digitalmars-d-learn wrote: On Mon, 12 Jan 2015 19:29:53 + jmh530 via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: the proper answer is too long to write

Re: D Beginner Trying Manual Memory Management

2015-01-12 Thread jmh530 via Digitalmars-d-learn
I had seen some stuff on alias thing, but I hadn't bothered to try to understand it until now. If I'm understanding the first example a href=http://dlang.org/class.html#AliasThis;here/a, alias this let's you refer to x in s by writing either s.x (as normally) or just s. That didn't seem that

Re: Will D have a serious dedicated well supported IDE like Visual Studio or Eclipse?

2015-02-26 Thread jmh530 via Digitalmars-d-learn
On Thursday, 26 February 2015 at 20:23:10 UTC, Rinzler wrote: Hello, This question might have already been asked, but maybe new answers come up, with new updates. I a beginner with D, actually I have almost done nothing. I am using a Mac, and Xamarin Studio seem to be the best choice, but

Function Error: cannot be read at compile time

2015-06-04 Thread jmh530 via Digitalmars-d-learn
I'm trying to run the following code (to create an array of uniform random variables) on the latest version of rdmd (2.067.1). import std.random; auto uniform_array(int len, float a, float b) { Random gen; float output[len]; foreach(ref float i; output) {

Re: Casting MapResult

2015-06-23 Thread jmh530 via Digitalmars-d-learn
On Tuesday, 23 June 2015 at 10:50:51 UTC, John Colvin wrote: If I remember correctly, core.simd should work with every compiler on every supported OS. What did you try that didn't work? I figured out the issue! You have to compile using the -m64 flag to get it to work on Windows (this works

Re: Importing local modules in C style

2015-06-25 Thread jmh530 via Digitalmars-d-learn
On Thursday, 25 June 2015 at 17:20:46 UTC, jmh530 wrote: On Thursday, 25 June 2015 at 14:37:28 UTC, Binarydepth wrote: I organize some exercises in some source files, it's more how I like to work with C. I'm used to organize source files this way and I was wondering if this was possible with

Re: Importing local modules in C style

2015-06-25 Thread jmh530 via Digitalmars-d-learn
On Thursday, 25 June 2015 at 14:37:28 UTC, Binarydepth wrote: I organize some exercises in some source files, it's more how I like to work with C. I'm used to organize source files this way and I was wondering if this was possible with D. If the files are in the same folder, just import

Re: Casting MapResult

2015-06-22 Thread jmh530 via Digitalmars-d-learn
On Tuesday, 16 June 2015 at 16:37:35 UTC, John Colvin wrote: If you want really fast exponentiation of an array though, you want to use SIMD. Something like http://www.yeppp.info would be easy to use from D. I've been looking into SIMD a little. It turns out that core.simd only works for DMD

Re: Casting MapResult

2015-06-16 Thread jmh530 via Digitalmars-d-learn
On Monday, 15 June 2015 at 22:40:31 UTC, Baz wrote: Right, my bad. This one whould work: --- float[] test(float[] x) { auto result = x.dup; result.each!((ref a) = (a = exp(a))); return result; } --- That works. Thanks. I did some benchmarking and found that map tended to be

Re: Casting MapResult

2015-06-16 Thread jmh530 via Digitalmars-d-learn
On Tuesday, 16 June 2015 at 13:15:05 UTC, John Colvin wrote: *consistent as in different implementations performing very similarly instead of seeing big differences like you have here. That's a good point. I tried numpy's exp (which uses C at a low level, I think) and found it takes about

Re: Casting MapResult

2015-06-15 Thread jmh530 via Digitalmars-d-learn
Thank you all for the very fast answers. It looks like that works.

Casting MapResult

2015-06-15 Thread jmh530 via Digitalmars-d-learn
I wrote a simple function to apply map to a float dynamic array auto exp(float[] x) { auto y = x.map!(a = exp(a)); return y; } However, the type of the result is MapResult!(__lambda2, float[]). It seems like some of the things that I might do to a float[], I can't do to this

Re: Casting MapResult

2015-06-16 Thread jmh530 via Digitalmars-d-learn
On Tuesday, 16 June 2015 at 16:38:55 UTC, John Colvin wrote: What OS are you on? See http://wiki.dlang.org/Compilers I'm on Windows 7 at work, and I have both Win7 and linux at home. I figure I can try it on linux at home. Sometimes the work computer is a bit funky with installing things,

Re: Casting MapResult

2015-06-16 Thread jmh530 via Digitalmars-d-learn
Err...vectors not matrices.

Base type for arrays

2015-06-17 Thread jmh530 via Digitalmars-d-learn
I want to write a function template that works for any array of a particular type, but not the base type, so real[], real[][], etc, but not real. I was using ForeachType to do some testing, but it doesn't really get the base type. It just takes one of the [] off and returns the remaining type

Re: Base type for arrays

2015-06-17 Thread jmh530 via Digitalmars-d-learn
On Wednesday, 17 June 2015 at 20:06:54 UTC, Alex Parrill wrote: Try: void foo(T)(T[] arg) { // In here, T should be the element type, and T[] the array type. } Not a general solution, but you mentioned that you wanted this for a function parameter. I don't think this works for

Re: Base type for arrays

2015-06-17 Thread jmh530 via Digitalmars-d-learn
On Wednesday, 17 June 2015 at 20:33:11 UTC, Namespace wrote: import std.stdio; template BaseTypeOf(T) { static if (is(T : U[], U)) alias BaseTypeOf = BaseTypeOf!(U); else alias BaseTypeOf = T; } void foo(T : U[], U)(T arr) if (is(BaseTypeOf!(U) == real)) {

Re: Casting MapResult

2015-06-15 Thread jmh530 via Digitalmars-d-learn
I have a little bit of a follow up. After making the recommended changes, the function seems to work with both static and dynamic arrays. I then noticed that all of the examples for functions that pass arrays in http://dlang.org/function.html use the dynamic array notation like my function

Re: Casting MapResult

2015-06-15 Thread jmh530 via Digitalmars-d-learn
I suppose I would want whichever has the best performance. Without testing, I'm not sure which one would be better. Thoughts? I had been fighting with the map results because I didn't realize there was an easy way to get just the array. I'm actually not having much luck with your original

Re: Casting MapResult

2015-06-15 Thread jmh530 via Digitalmars-d-learn
On Monday, 15 June 2015 at 19:32:12 UTC, Baz wrote: On Monday, 15 June 2015 at 19:30:08 UTC, Baz wrote: On Monday, 15 June 2015 at 19:22:31 UTC, jmh530 wrote: On Monday, 15 June 2015 at 19:04:32 UTC, Baz wrote: In addition to the other answers you can use std.algorithm.iteration.each(): ---

Re: Casting MapResult

2015-06-15 Thread jmh530 via Digitalmars-d-learn
On Monday, 15 June 2015 at 19:04:32 UTC, Baz wrote: In addition to the other answers you can use std.algorithm.iteration.each(): --- float[] _exp(float[] x) { auto result = x.dup; result.each!(a = exp(a)); return result; } --- Am I right that the difference is that map is lazy

Map Purity

2015-06-30 Thread jmh530 via Digitalmars-d-learn
My understanding of pure is that a function labeled pure can only include pure functions. I've been confused by the fact that a function calling map (like below) can be labeled pure without any problems. The only way I can rationalize it is that map really isn't a function, it's (if I'm

Re: Map Purity

2015-06-30 Thread jmh530 via Digitalmars-d-learn
On Sunday, 28 June 2015 at 16:15:31 UTC, Marc Schütz wrote: Secondly, `map` is indeed a template function, as you write. For templates functions, the compiler infers many properties, including purity. Thanks for the reply. Two follow ups: 1) Does labeling a template as pure matter if the

Re: how to iterate on Array?

2015-06-27 Thread jmh530 via Digitalmars-d-learn
On Saturday, 27 June 2015 at 18:32:10 UTC, Ali Çehreli wrote: Luckily, it is very easy to achieve it with std.range.enumerate: FTFY

Re: Array operations, dynamic arrays and length

2015-07-04 Thread jmh530 via Digitalmars-d-learn
On Thursday, 2 July 2015 at 19:27:57 UTC, J Miller wrote: I knew that automatic allocation doesn't happen, but I'm confused by the fact if you explicitly declare c with int[] c; and then assign c[] = a[] * b[], versus using auto c = a[] * b[], you get two different errors (array length

Squaring Arrays without Overlapping Array Error

2015-07-06 Thread jmh530 via Digitalmars-d-learn
If I call a function like int[] square_array(int[] x) { return x[] *= x[]; } I get an error that there is an overlapping array in a vector operation. I guess this makes sense as the lhs and rhs are occupying the same memory. Nevertheless, I find it a little frustrating. I tried two

Re: Multi-dimensional fixed arrays

2015-06-30 Thread jmh530 via Digitalmars-d-learn
On Tuesday, 30 June 2015 at 21:02:39 UTC, DLearner wrote: On Tuesday, 30 June 2015 at 20:33:31 UTC, jmh530 wrote: On Tuesday, 30 June 2015 at 20:17:12 UTC, Justin Whear wrote: [...] I think this is a good explanation. Looking through http://dlang.org/arrays.html I see that the

Re: Multi-dimensional fixed arrays

2015-06-30 Thread jmh530 via Digitalmars-d-learn
On Tuesday, 30 June 2015 at 20:17:12 UTC, Justin Whear wrote: No. The order of braces when indexing is the opposite of the order when declaring. The declaration int [1][2] foo; reads innermost to outermost, ((int [1] ) [2]) When indexing foo, you index from outermost to innermost, so

Re: Squaring Arrays without Overlapping Array Error

2015-07-07 Thread jmh530 via Digitalmars-d-learn
On Tuesday, 7 July 2015 at 13:58:17 UTC, Steven Schveighoffer wrote: Yeah, this seems like an unnecessary limitation for exact matching. In other words, if your destination array exactly matches one or more of the arguments, it should be fine. Where the overlapping starts causing problems is

Understanding Safety of Function Pointers vs. Addresses of Functions

2015-07-07 Thread jmh530 via Digitalmars-d-learn
I'm not sure I understand the safety of function pointers vs. the addresses of functions. The code below illustrates the issue. I was under the impression that pointers are not allowed in safe code. Naturally, I took that to also mean that function pointers are not allowed in safe code.

Re: Reading dmd's source code

2015-08-20 Thread jmh530 via Digitalmars-d-learn
On Thursday, 20 August 2015 at 04:25:01 UTC, Freddy wrote: dmd's source code is very big, are there tips for reading it(important files)? Might make for a good http://wiki.dlang.org/ page, particularly after the transition to ddmd.

Re: automatically verifying code samples in phobos docs

2015-08-20 Thread jmh530 via Digitalmars-d-learn
On Thursday, 20 August 2015 at 06:28:44 UTC, Jacob Carlborg wrote: On 2015-08-20 01:41, Laeeth Isharc wrote: Should this be done? How? Just use a documented unit tests block: /// unittest { // code goes here } It will be run as part of the unit tests and it will be included when

Re: Array start index

2015-08-03 Thread jmh530 via Digitalmars-d-learn
On Saturday, 1 August 2015 at 09:35:53 UTC, DLearner wrote: Does the D language set in stone that the first element of an array _has_ to be index zero? Wouldn't starting array elements at one avoid the common 'off-by-one' logic error, it does seem more natural to begin a count at 1. Actually,

Overloading Based on Constraints

2015-07-23 Thread jmh530 via Digitalmars-d-learn
I was looking at http://dlang.org/concepts.html where it discusses overloading templates based on constraints. I wanted to try to overload a template function with another version that does everything in place. So basically, one has a return and the other doesn't. However, when I run the code,

Re: Understanding Safety of Function Pointers vs. Addresses of Functions

2015-07-14 Thread jmh530 via Digitalmars-d-learn
On Tuesday, 14 July 2015 at 12:12:41 UTC, anonymous wrote: Works for me. Please show the complete code and the error message you get. Here's what works for me: Thanks for posting that. I figured out the issue. Before you had recommended that I use alias cos = std.math.cos; I had kept

Re: Understanding Safety of Function Pointers vs. Addresses of Functions

2015-07-14 Thread jmh530 via Digitalmars-d-learn
On Tuesday, 14 July 2015 at 17:24:41 UTC, anonymous wrote: This fails with Error: None of the overloads of 'cos' are callable using argument types (int[]). The problem is that template mixins cannot add to existing overload sets. The spec says: If the name of a declaration in a mixin is

Re: Profile Ouput

2015-07-15 Thread jmh530 via Digitalmars-d-learn
On Wednesday, 15 July 2015 at 11:47:53 UTC, Mike Parker wrote: On Tuesday, 14 July 2015 at 13:35:40 UTC, Mike Parker wrote: -- 4000 _Dmain _D4main6selectFZk 40002736471 4000 _D3std6random27__T7uniformVAyaa2_5b29TkTkZ7uniformFNfkkZk

Re: Understanding Safety of Function Pointers vs. Addresses of Functions

2015-07-15 Thread jmh530 via Digitalmars-d-learn
On Wednesday, 15 July 2015 at 11:45:00 UTC, Laeeth Isharc wrote: Now - is there a way to rewrite my code without mixins? Not sure that is possible. It would be interesting if someone could figure it out though. I'm more focused on making the givemeabettername a bit more general. Someone

std.algorithm each documentation terse

2015-07-20 Thread jmh530 via Digitalmars-d-learn
I have found the documentation for each in std.algorithm a bit terse. It seemed like it was an eager version of map, but it seems to be a bit more limited than that. In particular, the documentation says that if you can mutate the value in place, then you can call each on it. The first thing

Re: std.algorithm each documentation terse

2015-07-20 Thread jmh530 via Digitalmars-d-learn
On Monday, 20 July 2015 at 14:40:59 UTC, jmh530 wrote: Is there a way to write a void lambda that would work with each? Ugh, I hate that I can't edit posts. I meant to delete this line.

Re: Understanding Safety of Function Pointers vs. Addresses of Functions

2015-07-12 Thread jmh530 via Digitalmars-d-learn
On Sunday, 12 July 2015 at 20:31:20 UTC, jmh530 wrote: On Sunday, 12 July 2015 at 17:11:04 UTC, anonymous wrote: And personally, I'd probably just type out `x.map!fun.array` every time. [1] http://dlang.org/hijack.html Thanks for the comments. After thinking it over, I think you're

Re: Understanding Safety of Function Pointers vs. Addresses of Functions

2015-07-12 Thread jmh530 via Digitalmars-d-learn
On Sunday, 12 July 2015 at 17:11:04 UTC, anonymous wrote: And personally, I'd probably just type out `x.map!fun.array` every time. [1] http://dlang.org/hijack.html Thanks for the comments.

Re: Understanding Safety of Function Pointers vs. Addresses of Functions

2015-07-13 Thread jmh530 via Digitalmars-d-learn
On Monday, 13 July 2015 at 02:52:11 UTC, Laeeth Isharc wrote: I am venturing in territory still new to me, but I think that was his point - foreach with tuples looks like it is looping, but really it is unpacking them statically at compile time. And similarly with the recursive version. I

Re: std.algorithm each documentation terse

2015-07-20 Thread jmh530 via Digitalmars-d-learn
On Monday, 20 July 2015 at 15:12:28 UTC, Marc Schütz wrote: On Monday, 20 July 2015 at 15:08:16 UTC, Nicholas Wilson wrote: But the lambda takes a ref parameter... Yes, but it never writes to it: x.each!((ref a) = a + 1); Instead, this should work: x.each!((ref a) = a = a + 1);

Re: std.algorithm each documentation terse

2015-07-20 Thread jmh530 via Digitalmars-d-learn
On Monday, 20 July 2015 at 21:24:37 UTC, sigod wrote: On Monday, 20 July 2015 at 14:40:59 UTC, jmh530 wrote: I have found the documentation for each in std.algorithm a bit terse. It seemed like it was an eager version of map, but it seems to be a bit more limited than that. Why are you

Re: OT: why do people use python when it is slow?

2015-10-14 Thread jmh530 via Digitalmars-d-learn
On Tuesday, 13 October 2015 at 23:26:14 UTC, Laeeth Isharc wrote: https://www.quora.com/Why-is-Python-so-popular-despite-being-so-slow Andrei suggested posting more widely. I was just writing some R code yesterday after playing around with D for a couple weeks. I accomplished more in an

Re: OT: why do people use python when it is slow?

2015-10-15 Thread jmh530 via Digitalmars-d-learn
On Thursday, 15 October 2015 at 10:33:54 UTC, Russel Winder wrote: CUDA is of course doomed in the long run as Intel put GPGPU on the processor chip. OpenCL will eventually be replaced with Vulkan (assuming they can get the chips made). I thought Vulkan was meant to replace OpenGL.

Re: OT: why do people use python when it is slow?

2015-10-14 Thread jmh530 via Digitalmars-d-learn
On Wednesday, 14 October 2015 at 22:11:56 UTC, data pulverizer wrote: On Tuesday, 13 October 2015 at 23:26:14 UTC, Laeeth Isharc wrote: https://www.quora.com/Why-is-Python-so-popular-despite-being-so-slow Andrei suggested posting more widely. I believe it is easier and more effective to

Re: Squaring Arrays without Overlapping Array Error

2015-07-07 Thread jmh530 via Digitalmars-d-learn
On Tuesday, 7 July 2015 at 17:05:21 UTC, Steven Schveighoffer wrote: Sure, file as an enhancement. -Steve https://issues.dlang.org/show_bug.cgi?id=14783

Re: Understanding Safety of Function Pointers vs. Addresses of Functions

2015-07-07 Thread jmh530 via Digitalmars-d-learn
On Tuesday, 7 July 2015 at 20:13:08 UTC, anonymous wrote: So long as you exclamation mark? Huh? Thanks for the detailed answer. All I meant here is that if I have some T foo(T)(T x), then to take the address, sometimes I've needed to foo!int or foo!real, etc.

Re: Understanding Safety of Function Pointers vs. Addresses of Functions

2015-07-07 Thread jmh530 via Digitalmars-d-learn
On Tuesday, 7 July 2015 at 20:23:08 UTC, H. S. Teoh wrote: The reason for this is that function pointers have attributes associated with them, as part of the type system. The address of a @safe function is a @safe function pointer, meaning that it's legal to call the function through this

Re: Understanding Safety of Function Pointers vs. Addresses of Functions

2015-07-08 Thread jmh530 via Digitalmars-d-learn
On Wednesday, 8 July 2015 at 11:15:12 UTC, Marc Schütz wrote: It seems std.math.cos is an intrinsic function (i.e. one that the compiler implements when needed, or generates the appropriate asm for): https://github.com/D-Programming-Language/phobos/blob/master/std/math.d#L630 The compiler

Re: Understanding Safety of Function Pointers vs. Addresses of Functions

2015-07-08 Thread jmh530 via Digitalmars-d-learn
On Wednesday, 8 July 2015 at 14:37:23 UTC, jmh530 wrote: Thanks. I was worried I was doing something wrong. It seems like if you wrap the intrinsic function in another function than it works fine (below). Easy enough work-around, I suppose. If there is no intention to fix the pointer to

Re: Understanding Safety of Function Pointers vs. Addresses of Functions

2015-07-08 Thread jmh530 via Digitalmars-d-learn
On Wednesday, 8 July 2015 at 18:31:00 UTC, Steven Schveighoffer wrote: You can use a function lambda: auto fp = (real a) = cos(a); Note, I had to put (real a) even though I would have expected a = cos(a) to work. -Steve Interesting. You have to put real because there is also a float and

Re: Squaring Arrays without Overlapping Array Error

2015-07-07 Thread jmh530 via Digitalmars-d-learn
On Tuesday, 7 July 2015 at 08:06:50 UTC, tcak wrote: I have never used arrays in that way before, though I don't get why you are writing return line in that way. Shouldn't it be like `return (x[] * x[]);` ? There's nothing fundamentally wrong with doing that in the return line. For

Re: Understanding Safety of Function Pointers vs. Addresses of Functions

2015-07-07 Thread jmh530 via Digitalmars-d-learn
I'm still not sure why I'm getting the error I mention in the original post. For instance, the code below is giving that Error 42 Symbol Undefined error. Seems very mystifying... import std.math : cos; real foo(T)(T fp, real x) { return fp(x); } void main() { real x = 0;

Re: Understanding Safety of Function Pointers vs. Addresses of Functions

2015-07-12 Thread jmh530 via Digitalmars-d-learn
On Sunday, 12 July 2015 at 22:26:44 UTC, anonymous wrote: You don't need the lambda, do you? - return x.map!fun.array; You're right. I don't know what exactly you're after, but you can use foreach on a whatever-they're-called-now tuple (there's been a discussion about the name which I

Re: Understanding Safety of Function Pointers vs. Addresses of Functions

2015-07-12 Thread jmh530 via Digitalmars-d-learn
On Wednesday, 8 July 2015 at 18:31:00 UTC, Steven Schveighoffer wrote: You can use a function lambda: auto fp = (real a) = cos(a); Note, I had to put (real a) even though I would have expected a = cos(a) to work. -Steve I've been playing around with this a little more. I wrote this

Scoped Imports for Structs/Classes/Template Constraints

2015-08-31 Thread jmh530 via Digitalmars-d-learn
I've been thinking about scoped imports. While it seems like you can use scoped imports a lot of the time, it seems like there are some potential cases where you can't. Most notably if a function input is a struct or class, then I can't figure out a way to use a scoped import. This also

Re: Scoped Imports for Structs/Classes/Template Constraints

2015-08-31 Thread jmh530 via Digitalmars-d-learn
On Monday, 31 August 2015 at 20:54:53 UTC, Enamex wrote: You can't use it with foo(S) because the type is used /outside/ the scope of the function, in its head. You have to qualify it ( void foo(local.S s) ) or import the type as: { import local: S; void foo(S s) { ... } } I figured

Re: Role of D in Python and performance computing [was post on using go 1.5 and GC latency]

2015-09-01 Thread jmh530 via Digitalmars-d-learn
On Tuesday, 25 August 2015 at 05:12:55 UTC, Laeeth Isharc wrote: What's the best reference to learn more about PGAS? I've seen a few presentations, https://www.osc.edu/sites/osc.edu/files/staff_files/dhudak/pgas-tutorial.pdf

Re: Scoped Imports for Structs/Classes/Template Constraints

2015-09-01 Thread jmh530 via Digitalmars-d-learn
On Tuesday, 1 September 2015 at 19:48:02 UTC, Enamex wrote: They aren't selective, yeah. But the rationale is good: There's not supposed to be any way to import modules with the same path so static importing means it's entirely and always unambiguous. I understand that a static import is

Re: Scoped Imports for Structs/Classes/Template Constraints

2015-09-01 Thread jmh530 via Digitalmars-d-learn
On Monday, 31 August 2015 at 23:36:25 UTC, Enamex wrote: I'm not sure whether a naked 'local.S' should work; sometimes it does and sometimes it doesn't. But an `static import local;` then `voidfoo(local.S)` definitely works. `static import` forces the imported symbols to be fully qualified

Re: Passing Arguments on in Variadic Functions

2015-09-14 Thread jmh530 via Digitalmars-d-learn
Thanks to you both. This works perfect.

Re-named & Selective Imports

2015-09-15 Thread jmh530 via Digitalmars-d-learn
I combined a re-named import with a selective import and was surprised to find that it didn't do what I would have expected. In the code below, I would have expected only the "test2" line to have compiled, but it turned out that all three of these do. I'm guessing the logic is that it imports

Re: Passing Arguments on in Variadic Functions

2015-09-17 Thread jmh530 via Digitalmars-d-learn
On Monday, 14 September 2015 at 20:26:56 UTC, jmh530 wrote: Thanks to you both. This works perfect. I noticed that there's some interesting interplay with this technique and default arguments. From below, it is required that you put the ones with default arguments last. If there are only

Re: Passing Arguments on in Variadic Functions

2015-09-17 Thread jmh530 via Digitalmars-d-learn
On Thursday, 17 September 2015 at 18:40:56 UTC, Adam D. Ruppe wrote: I would actually just make it required or do separate functions with it. Optional and variadics don't mix well together. (You could also loop through and look for a bool argument yourself but that is a bit messier.)

Re: Passing Arguments on in Variadic Functions

2015-09-17 Thread jmh530 via Digitalmars-d-learn
On Thursday, 17 September 2015 at 18:40:56 UTC, Adam D. Ruppe wrote: import std.meta; import std.traits; if(allSatisfy!(isNumeric, V)) should do it Was not aware of allSatisfy. Thanks.

Re: Passing Arguments on in Variadic Functions

2015-09-17 Thread jmh530 via Digitalmars-d-learn
On Thursday, 17 September 2015 at 21:27:31 UTC, jmh530 wrote: There's probably a way to clean this up better, but this is what I was talking about. import std.algorithm : sum; import std.stdio : writeln; import std.traits : isNumeric; auto test(T)(T x, bool sample=true) { auto

Passing Arguments on in Variadic Functions

2015-09-14 Thread jmh530 via Digitalmars-d-learn
In R, it is easy to have some optional inputs labeled as ... and then pass all those optional inputs in to another function. I was trying to get something similar to work in a templated D function, but I couldn't quite get the same behavior. What I have below is what I was able to get working.

Re: Why are static arrays not ranges?

2015-09-21 Thread jmh530 via Digitalmars-d-learn
On Monday, 21 September 2015 at 20:33:10 UTC, Jack Stouffer wrote: That's ridiculous. Do I have to wrap my static arrays in structs to get range primitives? Is there an actual reason for this? I had done basically the same thing. Below is my naive implementation. import std.traits;

Re: Passing Arguments on in Variadic Functions

2015-09-18 Thread jmh530 via Digitalmars-d-learn
On Friday, 18 September 2015 at 00:55:12 UTC, anonymous wrote: On Thursday 17 September 2015 23:27, jmh530 wrote: I think I could figure out how to look through the arguments for a bool, but wouldn't that make me give up the default value for the bool? If you don't find a bool, you use the

Re: dataframe implementations

2015-11-20 Thread jmh530 via Digitalmars-d-learn
On Thursday, 19 November 2015 at 06:33:06 UTC, Jay Norwood wrote: Maybe the nd slices could be applied if you considered each row to be the same structure, and slice by rows rather than operating on columns. Pandas supports a multi-dimension panel. Maybe this would be the application for

Re: dataframe implementations

2015-11-18 Thread jmh530 via Digitalmars-d-learn
On Monday, 2 November 2015 at 13:54:09 UTC, Jay Norwood wrote: I saw someone posting that they were working on DataFrame implementation here, but haven't been able to locate any code in github, and was wondering what implementation decisions are being made here. Thanks. My sense is that

Re: Scale-Hierarchy on ndslice

2016-01-13 Thread jmh530 via Digitalmars-d-learn
On Tuesday, 12 January 2016 at 21:48:39 UTC, Per Nordlöw wrote: Have anybody been thinking about adding a scale-hierarchy structure on top of ndslice? What is a scale-hierarchy structure?

struct on heap with std.experimental.allocator

2016-06-07 Thread jmh530 via Digitalmars-d-learn
I modified one of the first examples from std.experimental.allocator to put a struct on the heap (below). My sense is that putting it on the GC heap gives the struct reference semantics. I was struck by two things. First, I didn't have to use (*a).x, I could just use a.x. Also, when I assign

Re: struct on heap with std.experimental.allocator

2016-06-07 Thread jmh530 via Digitalmars-d-learn
On Tuesday, 7 June 2016 at 15:43:34 UTC, Adam D. Ruppe wrote: On Tuesday, 7 June 2016 at 15:39:59 UTC, jmh530 wrote: My sense is that putting it on the GC heap gives the struct reference semantics. It doesn't matter what heap it is on, you are just using a pointer here. Struct pointers in

Gotchas for returning values from blocks

2016-06-12 Thread jmh530 via Digitalmars-d-learn
I was thinking about how Rust can return arbitrarily from blocks. It occurred to me recently that there's no reason you can't do that in D. I'm just not sure if there are any limitations. For instance, in the code below, I create an object but don't allocate anything, then in a block I create

Re: Gotchas for returning values from blocks

2016-06-12 Thread jmh530 via Digitalmars-d-learn
On Sunday, 12 June 2016 at 19:30:49 UTC, Era Scarecrow wrote: On Sunday, 12 June 2016 at 18:24:58 UTC, jmh530 wrote: I'm just not sure if there are any gotchas to be aware of. Aside from forgetting it's it's own block, you might add a return statement to it and leave the entire function. Or

Re: Gotchas for returning values from blocks

2016-06-13 Thread jmh530 via Digitalmars-d-learn
On Monday, 13 June 2016 at 01:41:07 UTC, Mike Parker wrote: Everything works fine in your example because 'new' always allocates on the heap. Anything allocated on the stack is not guaranteed to be valid after the scope exits: struct Foo { int baz; ~this() { baz = 1; } } void

Re: Meaning of const variables

2016-06-21 Thread jmh530 via Digitalmars-d-learn
On Tuesday, 21 June 2016 at 02:54:06 UTC, ketmar wrote: Thanks to you and the others for the detailed clarifications. I think part of the difficulty is that there are basically three things being discussed that are all very similar: an alias to data, a pointer to data, and a view of data.

Re: Meaning of const variables

2016-06-21 Thread jmh530 via Digitalmars-d-learn
On Tuesday, 21 June 2016 at 15:21:01 UTC, Ali Çehreli wrote: [snip] Thanks.

Meaning of const variables

2016-06-20 Thread jmh530 via Digitalmars-d-learn
I feel like I have a reasonable understanding of when to use const as a parameter in a function or for const member functions. However, I don't really understand why/when it should be used as a type modifier. For instance, the Programming in D book basically just says

Re: Things that keep D from evolving?

2016-02-09 Thread jmh530 via Digitalmars-d-learn
On Tuesday, 9 February 2016 at 13:01:29 UTC, NX wrote: Well, GC being better than it used to be doesn't change the fact it's still the > worst of it's kind. I don't know if this[1] work actually got released or merged but looks like it's abandoned. Pretty sad as it seemed very promising. [1]

Re: Things that keep D from evolving?

2016-02-12 Thread jmh530 via Digitalmars-d-learn
On Friday, 12 February 2016 at 17:20:23 UTC, rsw0x wrote: note that 'in' and 'scope'(other than for delegates) parameter storage class usage should be avoided. It really should be a warning. Add to docs!

UFCS on Enum in Member Function

2016-02-09 Thread jmh530 via Digitalmars-d-learn
I have been working with some C error codes that are organized in an enum. I noticed that if I tried to write a function that processes these error codes within a struct, then I could not use a UFCS-style call. For instance, in the code below, I could use Baz but not Caz. It seems to work

Re: Speed of csvReader

2016-01-27 Thread jmh530 via Digitalmars-d-learn
On Tuesday, 26 January 2016 at 22:36:31 UTC, H. S. Teoh wrote: Yeah, in the course of this exercise, I found that the one thing that has had the biggest impact on performance is the amount of allocations involved. [...snip] Really interesting discussion.

Re: Linking C libraries with DMD

2016-02-02 Thread jmh530 via Digitalmars-d-learn
On Friday, 22 January 2016 at 04:43:52 UTC, Mike Parker wrote: [snip] Thanks again for your help. I've worked through some simple examples and started trying to write a binding to a C library. I think I've got the .h file converted properly (the D file compiles), but I was getting a

Re: Linking C libraries with DMD

2016-02-02 Thread jmh530 via Digitalmars-d-learn
On Tuesday, 2 February 2016 at 20:06:05 UTC, jmh530 wrote: I suspect that if I re-compile the dll using Visual Studio, then it will work with D. Yeah, this is what finally allowed me to progress. Unfortunately, my sample example compiles, but throws an Access Violation error when I run it.

Binding to C - Arrays and Access Violation

2016-02-02 Thread jmh530 via Digitalmars-d-learn
I'm working on generating a binding to a C library. I've got the .h file converted and can call some parts of the library with no errors. However, I have reached a stumbling block in a critical part. The library requires passing function pointers to various functions in the library. When I

Re: Binding to C - Arrays and Access Violation

2016-02-02 Thread jmh530 via Digitalmars-d-learn
On Wednesday, 3 February 2016 at 00:28:24 UTC, biozic wrote: Is grad allocated in the D code? If so, it could have been collected because the GC lost track of its use when passing to and from the C code. Or is grad owned by the C code? If so, either there is a bug in the library or it's

Re: Binding to C - Arrays and Access Violation

2016-02-02 Thread jmh530 via Digitalmars-d-learn
On Wednesday, 3 February 2016 at 00:37:25 UTC, Mike Parker wrote: The parameter to the C function should be declared as extern(C), and so should your function implementation. extern(C) alias FuncPtr = double function(uint, const(double)*, double*, void*); extern(C) void

Re: Simple performance question from a newcomer

2016-02-23 Thread jmh530 via Digitalmars-d-learn
On Tuesday, 23 February 2016 at 20:03:30 UTC, dextorious wrote: Personally, I think a few aspects of documentation for the various compilers, dub and possibly the dlang.org website itself could be improved, if accessibility is considered important. Couldn't agree more. Being new to the

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

2016-02-25 Thread jmh530 via Digitalmars-d-learn
On Wednesday, 24 February 2016 at 21:48:14 UTC, 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? I don't see that anyone has mentioned it but:

Re: Calling python code from D

2016-02-25 Thread jmh530 via Digitalmars-d-learn
On Thursday, 25 February 2016 at 21:46:40 UTC, asdf wrote: I haven't tried this myself but D is supposed to have excellent interface to C code. Perhaps you can go that route. http://stackoverflow.com/questions/145270/calling-c-c-from-python That question is the reverse, calling C from

Re: D equivalent of run-time DLLs / Plugins

2016-02-29 Thread jmh530 via Digitalmars-d-learn
On Monday, 29 February 2016 at 19:02:27 UTC, Chris Katko wrote: Hello. Dlang newbie here. Does D support run-time loading of D modules? Basically, I'm looking to create an application with a plugin interface. I've seen a few posts, but they're dated and it's hard to keep up with "What is

Re: Simple performance question from a newcomer

2016-02-24 Thread jmh530 via Digitalmars-d-learn
On Wednesday, 24 February 2016 at 19:15:23 UTC, dextorious wrote: However, there doesn't seem to be any way to specify different dflags for different compilers There are examples like in the package format page "dflags-dmd": ["-vtls"], "sourceFiles-windows-x86_64-dmd":

Linking C libraries with DMD

2016-01-21 Thread jmh530 via Digitalmars-d-learn
I'm trying to understand calling C libraries from D on Windows with DMD. I made a simple example and compiled it with a static library fine (so I've converted the .h file correctly). Then, I compiled with gcc to a shared library (because I cannot for the life of me figure out how to do this

Re: Linking C libraries with DMD

2016-01-21 Thread jmh530 via Digitalmars-d-learn
On Thursday, 21 January 2016 at 16:57:26 UTC, W.J. wrote: You need to port the header file to d. i believe there's the htod utility, however I haven't used that yet. Then, basically all you have to do is to tell the linker to link against your C .lib. Remember that -LC:\folder (for dmd)

  1   2   3   4   5   >