Re: Merging one Array with Another

2015-05-01 Thread via Digitalmars-d-learn
On Friday, 1 May 2015 at 22:47:17 UTC, Ali Çehreli wrote: It is about the uniqueness of consecutive elements. It says unique consecutive elements. Ali Ah. Then I guess that if input is SortedRange then SortedRange should be returned. Thanks.

Re: Reducing source code: weak+alias values in array

2015-05-01 Thread Jens Bauer via Digitalmars-d-learn
On Saturday, 2 May 2015 at 03:21:38 UTC, Jens Bauer wrote: For some reason, my build time has increased dramatically... Building with 1 vector takes 0.6 seconds. Building with 2 vector takes 0.7 seconds. Building with 4 vector takes 0.9 seconds. Building with 8 vector takes 1.1 seconds.

Re: Reducing source code: weak+alias values in array

2015-05-01 Thread Jens Bauer via Digitalmars-d-learn
On 04/27/15 19:49, Jens Bauer via Digitalmars-d-learn wrote: I was wondering if there's a way to reduce my bulky startup files a bit. On Wednesday, 29 April 2015 at 13:58:14 UTC, Artur Skawina wrote: mixin(VectorFuncs!(q{ PTR stack = {`_stack`}; EXC Reset_Handler =

Re: Merging one Array with Another

2015-05-01 Thread Ali Çehreli via Digitalmars-d-learn
On 05/01/2015 06:39 PM, Per =?UTF-8?B?Tm9yZGzDtnci?= per.nord...@gmail.com wrote: On Friday, 1 May 2015 at 22:47:17 UTC, Ali Çehreli wrote: It is about the uniqueness of consecutive elements. It says unique consecutive elements. Ali Ah. Then I guess that if input is SortedRange then

Re: Merging one Array with Another

2015-05-01 Thread Ilya Yaroshenko via Digitalmars-d-learn
fix: completeSort(x.assumeSorted, y); x = x.chain(y).uniq.array; or (was fixed) y = y.sort().uniq.array; completeSort(x.assumeSorted, y); x ~= y;

Re: apache spark - not disk or network bound but CPU bound

2015-05-01 Thread monty via Digitalmars-d-learn
On Friday, 1 May 2015 at 11:15:01 UTC, Laeeth Isharc wrote: http://radar.oreilly.com/2015/04/investigating-sparks-performance.html paper: http://www.eecs.berkeley.edu/~keo/publications/nsdi15-final147.pdf

Re: How to reuse functions

2015-05-01 Thread Luigi via Digitalmars-d-learn
ERRATA CORRIGE: in place of x_s replace with x_n. Sorry

Re: How to reuse functions

2015-05-01 Thread Luigi via Digitalmars-d-learn
On Friday, 1 May 2015 at 11:03:19 UTC, anonymous wrote: If x_n is a constant (enum), you can use that to create a function instead of a delegate: void main() { enum real x_n = 1; real x_m = -1; real function(real) s_n = z = F1(z, x_n); auto J = jac(s_n, x_m); } If

What wrong?

2015-05-01 Thread Fyodor Ustinov via Digitalmars-d-learn
Simple code: http://pastebin.com/raw.php?i=7jVeMFXQ This code works compiled by DMD v2.066.1 and LDC2 (0.15.1) based on DMD v2.066.1 and LLVM 3.5.0. $ ./z TUQLUE 42 11 Compiled by DMD v2.067.1 the program crashes: $ ./aa TUQLUE Segmentation fault What I'm doing wrong?

Re: Calling functions using mixins

2015-05-01 Thread Dennis Ritchie via Digitalmars-d-learn
On Friday, 1 May 2015 at 21:50:51 UTC, anonymous wrote: What's that supposed to do? Excuse me, what is not said. I thought that my wish will be obvious. On Friday, 1 May 2015 at 21:59:31 UTC, Ali Çehreli wrote: On 05/01/2015 02:41 PM, Dennis Ritchie wrote: immutable string[] s = [

Re: Merging one Array with Another

