Re: More type-flexible arrays?

2015-06-15 Thread Ozan via Digitalmars-d-learn
On Sunday, 14 June 2015 at 06:46:05 UTC, Ali Çehreli wrote: On 06/13/2015 11:12 PM, Ozan wrote: Hallo! Is it possible to create arrays which has more then one type, Not possible. f. ex. array[0] = 1; array[1] = z; array[2] = new clazz(), I tried Variant, but it slow down heavily my

Re: More type-flexible arrays?

2015-06-15 Thread Ozan via Digitalmars-d-learn
On Sunday, 14 June 2015 at 06:43:48 UTC, ketmar wrote: On Sun, 14 Jun 2015 06:12:29 +, Ozan wrote: Hallo! Is it possible to create arrays which has more then one type, f. ex. array[0] = 1; array[1] = z; array[2] = new clazz(), I tried Variant, but it slow down heavily my app. it

Re: CPU cores threads fibers

2015-06-15 Thread Robert M. Münch via Digitalmars-d-learn
On 2015-06-14 15:54:30 +, Etienne Cimon said: Yes, however nothing really guarantees multi-threading = multi-core. The kernel reserves the right and will most likely do everything possible to keep your process core-local to use caching efficiently. Hi, sure. It's more about raising the

oauth, Twitter, and std.net.curl

2015-06-15 Thread Taylor Gronka via Digitalmars-d-learn
Hello, I've picked up a web design project, and I would love to use vibe.d/dlang. I need to use oauth to search on a number of web api's, such as searching for Twitter tweets. I tried using Adam's oauth (Thanks!). However, it doesn't appear support the validation needed for searching

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.

dmd/druntime/phobos HEAD: can't link binaries on Arch Linux

2015-06-15 Thread Atila Neves via Digitalmars-d-learn
Anyone else getting this problem on Arch Linux? dmd hello.d hello.o:hello.d:TypeInfo_S3std3uni38__T13InversionListTS3std3uni8GcPolicyZ13InversionList67__T9IntervalsTS3std3uni32__T8CowArrayTS3std3uni8GcPolicyZ8CowArrayZ9Intervals.init$: error: undefined reference to

Re: Casting MapResult

2015-06-15 Thread ketmar via Digitalmars-d-learn
On Mon, 15 Jun 2015 15:10:20 +, jmh530 wrote: you shouldn't cast it like that. use `std.array.array` to get the actual array. like this: import std.array; auto y = x.map!(a = exp(a)).array; the thing is that `map` returns so-called lazy range. lazy ranges trying to not do any work

Re: Process a TypeTuple

2015-06-15 Thread Justin Whear via Digitalmars-d-learn
On Mon, 15 Jun 2015 04:06:12 +, Baz wrote: On Monday, 15 June 2015 at 03:53:35 UTC, Yuxuan Shui wrote: Is it possible to apply some operation on every member of a TypeTuple, then get the result back? Say I have a TypeTuple of array types, and I want a TypeTuple of their element types,

Re: oauth, Twitter, and std.net.curl

2015-06-15 Thread Taylor Gronka via Digitalmars-d-learn
You two are phenomenal! Thanks!

Re: oauth, Twitter, and std.net.curl

2015-06-15 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 15 June 2015 at 14:41:32 UTC, Taylor Gronka wrote: I tried using Adam's oauth (Thanks!). However, it doesn't appear support the validation needed for searching Twitter. https://github.com/adamdruppe/arsd/blob/master/oauth.d I haven't actually used the twitter search api for like a

Re: oauth, Twitter, and std.net.curl

2015-06-15 Thread wobbles via Digitalmars-d-learn
On Monday, 15 June 2015 at 14:41:32 UTC, Taylor Gronka wrote: Hello, I've picked up a web design project, and I would love to use vibe.d/dlang. I need to use oauth to search on a number of web api's, such as searching for Twitter tweets. I tried using Adam's oauth (Thanks!). However, it

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: oauth, Twitter, and std.net.curl

