Re: Why .dup not work with multidimensional arrays?

2015-05-07 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-07 Thread Nick Sabalausky via Digitalmars-d-learn
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 should be a way to do it without allocating an array. But it's n

Re: Moving from Python to D

2015-05-07 Thread Nick Sabalausky via Digitalmars-d-learn
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 declared like this: string[string][string] scenes; Then the above lin

Re: Moving from Python to D

2015-05-07 Thread Nick Sabalausky via Digitalmars-d-learn
I'm not really sure exactly what parts are the issue, but I'll point out what I can: On 05/07/2015 11:24 PM, avarisclari 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 s

Moving from Python to D

2015-05-07 Thread avarisclari via Digitalmars-d-learn
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 to get this right? Here's the python: scene = scenes["title"] while 1 == 1:

Re: Why .dup not work with multidimensional arrays?

2015-05-07 Thread Dennis Ritchie via Digitalmars-d-learn
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 the inner arrays yourself if you need to make a

Re: Why .dup not work with multidimensional arrays?

2015-05-07 Thread E.S. Quinn via Digitalmars-d-learn
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 the inner arrays yourself if you need to make a deep copy. On Friday, 8 May 2015 at 02:15:38 UTC, Dennis

Why .dup not work with multidimensional arrays?

2015-05-07 Thread Dennis Ritchie via Digitalmars-d-learn
Hi, Should the method .dup work with multidimensional arrays for copying? - import std.stdio; void main() { auto a = [1, 2, 3]; auto b = a.dup; b[] *= 2; writeln("a = ", a); // [1, 2, 3] // OK writeln("b = ", b); // [2, 4, 6] // OK auto c

Re: Multiple template alias parameters

2015-05-07 Thread Rikki Cattermole via Digitalmars-d-learn
On 8/05/2015 1:53 p.m., Brian Schott wrote: I have some code that automatically wires up control flow based on annotations. Use of this code looks something like this: ``` import some_package.some_module; void main(string[] args) { doMagicStuff!(some_package.some_module)(args); } ``` All of

Multiple template alias parameters

2015-05-07 Thread Brian Schott via Digitalmars-d-learn
I have some code that automatically wires up control flow based on annotations. Use of this code looks something like this: ``` import some_package.some_module; void main(string[] args) { doMagicStuff!(some_package.some_module)(args); } ``` All of this works and everything is happy (Except t

Re: Bitfield-style enum to strings?

2015-05-07 Thread Meta via Digitalmars-d-learn
On Thursday, 7 May 2015 at 21:41:06 UTC, Nick Sabalausky wrote: On 05/07/2015 05:19 PM, Justin Whear wrote: On Thu, 07 May 2015 16:55:42 -0400, Nick Sabalausky wrote: // There's gotta be a better way to convert EnumMembers!T // to a range, right? But std.range.only() didn't work, //

Re: Baffled by compilation error for formattedRead

2015-05-07 Thread Dennis Ritchie via Digitalmars-d-learn
On Thursday, 7 May 2015 at 23:13:41 UTC, PhilipDaniels wrote: On Thursday, 7 May 2015 at 23:10:26 UTC, PhilipDaniels wrote: Let's try reformatting that... ubyte r, g, b; // does not compile auto numRead = formattedRead(dropExactly(input, 4), "%x/%x/%x", &r, &g, &b); // does not compile auto

Re: Baffled by compilation error for formattedRead

2015-05-07 Thread PhilipDaniels via Digitalmars-d-learn
On Thursday, 7 May 2015 at 23:23:08 UTC, Justin Whear wrote: formattedRead takes its input by ref and consumes it. Your first two attempts are both passing the result of functions (dropExactly and opSlice) which are temporary rvalues and can thus not be passed by reference. Here's more readin

Re: Baffled by compilation error for formattedRead

2015-05-07 Thread Justin Whear via Digitalmars-d-learn
On Thu, 07 May 2015 23:10:26 +, PhilipDaniels wrote: > Why do the first two fail to compile but the last one does?! I cannot > see any difference between the 's2' case and the second case, it is a > completely mechanical source code transformation I have made. formattedRead takes its input by

Re: Baffled by compilation error for formattedRead

2015-05-07 Thread PhilipDaniels via Digitalmars-d-learn
On Thursday, 7 May 2015 at 23:10:26 UTC, PhilipDaniels wrote: Let's try reformatting that... ubyte r, g, b; // does not compile auto numRead = formattedRead(dropExactly(input, 4), "%x/%x/%x", &r, &g, &b); // does not compile auto numRead = formattedRead(input[4..$], "%x/%x/%x", &r, &g, &b);

Baffled by compilation error for formattedRead

2015-05-07 Thread PhilipDaniels via Digitalmars-d-learn
Given a string string input = "rgb:20/30/40"; And the following: ubyte r, g, b; auto numRead = formattedRead(dropExactly(input, 4), "%x/%x/%x", &r, &g, &b); // does not compile auto numRead = formattedRead(input[4..$], "%x/%x/%x", &r, &g, &b);// does not c

Re: Bitfield-style enum to strings?

2015-05-07 Thread anonymous via Digitalmars-d-learn
On Thursday, 7 May 2015 at 20:55:42 UTC, Nick Sabalausky wrote: // There's gotta be a better way to convert EnumMembers!T // to a range, right? But std.range.only() didn't work, // due to a template instantiation error. T[] members; foreach(m; EnumMembers!(T)) members

Re: Merging one Array with Another

2015-05-07 Thread via Digitalmars-d-learn
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 you really need. :) Thanks. These are good ideas in general.

Re: Bitfield-style enum to strings?

2015-05-07 Thread Nick Sabalausky via Digitalmars-d-learn
On 05/07/2015 05:19 PM, Justin Whear wrote: On Thu, 07 May 2015 16:55:42 -0400, Nick Sabalausky wrote: // There's gotta be a better way to convert EnumMembers!T // to a range, right? But std.range.only() didn't work, // due to a template instantiation error. T[] members;

Re: Bitfield-style enum to strings?

2015-05-07 Thread Justin Whear via Digitalmars-d-learn
On Thu, 07 May 2015 16:55:42 -0400, Nick Sabalausky wrote: > // There's gotta be a better way to convert EnumMembers!T // to a > range, right? But std.range.only() didn't work, // due to a > template instantiation error. > T[] members; > foreach(m; EnumMembers!(T)) >

Re: Bitfield-style enum to strings?

2015-05-07 Thread Nick Sabalausky via Digitalmars-d-learn
Gah, missed some imports that time: On 05/07/2015 05:04 PM, Nick Sabalausky wrote: Minor fix to work right for "none" fields. Already worked fine on combination fields liek "all". - enum Foo { none = 0, optionA = 1<<0, optionB = 1<<1, opti

Re: Bitfield-style enum to strings?

2015-05-07 Thread Nick Sabalausky via Digitalmars-d-learn
Minor fix to work right for "none" fields. Already worked fine on combination fields liek "all". - enum Foo { none = 0, optionA = 1<<0, optionB = 1<<1, optionC = 1<<2, optionD = 1<<3, all = optionA | optionB | optionC | optionD, } impo

Re: Bitfield-style enum to strings?

2015-05-07 Thread Nick Sabalausky via Digitalmars-d-learn
On 05/07/2015 01:41 PM, Nick Sabalausky wrote: Assuming a plain old bitfield-style enum like: enum Foo { optionA = 1<<0; optionB = 1<<1; optionC = 1<<2; optionD = 1<<3; optionE = 1<<4; } Does a function already exist somewhere to take an instance of Foo and get a list o

Re: Looking for MQTT client library

2015-05-07 Thread Orfeo via Digitalmars-d-learn
On Thursday, 23 April 2015 at 14:40:01 UTC, Frank Pagliughi wrote: I got the OK to submit the D library to Eclipse Paho. So, hopefully within the next few weeks there will be a Paho incubator project for the D language client. Hi Frank, any news about your MQTT client project? Thank you

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

2015-05-07 Thread yawniek via Digitalmars-d-learn
On Thursday, 7 May 2015 at 18:59:13 UTC, Suliman wrote: shared static this() { auto router = new URLRouter; router.get("/", &root); auto settings = new HTTPServerSettings; settings.port = 8080; listenHTTP(settings, router); } void root(HTTPServerRequest req, HTT

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

2015-05-07 Thread yawniek via Digitalmars-d-learn
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: https://github.com/rejectedsoftware/vibe.d/blob/11578aa956a9b3b0e305d655f9668a867fdd89bd/source/vibe/inet/pat

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

2015-05-07 Thread Suliman via Digitalmars-d-learn
shared static this() { auto router = new URLRouter; router.get("/", &root); auto settings = new HTTPServerSettings; settings.port = 8080; listenHTTP(settings, router); } void root(HTTPServerRequest req, HTTPServerResponse res) { serveStaticFiles("public/"

Re: Bitfield-style enum to strings?

2015-05-07 Thread Baz via Digitalmars-d-learn
On Thursday, 7 May 2015 at 17:41:10 UTC, Nick Sabalausky wrote: Assuming a plain old bitfield-style enum like: enum Foo { optionA = 1<<0; optionB = 1<<1; optionC = 1<<2; optionD = 1<<3; optionE = 1<<4; } Does a function already exist somewhere to take an instance of Foo and

Bitfield-style enum to strings?

2015-05-07 Thread Nick Sabalausky via Digitalmars-d-learn
Assuming a plain old bitfield-style enum like: enum Foo { optionA = 1<<0; optionB = 1<<1; optionC = 1<<2; optionD = 1<<3; optionE = 1<<4; } Does a function already exist somewhere to take an instance of Foo and get a list of the switch names as strings? Something kinda lik

Re: Signs by which to recognize D1

2015-05-07 Thread ketmar via Digitalmars-d-learn
On Wed, 06 May 2015 14:26:43 +, rumbu wrote: > operator overloads: opCom, opAdd, opSub ... phobos' std.xml, std.variand and std.bitmanip are D1! ;-) signature.asc Description: PGP signature

Re: Merging one Array with Another

2015-05-07 Thread Andrea Fontana via Digitalmars-d-learn
On Thursday, 7 May 2015 at 09:21:58 UTC, Per Nordlöw wrote: On Thursday, 7 May 2015 at 08:03:41 UTC, Andrea Fontana wrote: It's not that difficult to implement. You just need to implement a merge() range that returns the min of all ranges' front(). Then you can define distinct() for SortedRang

Re: Static function template

2015-05-07 Thread Daniel Kozak via Digitalmars-d-learn
On Thursday, 7 May 2015 at 11:18:17 UTC, Daniel Kozak wrote: On Thursday, 7 May 2015 at 11:15:02 UTC, Daniel Kozak wrote: On Thursday, 7 May 2015 at 11:08:50 UTC, Daniel Kozák wrote: On Thu, 07 May 2015 10:46:19 + Lemonfiend via Digitalmars-d-learn wrote: On Thursday, 7 May 2015 at 10

Re: Static function template

2015-05-07 Thread Daniel Kozak via Digitalmars-d-learn
On Thursday, 7 May 2015 at 10:19:44 UTC, Lemonfiend wrote: Is it not possible to have a static function template with the same name as the non-static version? struct S { int i; auto foo(T)(int j) { i=j; } static auto foo(T)(int j) { S s; s.foo!T(j);

Re: Static function template

2015-05-07 Thread Daniel Kozak via Digitalmars-d-learn
On Thursday, 7 May 2015 at 11:08:50 UTC, Daniel Kozák wrote: On Thu, 07 May 2015 10:46:19 + Lemonfiend via Digitalmars-d-learn wrote: On Thursday, 7 May 2015 at 10:43:28 UTC, Daniel Kozak wrote: > On Thursday, 7 May 2015 at 10:39:09 UTC, Daniel Kozák wrote: >> >> On Thu, 07 May 2015 10:

Re: Static function template

2015-05-07 Thread Daniel Kozak via Digitalmars-d-learn
On Thursday, 7 May 2015 at 11:15:02 UTC, Daniel Kozak wrote: On Thursday, 7 May 2015 at 11:08:50 UTC, Daniel Kozák wrote: On Thu, 07 May 2015 10:46:19 + Lemonfiend via Digitalmars-d-learn wrote: On Thursday, 7 May 2015 at 10:43:28 UTC, Daniel Kozak wrote: > On Thursday, 7 May 2015 at 1

Re: Static function template

2015-05-07 Thread Daniel Kozák via Digitalmars-d-learn
On Thu, 07 May 2015 10:46:19 + Lemonfiend via Digitalmars-d-learn wrote: > On Thursday, 7 May 2015 at 10:43:28 UTC, Daniel Kozak wrote: > > On Thursday, 7 May 2015 at 10:39:09 UTC, Daniel Kozák wrote: > >> > >> On Thu, 07 May 2015 10:33:44 + > >> Vadim Lopatin via Digitalmars-d-learn > >

Re: Static function template

2015-05-07 Thread Lemonfiend via Digitalmars-d-learn
On Thursday, 7 May 2015 at 10:43:28 UTC, Daniel Kozak wrote: On Thursday, 7 May 2015 at 10:39:09 UTC, Daniel Kozák wrote: On Thu, 07 May 2015 10:33:44 + Vadim Lopatin via Digitalmars-d-learn wrote: struct S { int i; auto foo2(T)(int j) { i=j; } static S foo(T)(i

Re: Static function template

2015-05-07 Thread Daniel Kozak via Digitalmars-d-learn
On Thursday, 7 May 2015 at 10:39:09 UTC, Daniel Kozák wrote: On Thu, 07 May 2015 10:33:44 + Vadim Lopatin via Digitalmars-d-learn wrote: struct S { int i; auto foo2(T)(int j) { i=j; } static S foo(T)(int j) { S s; s.foo2!T(j); retu

Re: Static function template

2015-05-07 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, May 07, 2015 10:19:42 Lemonfiend via Digitalmars-d-learn wrote: > Is it not possible to have a static function template with the > same name as the non-static version? No. Unfortunately, you can't overload based on static. I believe that it works if they're overloaded on parameters bu

Re: Static function template

2015-05-07 Thread Daniel Kozák via Digitalmars-d-learn
On Thu, 07 May 2015 10:33:44 + Vadim Lopatin via Digitalmars-d-learn wrote: > struct S > { > int i; > > auto foo2(T)(int j) { > i=j; > } > > static S foo(T)(int j) { > S s; > s.foo2!T(j); > return s; > } > } > > void main() > {

Re: Static function template

2015-05-07 Thread Daniel Kozák via Digitalmars-d-learn
On Thu, 07 May 2015 10:19:42 + Lemonfiend via Digitalmars-d-learn wrote: > Is it not possible to have a static function template with the > same name as the non-static version? > > struct S > { > int i; > > auto foo(T)(int j) { > i=j; > } > > static auto foo(

Re: Static function template

2015-05-07 Thread Vadim Lopatin via Digitalmars-d-learn
On Thursday, 7 May 2015 at 10:19:44 UTC, Lemonfiend wrote: Is it not possible to have a static function template with the same name as the non-static version? struct S { int i; auto foo(T)(int j) { i=j; } static auto foo(T)(int j) { S s; s.foo!T(j);

Re: Static function template

2015-05-07 Thread Daniel Kozák via Digitalmars-d-learn
On Thu, 07 May 2015 10:19:42 + Lemonfiend via Digitalmars-d-learn wrote: > Is it not possible to have a static function template with the > same name as the non-static version? > > struct S > { > int i; > > auto foo(T)(int j) { > i=j; > } > > static auto foo(

Static function template

2015-05-07 Thread Lemonfiend via Digitalmars-d-learn
Is it not possible to have a static function template with the same name as the non-static version? struct S { int i; auto foo(T)(int j) { i=j; } static auto foo(T)(int j) { S s; s.foo!T(j); return s; } } void main() { auto s = S.foo!boo

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

2015-05-07 Thread Chris via Digitalmars-d-learn
Later you can have more sophisticated methods, e.g. if you want to handle query strings you could do something like this: import vibe.d; shared static this() { auto settings = new HTTPServerSettings; settings.port = 8080; settings.bindAddresses = ["::1", "127.0.0.1"]; auto router = ne

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

2015-05-07 Thread Chris via Digitalmars-d-learn
On Thursday, 7 May 2015 at 09:27:39 UTC, Chris wrote: On Thursday, 7 May 2015 at 08:25:30 UTC, Suliman wrote: You're not setting a port. add: settings.port = 8080; before listenHTTP(); then it'll work. It's do not help :( This should work, put it in your `app.d` file: import vibe.d; sha

Re: Merging one Array with Another

2015-05-07 Thread via Digitalmars-d-learn
On Thursday, 7 May 2015 at 09:21:58 UTC, Per Nordlöw wrote: I was only interested in removing equal consequtive elements within the same range. I looked at UniqResult. What we need is to fix the typesystem with perhaps some traits the figure out which ranges (multi-layered meta-ranges) posses

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

2015-05-07 Thread Chris via Digitalmars-d-learn
On Thursday, 7 May 2015 at 08:25:30 UTC, Suliman wrote: You're not setting a port. add: settings.port = 8080; before listenHTTP(); then it'll work. It's do not help :( This should work, put it in your `app.d` file: import vibe.d; shared static this() { auto settings = new HTTPServerSe

Re: Merging one Array with Another

2015-05-07 Thread via Digitalmars-d-learn
On Thursday, 7 May 2015 at 08:03:41 UTC, Andrea Fontana wrote: It's not that difficult to implement. You just need to implement a merge() range that returns the min of all ranges' front(). Then you can define distinct() for SortedRange as: merge(sortedrange1, sortedrange2, sortedrange3).uniq

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

2015-05-07 Thread wobbles via Digitalmars-d-learn
On Thursday, 7 May 2015 at 09:08:53 UTC, wobbles wrote: On Thursday, 7 May 2015 at 08:25:30 UTC, Suliman wrote: You're not setting a port. add: settings.port = 8080; before listenHTTP(); then it'll work. It's do not help :( You're sure? My app.d is: import std.stdio; import vibe.d; shar

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

2015-05-07 Thread wobbles via Digitalmars-d-learn
On Thursday, 7 May 2015 at 08:25:30 UTC, Suliman wrote: You're not setting a port. add: settings.port = 8080; before listenHTTP(); then it'll work. It's do not help :( You're sure? My app.d is: import std.stdio; import vibe.d; shared static this(){ auto router = new URLRouter;

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

2015-05-07 Thread Suliman via Digitalmars-d-learn
You're not setting a port. add: settings.port = 8080; before listenHTTP(); then it'll work. It's do not help :(

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

2015-05-07 Thread wobbles via Digitalmars-d-learn
On Thursday, 7 May 2015 at 08:09:50 UTC, Suliman wrote: Is next example is enough to serv simple index.html page? void setupServer() { auto router = new URLRouter; // add other routes here router.get("*", serveStaticFiles("public/")); auto settings = new HTTPServ

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

2015-05-07 Thread Suliman via Digitalmars-d-learn
Is next example is enough to serv simple index.html page? void setupServer() { auto router = new URLRouter; // add other routes here router.get("*", serveStaticFiles("public/")); auto settings = new HTTPServerSettings; listenHTTP(settings, router); } Afte

Re: Merging one Array with Another

2015-05-07 Thread Andrea Fontana via Digitalmars-d-learn
On Thursday, 7 May 2015 at 06:53:39 UTC, Per Nordlöw wrote: On Wednesday, 6 May 2015 at 16:05:15 UTC, Andrea Fontana wrote: Maybe a way like this could be useful: http://dpaste.dzfl.pl/7b4b37b490a7 If r is a SortedRange this is very unneccesary wasteful because of the use AA. In that case y