2015-05-01 Thread via Digitalmars-d-learn
On Friday, 1 May 2015 at 19:30:08 UTC, Ilya Yaroshenko wrote: Probably you need something like that: x = x.chain(y).sort.uniq.array; You're right: import std.stdio, std.algorithm, std.range; auto x = [11, 3, 2, 4, 5, 1]; auto y = [0, 3, 10, 2, 4, 5, 1];

Re: Reducing source code: weak+alias values in array

2015-05-01 Thread Jens Bauer via Digitalmars-d-learn
On Friday, 1 May 2015 at 21:36:29 UTC, Artur Skawina wrote: On 05/01/15 22:29, Jens Bauer via Digitalmars-d-learn wrote: On Wednesday, 29 April 2015 at 13:58:14 UTC, Artur Skawina wrote: Use `@weakalias!blah` instead: enum weakalias(string A) = gcc.attribute.attribute(alias, A);

Re: Merging one Array with Another

2015-05-01 Thread Ali Çehreli via Digitalmars-d-learn
On 05/01/2015 03:41 PM, Per =?UTF-8?B?Tm9yZGzDtnci?= per.nord...@gmail.com wrote: so why doesn't http://dlang.org/phobos/std_algorithm_iteration.html#.uniq say anything about need for sortness!? It is about the uniqueness of consecutive elements. It says unique consecutive elements.

Re: Ada to D - an array for storing values of each of the six bits which are sufficient

2015-05-01 Thread Dennis Ritchie via Digitalmars-d-learn
Maybe someone will show a primitive packed array. I really can not imagine how to do it on D.

Re: dub -vgc

2015-05-01 Thread Robert M. Münch via Digitalmars-d-learn
On 2015-05-01 00:52:57 +, Laeeth Isharc said: Does dflags work ? http://code.dlang.org/package-format Hi, yes. Overlooked this one as d(ebug)flags. Thanks. -- Robert M. Münch http://www.saphirion.com smarter | better | faster

Re: How to reuse functions

2015-05-01 Thread John Colvin via Digitalmars-d-learn
On Friday, 1 May 2015 at 03:34:53 UTC, Luigi wrote: Hi everybody. I am tring to use a function where its parameter is another function, and at the same time are both already made - they cannot be modified - and the second one has to be conditioned before to be passed as argument. Let's say

Re: Destruction in D

2015-05-01 Thread bitwise via Digitalmars-d-learn
On Friday, 1 May 2015 at 02:35:52 UTC, Idan Arye wrote: On Thursday, 30 April 2015 at 23:27:49 UTC, bitwise wrote: Well, the third thing was just my reasoning for asking in the first place. I need to be able to acquire/release shared resources reliably, like an OpenGL texture, for example.

Re: Merging one Array with Another

2015-05-01 Thread Ilya Yaroshenko via Digitalmars-d-learn
fix: completeSort(x.assumeSorted, y); x = x.chain(y).uniq.array; or completeSort(x.assumeSorted, y.uniq.array); x ~= y; On Friday, 1 May 2015 at 19:34:20 UTC, Ilya Yaroshenko wrote: If x is already sorted x = x.completeSort(y).uniq.array; On Friday, 1 May

Re: Reducing source code: weak+alias values in array

2015-05-01 Thread Jens Bauer via Digitalmars-d-learn
On Wednesday, 29 April 2015 at 13:58:14 UTC, Artur Skawina wrote: On 04/27/15 19:49, Jens Bauer via Digitalmars-d-learn wrote: I was wondering if there's a way to reduce my bulky startup files a bit. {snip} Just create a helper module, which the startup files can all use to generate the data

stdx.data.json - enhancement suggestions

2015-05-01 Thread Laeeth Isharc via Digitalmars-d-learn
On Wednesday, 29 April 2015 at 18:48:22 UTC, Laeeth Isharc wrote: Hi. What's the best way to pass the contents of a file to the stream parser without reading the whole thing into memory first? I get an error if using byLine because the kind of range this function returns is not what the

Re: stdx.data.json - enhancement suggestions

2015-05-01 Thread Ilya Yaroshenko via Digitalmars-d-learn
This line can be removed: .map!(ch = ch.idup) On Friday, 1 May 2015 at 20:02:46 UTC, Ilya Yaroshenko wrote: Current std.stdio is deprecated. This ad-hoc should works. auto json = File(fileName) .byChunk(1024 * 1024) //1 MB. Data cluster equals 1024 * 4