2015-06-15 Thread Adam D. Ruppe via Digitalmars-d-learn
Here's a working example using std.net.curl to search: http://arsdnet.net/dcode/twitter.d I show how you can get a token from the command line and code that I think will also work from std.net.curl in the top comment. Once you get that token, paste it in here, pulling it out of the json.

Re: Casting MapResult

2015-06-15 Thread Justin Whear via Digitalmars-d-learn
On Mon, 15 Jun 2015 15:10:20 +, jmh530 wrote: So I suppose I have two questions: 1) am I screwing up the cast, or is there no way to convert the MapResult to float[], 2) should I just not bother with map (I wrote an alternate, longer, version that doesn't use map but returns float[]

Re: Casting MapResult

2015-06-15 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 15 June 2015 at 15:10:24 UTC, jmh530 wrote: So I suppose I have two questions: 1) am I screwing up the cast, or is there no way to convert the MapResult to float[] Don't cast it, just slap a .array on the end after importing std.range. Like so: import std.algorithm; import

Re: Casting MapResult

2015-06-15 Thread anonymous via Digitalmars-d-learn
On Monday, 15 June 2015 at 15:10:24 UTC, jmh530 wrote: float[] exp(float[] x) { auto y = x.map!(a = exp(a)); cast(float[]) y; return y; } But I get an error that I can't convert MapResult!(__lambda2, float[]) to float[]. So I suppose I have two questions: 1) am I

Re: oauth, Twitter, and std.net.curl

2015-06-15 Thread wobbles via Digitalmars-d-learn
On Monday, 15 June 2015 at 15:23:43 UTC, Taylor Gronka wrote: You two are phenomenal! Thanks! Oh, replaceMap is a custom funciton I wrote too... Eases replacing multiple values in a string with 1 function call. I wont pretend that it's fast as it allocates a lot of memory :) public string

Re: Casting MapResult

2015-06-15 Thread wobbles via Digitalmars-d-learn
On Monday, 15 June 2015 at 15:10:24 UTC, jmh530 wrote: snip float[] exp(float[] x) { auto y = x.map!(a = exp(a)); cast(float[]) y; return y; } Also, I dont think your functions will work? Your recursively calling exp in your map, but with a 'float' instead of

Re: compilation issues in a shared library project

