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
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
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(
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
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
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
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
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
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
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
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
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
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
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
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
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
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 (
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.
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 {
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)
{
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.
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
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
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
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;
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
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))
{
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
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
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
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,
31 matches
Mail list logo