Re: stdx.data.json - enhancement suggestions

2015-05-01 Thread Ilya Yaroshenko via Digitalmars-d-learn
Current std.stdio is deprecated. This ad-hoc should works. auto json = File(fileName) .byChunk(1024 * 1024) //1 MB. Data cluster equals 1024 * 4 .map!(ch = ch.idup) .joiner .map!(b = cast(char)b) .parseJSON;

Re: Merging one Array with Another

2015-05-01 Thread Ilya Yaroshenko via Digitalmars-d-learn
Both variants are wrong because uniq needs sorted ranges. Probably you need something like that: x = x.chain(y).sort.uniq.array; On Friday, 1 May 2015 at 19:08:51 UTC, Per Nordlöw wrote: What's the fastest Phobos-way of doing either x ~= y; // append x = x.uniq; // remove duplicates

Re: Merging one Array with Another

2015-05-01 Thread Ilya Yaroshenko via Digitalmars-d-learn
If x is already sorted x = x.completeSort(y).uniq.array; On Friday, 1 May 2015 at 19:30:08 UTC, Ilya Yaroshenko wrote: Both variants are wrong because uniq needs sorted ranges. Probably you need something like that: x = x.chain(y).sort.uniq.array; On Friday, 1 May 2015 at 19:08:51 UTC, Per

Merging one Array with Another

2015-05-01 Thread via Digitalmars-d-learn
What's the fastest Phobos-way of doing either x ~= y; // append x = x.uniq; // remove duplicates or x = (x ~ y).uniq; // append and remove duplicates in one go provided that T[] x, y; ?

Re: Destruction in D

2015-05-01 Thread Idan Arye via Digitalmars-d-learn
On Friday, 1 May 2015 at 17:45:02 UTC, bitwise wrote: On Friday, 1 May 2015 at 02:35:52 UTC, Idan Arye wrote: On Thursday, 30 April 2015 at 23:27:49 UTC, bitwise wrote: Well, the third thing was just my reasoning for asking in the first place. I need to be able to acquire/release shared

Re: Implicit conversion error

2015-05-01 Thread Paul via Digitalmars-d-learn
On Thursday, 30 April 2015 at 22:24:15 UTC, bearophile wrote: Paul: When compiled on a 64 bit machine, this line int r = uniform(0, mobs.length); .length returns a size_t, and 0 is an int. uniform() probably decides to unify those types to a size_t. A size_t is 32 bit on 32 bit machines

Re: Factory pattern in D

2015-05-01 Thread biozic via Digitalmars-d-learn
On Friday, 1 May 2015 at 10:12:36 UTC, Chris wrote: On Friday, 1 May 2015 at 10:04:46 UTC, Namespace wrote: How about this: struct A { int x = 42; } struct B { int x = 7; } T factory(T)() { return T(); } void main() { auto a = factory!(A); } That's what I was looking for, I

Re: Factory pattern in D

2015-05-01 Thread Rikki Cattermole via Digitalmars-d-learn
On 1/05/2015 10:01 p.m., Chris wrote: What would be the D equivalent of the factory pattern? This obviously doesn't work: struct A { int x = 42; } struct B { int x = 7; } auto factory(string type) { if (type == A) return A(); else if (type == B) return B(); else

Re: Factory pattern in D

2015-05-01 Thread Chris via Digitalmars-d-learn
On Friday, 1 May 2015 at 10:04:46 UTC, Namespace wrote: How about this: struct A { int x = 42; } struct B { int x = 7; } T factory(T)() { return T(); } void main() { auto a = factory!(A); } That's what I was looking for, I just couldn't get it right. Thanks. Rikki: I

Re: Factory pattern in D

2015-05-01 Thread Namespace via Digitalmars-d-learn
How about this: struct A { int x = 42; } struct B { int x = 7; } T factory(T)() { return T(); } void main() { auto a = factory!(A); }

Factory pattern in D

