Re: Why .dup not work with multidimensional arrays?

2015-05-08 Thread Ali Çehreli via Digitalmars-d-learn
On 05/07/2015 07:39 PM, Dennis Ritchie wrote: On Friday, 8 May 2015 at 02:23:23 UTC, E.S. Quinn wrote: It's because arrays are references types, and .dup is a strictly shallow copy, so you're getting two outer arrays that reference the same set of inner arrays. You'll have to duplicated each of

Re: Bitfield-style enum to strings?

2015-05-08 Thread Meta via Digitalmars-d-learn
On Friday, 8 May 2015 at 04:11:36 UTC, Nick Sabalausky wrote: On 05/07/2015 09:17 PM, Meta wrote: On Thursday, 7 May 2015 at 21:41:06 UTC, Nick Sabalausky wrote: On 05/07/2015 05:19 PM, Justin Whear wrote: T[] members = [ EnumMembers!T ]; Doh! Yup, that works. Still, I would think there

Re: Merging one Array with Another

2015-05-08 Thread Andrea Fontana via Digitalmars-d-learn
On Thursday, 7 May 2015 at 21:53:24 UTC, Per Nordlöw wrote: On Thursday, 7 May 2015 at 13:38:23 UTC, Andrea Fontana wrote: Because it is a more generic operation and you can work on a lazy range. Anyway, to sort and to do uniq it isn't the fastest way. Or maybe I just didn't understand what

Re: vibed: how to use pure HTML instead of template engine?

2015-05-08 Thread Rikki Cattermole via Digitalmars-d-learn
On 8/05/2015 10:17 p.m., Chris wrote: On Thursday, 7 May 2015 at 19:51:20 UTC, yawniek wrote: On Thursday, 7 May 2015 at 18:59:13 UTC, Suliman wrote: 1. Do I need write ./public/ ? In examples often simply public/ will work too. even public it goes trough Path struct, see:

Re: Merging one Array with Another

2015-05-08 Thread via Digitalmars-d-learn
On Friday, 8 May 2015 at 08:27:19 UTC, Andrea Fontana wrote: Name could be misleading. This is a sortedrange: [4,3,2,1,0]. In your case minElement is 4, maxElement is 0 :) On ranges with more complex elements sort order can be even less obvious. I think first and back it's ok! Ok. I guess

Re: vibed: how to use pure HTML instead of template engine?

2015-05-08 Thread Chris via Digitalmars-d-learn
On Friday, 8 May 2015 at 10:20:35 UTC, Rikki Cattermole wrote: On 8/05/2015 10:17 p.m., Chris wrote: On Thursday, 7 May 2015 at 19:51:20 UTC, yawniek wrote: On Thursday, 7 May 2015 at 18:59:13 UTC, Suliman wrote: 1. Do I need write ./public/ ? In examples often simply public/ will work too.

Chaining input

2015-05-08 Thread Chris via Digitalmars-d-learn
I have the following code that converts input like blah, blub, gobble, dygook to string[] auto f = File(file.txt, r); auto words = f.byLine .map!( a = a.to!(string) .splitter(, ) .filter!(a = a.length)

Re: vibed: how to use pure HTML instead of template engine?

2015-05-08 Thread Chris via Digitalmars-d-learn
On Thursday, 7 May 2015 at 19:51:20 UTC, yawniek wrote: On Thursday, 7 May 2015 at 18:59:13 UTC, Suliman wrote: 1. Do I need write ./public/ ? In examples often simply public/ will work too. even public it goes trough Path struct, see:

Re: Chaining input

2015-05-08 Thread Robert burner Schadek via Digitalmars-d-learn
On Friday, 8 May 2015 at 11:00:01 UTC, Chris wrote: I'm sure there is room for improvement. It looks like your reading some kind of comma seperated values (csv). have a look at std.csv of phobos ``` foreach(record; file.byLine.joiner(\n).csvReader!(Tuple!(string, string, int))) {

Re: Merging one Array with Another

2015-05-08 Thread Andrea Fontana via Digitalmars-d-learn
On Friday, 8 May 2015 at 09:23:42 UTC, Per Nordlöw wrote: On Friday, 8 May 2015 at 08:27:19 UTC, Andrea Fontana wrote: Name could be misleading. This is a sortedrange: [4,3,2,1,0]. In your case minElement is 4, maxElement is 0 :) On ranges with more complex elements sort order can be even less