2015-06-15 Thread Nicholas Wilson via Digitalmars-d-learn
On Sunday, 7 June 2015 at 00:38:17 UTC, Jonathan Villa wrote: module dt2.DataBlock; class DataBlock { public DataBlock * NextBlock; public DataBlock * PrevBlock; public string value; this() { NextBlock = null; PrevBlock =

Re: dmd/druntime/phobos HEAD: can't link binaries on Arch Linux

2015-06-15 Thread Vladimir Panteleev via Digitalmars-d-learn
On Monday, 15 June 2015 at 15:50:59 UTC, Atila Neves wrote: Anyone else getting this problem on Arch Linux? dmd hello.d

Re: Casting MapResult

2015-06-15 Thread Ali Çehreli via Digitalmars-d-learn
On 06/15/2015 08:21 AM, Adam D. Ruppe wrote: don't call .array if you don't have to, chaining calls to map and such, even foreach(item; some_map_result) can be done without actually building the array and can give more efficiency. To add, the OP can use 'sum' or 'reduce' for adding them

Extract template parameter at runtime?

2015-06-15 Thread Yuxuan Shui via Digitalmars-d-learn
I have a template class which is derived from a base class. Is it possible to extract the template parameter from a reference to the base class? Can is() operate on TypeInfo?

Re: Extract template parameter at runtime?

2015-06-15 Thread Baz via Digitalmars-d-learn
On Monday, 15 June 2015 at 18:10:34 UTC, Yuxuan Shui wrote: Can is() operate on TypeInfo? yes, you can compare instance of TypeInfo using is or '==' too, using typeid which is returns at run-time the TypeInfo of the argument: --- void main() { assert(typeid(2) == typeid(1));

Re: Casting MapResult

2015-06-15 Thread ketmar via Digitalmars-d-learn
On Mon, 15 Jun 2015 17:07:55 +, jmh530 wrote: 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

Re: Extract template parameter at runtime?

2015-06-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/15/15 2:10 PM, Yuxuan Shui wrote: I have a template class which is derived from a base class. Is it possible to extract the template parameter from a reference to the base class? No. You can't get compile-time information at runtime, unless you have stored it somewhere that runtime can

Re: Casting MapResult

2015-06-15 Thread Baz via Digitalmars-d-learn
On Monday, 15 June 2015 at 15:10:24 UTC, jmh530 wrote: 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

Re: Casting MapResult

2015-06-15 Thread via Digitalmars-d-learn
On Monday, 15 June 2015 at 16:16:00 UTC, Ali Çehreli wrote: On 06/15/2015 08:21 AM, Adam D. Ruppe wrote: don't call .array if you don't have to, chaining calls to map and such, even foreach(item; some_map_result) can be done without actually building the array and can give more efficiency.

Re: Casting MapResult

2015-06-15 Thread Ali Çehreli via Digitalmars-d-learn
On 06/15/2015 09:39 AM, Marc =?UTF-8?B?U2Now7x0eiI=?= schue...@gmx.net wrote: writeln(y.sum);// same as sum(y) } An equivalent of the last line: writeln(reduce!((result, a) = result + a)(y)); `sum` is better for floating-point ranges, because it uses pair-wise or Kahan

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 Baz via Digitalmars-d-learn
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(): --- float[] _exp(float[] x) { auto result = x.dup; result.each!(a = exp(a)); return result; } ---

Re: Casting MapResult

2015-06-15 Thread Baz via Digitalmars-d-learn
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(): --- float[] _exp(float[] x) { auto result = x.dup;

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

Re: compilation issues in a shared library project

2015-06-15 Thread Jonathan Villa via Digitalmars-d-learn
On Monday, 15 June 2015 at 06:39:49 UTC, Nicholas Wilson wrote: On Sunday, 7 June 2015 at 00:38:17 UTC, Jonathan Villa wrote: Just an FYI classes are reference types in D so you probably meant public DataBlock NextBlock; // is a class reference public DataBlock * PrevBlock;

Re: Extract template parameter at runtime?

2015-06-15 Thread Yuxuan Shui via Digitalmars-d-learn
On Monday, 15 June 2015 at 18:30:55 UTC, Steven Schveighoffer wrote: On 6/15/15 2:10 PM, Yuxuan Shui wrote: I have a template class which is derived from a base class. Is it possible to extract the template parameter from a reference to the base class? No. You can't get compile-time

Re: Extract template parameter at runtime?

2015-06-15 Thread Yuxuan Shui via Digitalmars-d-learn
On Monday, 15 June 2015 at 22:56:57 UTC, Yuxuan Shui wrote: On Monday, 15 June 2015 at 18:30:55 UTC, Steven Schveighoffer wrote: [...] Well I don't have a serious use case of this. I just started using D couple of weeks ago, and is now experimenting with it by writing a toy compiler. What

Re: Casting MapResult

2015-06-15 Thread Ali Çehreli via Digitalmars-d-learn
On 06/15/2015 12:44 PM, jmh530 wrote: On Monday, 15 June 2015 at 19:32:12 UTC, Baz wrote: Ah sorry it's you the OP. just get it. So you wanted greedy, didn't you ? I suppose I would want whichever has the best performance. Without testing, I'm not sure which one would be better.

Re: Extract template parameter at runtime?

2015-06-15 Thread Ali Çehreli via Digitalmars-d-learn
On 06/15/2015 04:04 PM, Yuxuan Shui wrote: Maybe I can put a virtual function in the class that return the template parameter? Yeah, that's how I would do it. Ali

Re: Casting MapResult

2015-06-15 Thread Baz via Digitalmars-d-learn
On Monday, 15 June 2015 at 20:10:30 UTC, jmh530 wrote: 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.