2015-05-01 Thread Chris via Digitalmars-d-learn
What would be the D equivalent of the factory pattern? This obviously doesn't work: struct A { int x = 42; } struct B { int x = 7; } auto factory(string type) { if (type == A) return A(); else if (type == B) return B(); else return A(); // default } void main() {

Re: Factory pattern in D

2015-05-01 Thread Namespace via Digitalmars-d-learn
On Friday, 1 May 2015 at 10:04:46 UTC, Namespace wrote: How about this: struct A { int x = 42; } struct B { int x = 7; } T factory(T)() { return T(); } void main() { auto a = factory!(A); } Of course, you can restrict the type to A or B, or both: T factory(T)() if

Re: Reducing source code: weak+alias values in array

2015-05-01 Thread Artur Skawina via Digitalmars-d-learn
On 05/01/15 22:29, Jens Bauer via Digitalmars-d-learn wrote: On Wednesday, 29 April 2015 at 13:58:14 UTC, Artur Skawina wrote: On 04/27/15 19:49, Jens Bauer via Digitalmars-d-learn wrote: I was wondering if there's a way to reduce my bulky startup files a bit. {snip} Just create a helper

Calling functions using mixins

2015-05-01 Thread Dennis Ritchie via Digitalmars-d-learn
hi, Is it possible to call functions using mixins in this way? - import std.stdio; int fooTestMixin() { return 5; } void main() { enum t { fooTestMixin }; immutable string[] strArr = [ fooTestMixin ]; writeln(mixin(`mixin(t.fooTestMixin)`));

Re: Startup files for STM32F4xx

2015-05-01 Thread Jens Bauer via Digitalmars-d-learn
On Friday, 24 April 2015 at 22:18:22 UTC, tom wrote: On Friday, 24 April 2015 at 13:12:56 UTC, Jens Bauer wrote: On Friday, 24 April 2015 at 07:34:55 UTC, tom wrote: would something like a STM32 NUCLEO-F401RE work? I forgot to give you a proper answer on this one: I think it should work, as

Re: Calling functions using mixins

2015-05-01 Thread anonymous via Digitalmars-d-learn
On Friday, 1 May 2015 at 21:04:10 UTC, Dennis Ritchie wrote: hi, Is it possible to call functions using mixins in this way? - import std.stdio; int fooTestMixin() { return 5; } void main() { enum t { fooTestMixin }; immutable string[] strArr = [ fooTestMixin ];

Re: Calling functions using mixins

2015-05-01 Thread Dennis Ritchie via Digitalmars-d-learn
On Friday, 1 May 2015 at 21:26:20 UTC, anonymous wrote: On Friday, 1 May 2015 at 21:04:10 UTC, Dennis Ritchie wrote: hi, Is it possible to call functions using mixins in this way? - import std.stdio; int fooTestMixin() { return 5; } void main() { enum t { fooTestMixin };

Re: Calling functions using mixins

2015-05-01 Thread anonymous via Digitalmars-d-learn
On Friday, 1 May 2015 at 21:41:10 UTC, Dennis Ritchie wrote: My final goal is to do something like this: - import std.stdio, std.string; int foo() { return 5; } int bar() { return 10; } void main() { immutable string[] s = [ foo, bar ];

Re: Calling functions using mixins

2015-05-01 Thread Ali Çehreli via Digitalmars-d-learn
On 05/01/2015 02:41 PM, Dennis Ritchie wrote: immutable string[] s = [ foo, bar ]; writeln(mixin(`format(%(%s, %), s)`));; If you are trying to call those functions, remove the double quotes by %-(, and use %| to specify what is a delimiter. To call, each needs a semicolon:

Re: Factory pattern in D

2015-05-01 Thread Chris via Digitalmars-d-learn
On Friday, 1 May 2015 at 10:46:20 UTC, Chris wrote: On Friday, 1 May 2015 at 10:27:16 UTC, biozic wrote: On Friday, 1 May 2015 at 10:12:36 UTC, Chris wrote: On Friday, 1 May 2015 at 10:04:46 UTC, Namespace wrote: How about this: struct A { int x = 42; } struct B { int x = 7; } T

Re: Factory pattern in D

2015-05-01 Thread Chris via Digitalmars-d-learn
On Friday, 1 May 2015 at 10:27:16 UTC, biozic wrote: On Friday, 1 May 2015 at 10:12:36 UTC, Chris wrote: On Friday, 1 May 2015 at 10:04:46 UTC, Namespace wrote: How about this: struct A { int x = 42; } struct B { int x = 7; } T factory(T)() { return T(); } void main() { auto a =

Re: Ada to D - an array for storing values of each of the six bits which are sufficient

2015-05-01 Thread Dennis Ritchie via Digitalmars-d-learn
On Thursday, 30 April 2015 at 11:20:55 UTC, bearophile wrote: Dennis Ritchie: There is an array of values to store each of which sufficiently 6 bits. As it is written down on the D? You can't do it directly in D. Someone has to write a packed array data structure to do it. Bye,

Re: Factory pattern in D

2015-05-01 Thread Chris via Digitalmars-d-learn
On Friday, 1 May 2015 at 10:47:22 UTC, Chris wrote: On Friday, 1 May 2015 at 10:46:20 UTC, Chris wrote: On Friday, 1 May 2015 at 10:27:16 UTC, biozic wrote: On Friday, 1 May 2015 at 10:12:36 UTC, Chris wrote: On Friday, 1 May 2015 at 10:04:46 UTC, Namespace wrote: How about this:

Re: How to reuse functions

2015-05-01 Thread anonymous via Digitalmars-d-learn
On Friday, 1 May 2015 at 03:34:53 UTC, Luigi wrote: Hi everybody. I am tring to use a function where its parameter is another function, and at the same time are both already made - they cannot be modified - and the second one has to be conditioned before to be passed as argument. Let's say

apache spark - not disk or network bound but CPU bound

2015-05-01 Thread Laeeth Isharc via Digitalmars-d-learn
http://radar.oreilly.com/2015/04/investigating-sparks-performance.html For many who use and deploy Apache Spark, knowing how to find critical bottlenecks is extremely important. In a recent O’Reilly webcast, Making Sense of Spark Performance, Spark committer and PMC member Kay Ousterhout gave

Re: Factory pattern in D

2015-05-01 Thread biozic via Digitalmars-d-learn
On Friday, 1 May 2015 at 11:01:29 UTC, Chris wrote: On Friday, 1 May 2015 at 10:47:22 UTC, Chris wrote: On Friday, 1 May 2015 at 10:46:20 UTC, Chris wrote: On Friday, 1 May 2015 at 10:27:16 UTC, biozic wrote: On Friday, 1 May 2015 at 10:12:36 UTC, Chris wrote: On Friday, 1 May 2015 at

Re: Ada to D - an array for storing values of each of the six bits which are sufficient

2015-05-01 Thread bearophile via Digitalmars-d-learn
Dennis Ritchie: Anybody can write a packed array on the D? I once badly represent the means by which we can write a packed array. Maybe for this you should use core.simd or unions? SIMD could be useful for some fancy bulk operations. But you should be able to write a good basic packed array

Re: Factory pattern in D

2015-05-01 Thread anonymous via Digitalmars-d-learn
On Friday, 1 May 2015 at 11:01:29 UTC, Chris wrote: This aside, how would I get something to load dynamically? It's either mismatched function return type or (with type check) variable X cannot be read at compile time: void main(string[] args) { auto type = args[1]; auto myType =

Re: Factory pattern in D

2015-05-01 Thread Chris via Digitalmars-d-learn
On Friday, 1 May 2015 at 11:11:28 UTC, biozic wrote: On Friday, 1 May 2015 at 11:01:29 UTC, Chris wrote: Thinking about it, T factory(T)() { return T(); } is better suited for a factory (with static type checks). But then I don't know what factory!X() provides that X() alone doesn't.

Re: Factory pattern in D

2015-05-01 Thread biozic via Digitalmars-d-learn
On Friday, 1 May 2015 at 11:20:32 UTC, Chris wrote: On Friday, 1 May 2015 at 11:11:28 UTC, biozic wrote: On Friday, 1 May 2015 at 11:01:29 UTC, Chris wrote: Thinking about it, T factory(T)() { return T(); } is better suited for a factory (with static type checks). But then I don't know