Re: Palindromes

2015-12-03 Thread Ali Çehreli via Digitalmars-d-learn
On 12/03/2015 04:23 PM, Jim Barnett wrote: > The `import` statement inside the `for`-loop kind of smells to me. In addition to what others have explained, local imports are necessary for template mixins: http://ddili.org/ders/d.en/mixin.html#ix_mixin.import,%20local Quoting: module a; im

Re: Palindromes

2015-12-03 Thread Jim Barnett via Digitalmars-d-learn
On Friday, 4 December 2015 at 03:33:55 UTC, Meta wrote: I have never seen a language that encourages the user to specify dependencies inside a loop. I am hoping I misunderstood something here. Sorry, I thought you were referring more generally to nested imports. No, imports in a while loop ar

Re: Reset all Members of a Aggregate Instance

2015-12-03 Thread Tofu Ninja via Digitalmars-d-learn
On Friday, 4 December 2015 at 04:08:33 UTC, Tofu Ninja wrote: On Thursday, 3 December 2015 at 21:04:00 UTC, Nordlöw wrote: ... I think reflection will be a bad choice for this because of private members and what not. I think the correct way is: void reset(C)(ref C c) { static if(is(

Re: Reset all Members of a Aggregate Instance

2015-12-03 Thread Tofu Ninja via Digitalmars-d-learn
On Thursday, 3 December 2015 at 21:04:00 UTC, Nordlöw wrote: ... I think reflection will be a bad choice for this because of private members and what not. I think the correct way is: void reset(C)(ref C c) { static if(is(C == class)) { auto init = typeid(c).in

Re: Palindromes

2015-12-03 Thread Meta via Digitalmars-d-learn
On Friday, 4 December 2015 at 01:10:41 UTC, Jim Barnett wrote: Really? If it leads to "hard to detect errors", I have a hard time believing that can be "idiomatic D". It's used throughout the standard library, granted I don't think there's any occurrences of importing inside a while loop. The

Re: Palindromes

2015-12-03 Thread Brad Anderson via Digitalmars-d-learn
On Friday, 4 December 2015 at 00:50:17 UTC, Meta wrote: On Friday, 4 December 2015 at 00:26:23 UTC, Jim Barnett wrote: On Friday, 4 December 2015 at 00:23:45 UTC, Jim Barnett wrote: The `import` statement inside the `for`-loop kind of smells to me. Sorry, inside the `while` loop In D it's

Re: Palindromes

2015-12-03 Thread Jim Barnett via Digitalmars-d-learn
On Friday, 4 December 2015 at 00:50:17 UTC, Meta wrote: On Friday, 4 December 2015 at 00:26:23 UTC, Jim Barnett wrote: On Friday, 4 December 2015 at 00:23:45 UTC, Jim Barnett wrote: The `import` statement inside the `for`-loop kind of smells to me. Sorry, inside the `while` loop In D it's

Re: Palindromes

2015-12-03 Thread Meta via Digitalmars-d-learn
On Friday, 4 December 2015 at 00:26:23 UTC, Jim Barnett wrote: On Friday, 4 December 2015 at 00:23:45 UTC, Jim Barnett wrote: The `import` statement inside the `for`-loop kind of smells to me. Sorry, inside the `while` loop In D it's considered idiomatic, but it can also cause some very h

Re: Palindromes

2015-12-03 Thread Jim Barnett via Digitalmars-d-learn
On Friday, 4 December 2015 at 00:23:45 UTC, Jim Barnett wrote: The `import` statement inside the `for`-loop kind of smells to me. Sorry, inside the `while` loop

Re: Palindromes

2015-12-03 Thread Jim Barnett via Digitalmars-d-learn
On Thursday, 3 December 2015 at 23:42:31 UTC, Nordlöw wrote: On Thursday, 3 December 2015 at 21:40:05 UTC, Jim Barnett wrote: Thanks for reading. My version slightly adjusted version: /** Returns: If range is a palindrome larger than $(D minLength). See also: http://forum.dlang.org/thr

Re: Palindromes

2015-12-03 Thread Nordlöw via Digitalmars-d-learn
On Thursday, 3 December 2015 at 21:40:05 UTC, Jim Barnett wrote: Thanks for reading. My version slightly adjusted version: /** Returns: If range is a palindrome larger than $(D minLength). See also: http://forum.dlang.org/thread/dlfeiszyweafpjioc...@forum.dlang.org#post-vpzuaqxvtdpzpeuor

Re: dataframe implementations

2015-12-03 Thread Jay Norwood via Digitalmars-d-learn
On Saturday, 21 November 2015 at 14:16:26 UTC, Laeeth Isharc wrote: Not sure it is a great idea to use a variant as the basic option when very often you will know that every cell in a particular column will be of the same type. I'm reading today about an n-dim extension to pandas named xray

Re: Palindromes

2015-12-03 Thread Jim Barnett via Digitalmars-d-learn
On Thursday, 3 December 2015 at 22:14:02 UTC, Justin Whear wrote: I don't think you want reverse because it works in-place; you'd need to make a copy to compare against. std.range.retro is probably what you're looking for: bool isPalindrome(R)(R range) if (isBidirectionalRange!R) { re

Re: Struct initializers as expressions

2015-12-03 Thread Enamex via Digitalmars-d-learn
On Thursday, 3 December 2015 at 15:31:49 UTC, Chris Wright wrote: On Thu, 03 Dec 2015 06:38:20 +, Mike Parker wrote: AFAIK, your only option is to use a struct constructor. This is the sort of thing they're used for. Which brings be back to positional arguments, which means that someone

Re: Reset all Members of a Aggregate Instance

2015-12-03 Thread Chris Wright via Digitalmars-d-learn
On Thu, 03 Dec 2015 21:55:04 +, Nordlöw wrote: > On Thursday, 3 December 2015 at 21:38:48 UTC, Chris Wright wrote: >> The terrible way is something like: >> >> void reset(Object o) >> in { >> assert(!(o is null)); >> } >> body { >> auto p = cast(ubyte*)*cast(void**)&o; >> auto ci = o.cla

Re: Palindromes

2015-12-03 Thread Justin Whear via Digitalmars-d-learn
On Thu, 03 Dec 2015 21:40:05 +, Jim Barnett wrote: > TL;DR I couldn't figure out how to write `isPalindrome` in terms of > std.algorithm.mutation.reverse > > I recognize it's more efficient in terms of CPU time and memory than my > C++ solution, but I suspect there is a shorter expression to

Re: Reset all Members of a Aggregate Instance

2015-12-03 Thread Nordlöw via Digitalmars-d-learn
On Thursday, 3 December 2015 at 21:38:48 UTC, Chris Wright wrote: The terrible way is something like: void reset(Object o) in { assert(!(o is null)); } body { auto p = cast(ubyte*)*cast(void**)&o; auto ci = o.classinfo; auto init = cast(ubyte)ci.init; p[0..init.length] = init[]; if (

Palindromes

2015-12-03 Thread Jim Barnett via Digitalmars-d-learn
TL;DR I couldn't figure out how to write `isPalindrome` in terms of std.algorithm.mutation.reverse I have dabbled in D a few times over the past few years, but still pretty inexperienced. I decided to work on some project euler problems in D for fun. A problem requires detecting a palindrome.

Re: Reset all Members of a Aggregate Instance

2015-12-03 Thread Chris Wright via Digitalmars-d-learn
The terrible way is something like: void reset(Object o) in { assert(!(o is null)); } body { auto p = cast(ubyte*)*cast(void**)&o; auto ci = o.classinfo; auto init = cast(ubyte)ci.init; p[0..init.length] = init[]; if (ci.defaultConstructor) { ci.defaultConstructor(o); } else {

Re: Reset all Members of a Aggregate Instance

2015-12-03 Thread Nordlöw via Digitalmars-d-learn
On Thursday, 3 December 2015 at 21:04:00 UTC, Nordlöw wrote: Something along foreach(ref member; __traits(allMembers, c)) { member = typeof(member).init; } This works for me: void resetAllMembers(T)(T c) if (is(T == class)) { foreach (ref m; c.tupleof) {

Re: Reset all Members of a Aggregate Instance

2015-12-03 Thread Sebastiaan Koppe via Digitalmars-d-learn
On Thursday, 3 December 2015 at 21:13:59 UTC, Nordlöw wrote: Need to assert that not a function and mutability (std.traits.isMutable) Yeah you need to do that.

Re: Reset all Members of a Aggregate Instance

2015-12-03 Thread Jakob Ovrum via Digitalmars-d-learn
On Thursday, 3 December 2015 at 21:04:00 UTC, Nordlöw wrote: Given class C { // lots of members } and a function f(C c) { } is there a generic way, perhaps through reflection, to reset (inside f) all members of `c` to their default values? Something along

Re: Reset all Members of a Aggregate Instance

2015-12-03 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 3 December 2015 at 21:04:00 UTC, Nordlöw wrote: is there a generic way, perhaps through reflection, to reset (inside f) all members of `c` to their default values? You could always copy the init back over it. For a struct: s = Struct.init; for a class... well, the code is a lot u

Re: Reset all Members of a Aggregate Instance

2015-12-03 Thread Nordlöw via Digitalmars-d-learn
On Thursday, 3 December 2015 at 21:08:30 UTC, Sebastiaan Koppe wrote: Haven't compiled but it should look something like this: foreach(member; __traits(allMembers, typeof(c))) __traits(getMember, c, member) = typeof(__traits(getMember, c, member)).init; Need to assert that not a function

Re: Reset all Members of a Aggregate Instance

2015-12-03 Thread Sebastiaan Koppe via Digitalmars-d-learn
Haven't compiled but it should look something like this: foreach(member; __traits(allMembers, typeof(c))) __traits(getMember, c, member) = typeof(__traits(getMember, c, member)).init;

Re: Reset all Members of a Aggregate Instance

2015-12-03 Thread Nordlöw via Digitalmars-d-learn
On Thursday, 3 December 2015 at 21:04:00 UTC, Nordlöw wrote: Given class C { // lots of members } and a function f(C c) { } is there a generic way, perhaps through reflection, to reset (inside f) all members of `c` to their default values? Something along

Reset all Members of a Aggregate Instance

2015-12-03 Thread Nordlöw via Digitalmars-d-learn
Given class C { // lots of members } and a function f(C c) { } is there a generic way, perhaps through reflection, to reset (inside f) all members of `c` to their default values? Something along foreach(ref member; __traits(allMembers, c)) {

Re: Struct initializers as expressions

2015-12-03 Thread Chris Wright via Digitalmars-d-learn
On Thu, 03 Dec 2015 06:38:20 +, Mike Parker wrote: > AFAIK, your only option is to use a struct constructor. This is the sort > of thing they're used for. Which brings be back to positional arguments, which means that someone wishing to supply a limit on the number of query results must als

__traits and string mixins

2015-12-03 Thread Christian Köstlin via Digitalmars-d-learn
Hi, I started an experiment with the informations that are available for compile time reflection. What I wanted to create is a thor like cli parser library, that forces you to encapsulate your programs into subclasses of Dli. The commands and options, that are understood by the generated cli

How to check session before access to static page?

2015-12-03 Thread Suliman via Digitalmars-d-learn
void main() { auto router = new URLRouter; router.get("/", serveStaticFiles("D:\\code\\onlineTest\\index.html")); router.get("/admin", serveStaticFiles("D:\\code\\onlineTest\\admin.html")); router.any("/foo", &foo); auto settings = new HTTPServerSettings; settings.port

Re: utils.toBulkString is not accesible from utils

2015-12-03 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, December 02, 2015 06:33:32 Andre via Digitalmars-d-learn wrote: > Hi, > > for following coding there is an error during compilation: > >module utils; > >package string toBulkString(string s) >{ > import std.string: format; > return "$%s\r\n%s\r\n".format(s.length,