Re: Moving from Python to D

2015-05-08 Thread Chris via Digitalmars-d-learn
Moving from Python to D always a good idea ;-)

Re: Moving from Python to D

2015-05-08 Thread Chris via Digitalmars-d-learn
On Friday, 8 May 2015 at 14:13:43 UTC, Chris wrote: Moving from Python to D always a good idea ;-) You might be interested in this: http://wiki.dlang.org/Programming_in_D_for_Python_Programmers http://d.readthedocs.org/en/latest/examples.html#plotting-with-matplotlib-python

Re: Why .dup not work with multidimensional arrays?

2015-05-08 Thread Dennis Ritchie via Digitalmars-d-learn
On Friday, 8 May 2015 at 06:30:46 UTC, Ali Çehreli wrote: In D, everything is possible and very easy. :p I called it deepDup: import std.stdio; import std.traits; import std.range; import std.algorithm; auto deepDup(A)(A arr) if (isArray!A) { static if (isArray!(ElementType!A)) {

Re: Why .dup not work with multidimensional arrays?

2015-05-08 Thread Dennis Ritchie via Digitalmars-d-learn
On Friday, 8 May 2015 at 15:13:14 UTC, Ali Çehreli wrote: On 05/08/2015 08:05 AM, Dennis Ritchie wrote: why static int idx variable declared within a function deepDup takes the values 1, 1, 1, 2, 2, 3, 4, as opposed to a global variable static int idx, which receives the expected value of 1,

Re: Moving from Python to D

2015-05-08 Thread Russel Winder via Digitalmars-d-learn
On Fri, 2015-05-08 at 03:24 +, avarisclari via Digitalmars-d-learn wrote: Hello, Sorry to bother you with something trivial, but I am having trouble translating a block of code I wrote in Python over to D. Everything else I've figured out so far. Could someone help me understand how

Re: Why .dup not work with multidimensional arrays?

2015-05-08 Thread Ali Çehreli via Digitalmars-d-learn
On 05/08/2015 08:05 AM, Dennis Ritchie wrote: why static int idx variable declared within a function deepDup takes the values 1, 1, 1, 2, 2, 3, 4, as opposed to a global variable static int idx, which receives the expected value of 1, 2, 3, 4, 5, 6, 7 ? That's because every template

Re: Moving from Python to D

2015-05-08 Thread avarisclari via Digitalmars-d-learn
On Friday, 8 May 2015 at 04:08:03 UTC, Nick Sabalausky wrote: On 05/08/2015 12:06 AM, Nick Sabalausky wrote: On 05/07/2015 11:24 PM, avarisclari wrote: scene = scenes[title] It looks like scenes is a dictionary that stores dictionaries of strings? If so, then in D, scenes would be

Re: Why .dup not work with multidimensional arrays?

2015-05-08 Thread Chris via Digitalmars-d-learn
On Friday, 8 May 2015 at 06:30:46 UTC, Ali Çehreli wrote: On 05/07/2015 07:39 PM, Dennis Ritchie wrote: On Friday, 8 May 2015 at 02:23:23 UTC, E.S. Quinn wrote: It's because arrays are references types, and .dup is a strictly shallow copy, so you're getting two outer arrays that reference the

Re: dub sub-packages

2015-05-08 Thread Alessandro via Digitalmars-d-learn
On Wednesday, 6 May 2015 at 15:28:53 UTC, Rikki Cattermole wrote: On 6/05/2015 11:39 p.m., Alessandro wrote: Hi everyone, I've been learning D for a few months now and really liked it :) ! Currently I'm experimenting with client/server application development using the ZeroMQ library D

Re: Multiple template alias parameters

2015-05-08 Thread Brian Schott via Digitalmars-d-learn
On Friday, 8 May 2015 at 02:03:17 UTC, Rikki Cattermole wrote: Can you not use something like this? Yes. I was getting confused by another problem that I had just worked on before this one.

Re: Multiple template alias parameters

2015-05-08 Thread Brian Schott via Digitalmars-d-learn
On Friday, 8 May 2015 at 12:44:31 UTC, Artur Skawina wrote: On 05/08/15 03:53, Brian Schott via Digitalmars-d-learn wrote: The problem occurs when I want to register multiple modules to scan for functions. The grammar does not allow this syntax: ``` template (alias Modules ...) { ... ```

Re: Multiple template alias parameters

2015-05-08 Thread Biotronic via Digitalmars-d-learn
On Friday, 8 May 2015 at 21:56:56 UTC, Brian Schott wrote: Allowing template Tem(alias Args ...) syntax would let me trace multiple variables at once. Actually, this already works: void traceVars(alias T, U...)() { import std.stdio : writeln; writeln(T.stringof, : , T); static if

Re: Multiple template alias parameters

2015-05-08 Thread anonymous via Digitalmars-d-learn
On Friday, 8 May 2015 at 22:29:28 UTC, Biotronic wrote: Sadly, the ... syntax precludes the use of __LINE__ and __FILE__. :( You can put them in the runtime parameters: void traceVars(alias T, U...)(size_t line = __LINE__, string file = __FILE__) { import std.stdio : writeln;

Re: Multiple template alias parameters

2015-05-08 Thread Artur Skawina via Digitalmars-d-learn
On 05/08/15 03:53, Brian Schott via Digitalmars-d-learn wrote: The problem occurs when I want to register multiple modules to scan for functions. The grammar does not allow this syntax: ``` template (alias Modules ...) { ... ``` The grammar allows omitting the 'alias' keyword. artur

Re: Safe Usage of Mutable Ranges in foreach scopes

2015-05-08 Thread via Digitalmars-d-learn
On Friday, 8 May 2015 at 11:32:50 UTC, Per Nordlöw wrote: On Friday, 8 May 2015 at 11:29:53 UTC, Per Nordlöw wrote: Such a feature would make the usage of this pattern very (perhaps even absolutely) safe from a memory corruption point of view. An alternative non-restrictive (relaxed)

Re: vibed: how to use pure HTML instead of template engine?

2015-05-08 Thread Rikki Cattermole via Digitalmars-d-learn
On 8/05/2015 10:49 p.m., Chris wrote: On Friday, 8 May 2015 at 10:20:35 UTC, Rikki Cattermole wrote: On 8/05/2015 10:17 p.m., Chris wrote: On Thursday, 7 May 2015 at 19:51:20 UTC, yawniek wrote: On Thursday, 7 May 2015 at 18:59:13 UTC, Suliman wrote: 1. Do I need write ./public/ ? In

Re: Chaining input

2015-05-08 Thread Chris via Digitalmars-d-learn
On Friday, 8 May 2015 at 11:14:43 UTC, Robert burner Schadek wrote: On Friday, 8 May 2015 at 11:00:01 UTC, Chris wrote: I'm sure there is room for improvement. It looks like your reading some kind of comma seperated values (csv). have a look at std.csv of phobos ``` foreach(record;

Re: Safe Usage of Mutable Ranges in foreach scopes

2015-05-08 Thread via Digitalmars-d-learn
On Friday, 8 May 2015 at 11:29:53 UTC, Per Nordlöw wrote: Such a feature would make the usage of this pattern very (perhaps even absolutely) safe from a memory corruption point of view. I guess I should have posted this on digitalmars.D instead ...

Safe Usage of Mutable Ranges in foreach scopes

2015-05-08 Thread via Digitalmars-d-learn
I use a lot of file parsing looking like alias T = double; T[] values; foreach (line; File(path).byLine) { foreach (part; line.splitter(separator)) { values ~= part.to!T; } } The key D thing here is that this is _both_ fast (because no copying of file-memory-slices needs

Re: Safe Usage of Mutable Ranges in foreach scopes

2015-05-08 Thread via Digitalmars-d-learn
On Friday, 8 May 2015 at 11:25:26 UTC, Per Nordlöw wrote: Such a feature would make the usage of this pattern very (perhaps even absolutely) safe from a memory corruption point of view. Correction: Not exactly memory corruption point of view. Rather to avoid logical bugs when

mscoff x86 invalid pointers

2015-05-08 Thread Etienne via Digitalmars-d-learn
I'm trying to compile a library that I think used to work with -m32mscoff flag before I reset my machine configurations. https://github.com/etcimon/memutils Whenever I run `dub test --config=32mscoff` it gives me an assertion failure, which is a global variable that already has a pointer