Re: Converting Unicode Escape Sequences to UTF-8

2015-10-24 Thread Nordlöw via Digitalmars-d-learn
On Saturday, 24 October 2015 at 08:54:40 UTC, Nordlöw wrote: Working first version at https://github.com/nordlow/justd/blob/master/conv_ex.d#L207 Next I'll make it a range. Made it a range: https://github.com/nordlow/justd/blob/master/conv_ex.d#L207

Re: Problem Benchmarking HashSet from containers-em

2015-10-22 Thread Nordlöw via Digitalmars-d-learn
On Thursday, 22 October 2015 at 17:32:34 UTC, Justin Whear wrote: On Thu, 22 Oct 2015 11:55:37 +, Nordlöw wrote: What's wrong? HashSet has a disabled default constructor; you need to supply the allocator instance to the constructor here https://github.com/nordlow/

Converting Unicode Escape Sequences to UTF-8

2015-10-22 Thread Nordlöw via Digitalmars-d-learn
How do I convert a `string` containing Unicode escape sequences such as "\u" into UTF-8?

Re: Converting Unicode Escape Sequences to UTF-8

2015-10-22 Thread Nordlöw via Digitalmars-d-learn
On Thursday, 22 October 2015 at 19:16:36 UTC, Nordlöw wrote: Can somebody point out in which function/file DMD does this decoding? std.conv.parseEscape includes this logic. But why is it private?

Re: Converting Unicode Escape Sequences to UTF-8

2015-10-22 Thread Nordlöw via Digitalmars-d-learn
On Thursday, 22 October 2015 at 18:40:06 UTC, anonymous wrote: On Thursday, October 22, 2015 08:10 PM, Nordlöw wrote: How do I convert a `string` containing Unicode escape sequences such as "\u" into UTF-8? Ali explained that "\u" is already UTF-8. But if you actually want to

Re: Converting Unicode Escape Sequences to UTF-8

2015-10-22 Thread Nordlöw via Digitalmars-d-learn
On Thursday, 22 October 2015 at 19:13:20 UTC, Nordlöw wrote: * Drop the backslash and the 'u'. * Parse as a hexadecimal integer, and cast to dchar. * Use std.utf.encode to convert to UTF-8. std.conv.to can probably do it too, and possibly simpler, but would allocate. Also be aware of the

Re: Problem Benchmarking HashSet from containers-em

2015-10-22 Thread Nordlöw via Digitalmars-d-learn
On Thursday, 22 October 2015 at 11:55:39 UTC, Nordlöw wrote: https://github.com/nordlow/justd/blob/master/containers_ex.d The current GitHub of containers_ex.d (using dmd git master) version works if justd repo is cloned recursively.

Problem Benchmarking HashSet from containers-em

2015-10-22 Thread Nordlöw via Digitalmars-d-learn
At https://github.com/nordlow/justd/blob/master/containers_ex.d I want to benchmark Economic Modelings container packages. Specifically HashSet with different allocators. But when I try to use `LocalAllocator` defined as alias LocalAllocator = InSituRegion!(n, T.alignof); at

Re: Problem Benchmarking HashSet from containers-em

2015-10-22 Thread Nordlöw via Digitalmars-d-learn
On Thursday, 22 October 2015 at 11:57:37 UTC, Nordlöw wrote: On Thursday, 22 October 2015 at 11:55:39 UTC, Nordlöw wrote: https://github.com/nordlow/justd/blob/master/containers_ex.d The current GitHub of containers_ex.d (using dmd git master) version works if justd repo is cloned

Re: Converting Unicode Escape Sequences to UTF-8

2015-10-24 Thread Nordlöw via Digitalmars-d-learn
On Thursday, 22 October 2015 at 21:52:05 UTC, anonymous wrote: On 22.10.2015 21:13, Nordlöw wrote: Hmm, why isn't this already in Phobos? Working first version at https://github.com/nordlow/justd/blob/master/conv_ex.d#L207 Next I'll make it a range.

Re: Capturing __FILE__ and __LINE in a variadic templated function

2015-11-02 Thread Nordlöw via Digitalmars-d-learn
On Tuesday, 3 November 2015 at 06:14:14 UTC, Jonathan M Davis wrote: You should pretty much never use __FILE__ or __LINE__ as template arguments unless you actually need to. The reason is that it will end up creating a new instantiation of the template pretty much every time that it's used,

Bidirectional Filter

2015-11-03 Thread Nordlöw via Digitalmars-d-learn
Is there a reason why std.algorithm.iteration.filter() doesn't propagate bidirectional access?

Re: Capturing __FILE__ and __LINE in a variadic templated function

2015-11-02 Thread Nordlöw via Digitalmars-d-learn
On Tuesday, 3 November 2015 at 06:14:14 UTC, Jonathan M Davis wrote: You should pretty much never use __FILE__ or __LINE__ as template arguments unless you actually need to. The reason is that it will end up creating a new instantiation of the template pretty much every time that it's used,

Re: Lazy std.algorithm.replace()

2015-11-02 Thread Nordlöw via Digitalmars-d-learn
On Monday, 2 November 2015 at 20:25:44 UTC, Adam D. Ruppe wrote: On Sunday, 1 November 2015 at 14:26:21 UTC, Nordlöw wrote: Is there a reason why Phobos doesn't contain a lazy range variant of std.string.replace? Would something like map work with the predicate being if(matches_needle)

Re: Lazy std.algorithm.replace()

2015-11-02 Thread Nordlöw via Digitalmars-d-learn
On Monday, 2 November 2015 at 19:53:09 UTC, Ali Çehreli wrote: On 11/02/2015 04:22 AM, Nordlöw wrote: On Sunday, 1 November 2015 at 14:26:21 UTC, Nordlöw wrote: Is there a reason why Phobos doesn't contain a lazy range variant of std.string.replace? Ping. What is the use case? Chaining

Lazy std.algorithm.replace()

2015-11-01 Thread Nordlöw via Digitalmars-d-learn
Is there a reason why Phobos doesn't contain a lazy range variant of std.string.replace?

Capturing __FILE__ and __LINE in a variadic templated function

2015-11-01 Thread Nordlöw via Digitalmars-d-learn
Is it possible to make the following definition void show(alias T, string file = __FILE__, uint line = __LINE__, string fun = __FUNCTION__)() { import std.stdio: writeln; try { debug writeln(file, ":",line, ":" /* , ": in ",fun */, " debug: ", T.stringof, ":", T); } catch

Re: Capturing __FILE__ and __LINE in a variadic templated function

2015-11-02 Thread Nordlöw via Digitalmars-d-learn
On Sunday, 1 November 2015 at 23:36:15 UTC, anonymous wrote: On 01.11.2015 23:49, Adam D. Ruppe wrote: Yeah, just make the other args normal runtime instead of template: Or make it two nested templates: template show(T...) { void show(string file = __FILE__, uint line = __LINE__,

RFC: Lazy variadic replace() that reuses find()

2015-11-07 Thread Nordlöw via Digitalmars-d-learn
I'm building a reference solution to a lazy variadic implementation of `replace` https://github.com/nordlow/justd/blob/master/replacing.d which, when ready, I plan to propose to Phobos' std.algorithm. I'm already done with the easier run-time and compile-time variadic overloads for the case

Re: Lazy std.algorithm.replace()

2015-11-07 Thread Nordlöw via Digitalmars-d-learn
On Monday, 2 November 2015 at 20:22:11 UTC, Nordlöw wrote: I'm done with the easy cases at https://github.com/nordlow/justd/blob/master/algorithm_ex.d#L1946 and https://github.com/nordlow/justd/blob/master/algorithm_ex.d#L1997 Moved stuff to

Re: RFC: Lazy variadic replace() that reuses find()

2015-11-07 Thread Nordlöw via Digitalmars-d-learn
On Saturday, 7 November 2015 at 15:29:08 UTC, Nordlöw wrote: `xx_yy_zz`.findSplitter(`11`, ... should be `xx_yy_zz`.findSplitter("xx", "zz")

Re: Capturing __FILE__ and __LINE in a variadic templated function

2015-11-02 Thread Nordlöw via Digitalmars-d-learn
On Monday, 2 November 2015 at 09:02:28 UTC, Gary Willoughby wrote: On Monday, 2 November 2015 at 08:23:16 UTC, Nordlöw wrote: I need `T` to be an alias in order for .stringof to work. typeof(T).stringof No, I want the variable name from the calling scope. This works for a single argument.

Re: Capturing __FILE__ and __LINE in a variadic templated function

2015-11-02 Thread Nordlöw via Digitalmars-d-learn
On Monday, 2 November 2015 at 09:54:50 UTC, John Colvin wrote: Works for me on multiple compilers. To be precise, this worked: template show(Args...) { void show(string file = __FILE__, uint line = __LINE__, string fun = __FUNCTION__)() { import std.stdio: write, writeln;

Re: Capturing __FILE__ and __LINE in a variadic templated function

2015-11-02 Thread Nordlöw via Digitalmars-d-learn
On Monday, 2 November 2015 at 11:44:45 UTC, Daniel N wrote: On Monday, 2 November 2015 at 11:36:27 UTC, Nordlöw wrote: I want it to print the name of Arg in the closing as x is 11 See my previous comment: Arg -> Args[i].stringof Ahh! Great! Thx!

Re: Lazy std.algorithm.replace()

2015-11-02 Thread Nordlöw via Digitalmars-d-learn
On Sunday, 1 November 2015 at 14:26:21 UTC, Nordlöw wrote: Is there a reason why Phobos doesn't contain a lazy range variant of std.string.replace? Ping.

Re: Idiomatic adjacent_difference

2015-10-16 Thread Nordlöw via Digitalmars-d-learn
On Friday, 16 October 2015 at 15:02:54 UTC, anonymous wrote: By the way, what's the point of `dropOne` over `drop(1)`? It's not shorter. Does it do anything subtly different? I also find it strange.

Building and Running Unittests for a Specific Phobos Package Only

2015-10-15 Thread Nordlöw via Digitalmars-d-learn
Is there a Make-target for building and running the unittests for a specific Phobos package, say `std.range`, only?

Re: Building and Running Unittests for a Specific Phobos Package Only

2015-10-15 Thread Nordlöw via Digitalmars-d-learn
On Thursday, 15 October 2015 at 13:12:32 UTC, Marc Schütz wrote: make -f posix.mak std/range.test Thx

Re: std.algorithm.startsWith only predicate

2015-10-19 Thread Nordlöw via Digitalmars-d-learn
On Sunday, 18 October 2015 at 21:44:57 UTC, Jonathan M Davis wrote: startsWith doesn't have an overload that takes only a predicate. The existing overloads all require at least one "needle" to search for in the "haystack." An overload that doesn't require a needle could certainly be added, but

Caching of Template Instantiations

2015-10-17 Thread Nordlöw via Digitalmars-d-learn
Does DMD cache template instantiations? That is, is it preferred to do, for instance, either static if (isIntegral!T && isUnsigned!(T)) {} else static if (isIntegral!T && isSigned!(T)) {} or enum integral = isIntegral!T; static if (integral && isUnsigned!(T)) {}

Re: Hash-Table-Based Multiple Arguments Replacement

2015-10-10 Thread Nordlöw via Digitalmars-d-learn
On Saturday, 10 October 2015 at 16:19:53 UTC, Nordlöw wrote: Is there an algorithm somewhere in Phobos which performs when possible a replacement/substitution based on a variadic definition of replacements using hash-table search similar to Found it:

Hash-Table-Based Multiple Arguments Replacement

2015-10-10 Thread Nordlöw via Digitalmars-d-learn
Is there an algorithm somewhere in Phobos which performs when possible a replacement/substitution based on a variadic definition of replacements using hash-table search similar to string replaceWhole(string a) { switch (x) { case "a": return "1"; case "b": return "2";

Re: Hash-Table-Based Multiple Arguments Replacement

2015-10-10 Thread Nordlöw via Digitalmars-d-learn
On Saturday, 10 October 2015 at 16:42:52 UTC, Nordlöw wrote: Found it: http://dlang.org/phobos/std_algorithm_comparison.html#predSwitch An alias would be perhaps be motivated to make newcomers easier grap that this can be used for whole replacements. Ahh, but this doesn't use a hash-table

Re: Hash-Table-Based Multiple Arguments Replacement

2015-10-11 Thread Nordlöw via Digitalmars-d-learn
On Sunday, 11 October 2015 at 05:06:04 UTC, Nordlöw wrote: On Sunday, 11 October 2015 at 00:16:44 UTC, Meta wrote: There was something like this proposed quite awhile ago (can't remember what it was, might've been extending unary/binaryFun to accept an AA), but it was rejected. With static

Re: Hash-Table-Based Multiple Arguments Replacement

2015-10-10 Thread Nordlöw via Digitalmars-d-learn
On Sunday, 11 October 2015 at 00:16:44 UTC, Meta wrote: There was something like this proposed quite awhile ago (can't remember what it was, might've been extending unary/binaryFun to accept an AA), but it was rejected. With static foreach in a switch we can do better. I'll put together a

Re: Picking specific D compiler with rdmd

2015-10-06 Thread Nordlöw via Digitalmars-d-learn
On Tuesday, 6 October 2015 at 07:16:39 UTC, Nordlöw wrote: I find now flag to rdmd for choosing a specific dmd. Is there none? Doh, there was already: --compiler

Picking specific D compiler with rdmd

2015-10-06 Thread Nordlöw via Digitalmars-d-learn
I find now flag to rdmd for choosing a specific dmd. Is there none?

Struct toString works but not std.conv.to!string

2015-10-13 Thread Nordlöw via Digitalmars-d-learn
I have defined a struct UTCOffset in https://github.com/nordlow/justd/blob/master/datetime_ex.d Everything works as desired except for import std.conv : to; assert(UTCOffset(+14, 0).to!string == "UTC+14:00"); which fails as /usr/include/dmd/phobos/std/conv.d(293,14): Error: template

Re: Struct toString works but not std.conv.to!string

2015-10-13 Thread Nordlöw via Digitalmars-d-learn
On Tuesday, 13 October 2015 at 21:50:54 UTC, Jonathan M Davis wrote: Just glancing at your code, you've marked toString with @property, which is kind of a weird thing to do, nd if we ever make @property enforce that it's not called with parens, then that code won't work. So, you might try

Re: lint? for D

2015-10-09 Thread Nordlöw via Digitalmars-d-learn
On Friday, 9 October 2015 at 12:28:50 UTC, Pradeep Gowda wrote: Is there a lint program for D, similar to say pep8 + pyflakes for python that can warn the programmer about unused imports, unused variables etc.,? https://github.com/Hackerpilot/Dscanner dscanner --syntaxCheck or dscanner

Checking for Homogeneous Tuples

2015-09-15 Thread Nordlöw via Digitalmars-d-learn
How do I check that all the elements of a std.typecons.Tuple all fulfil a specific predicate, in my case all have a specific type: Something like import std.typecons : isTuple; enum isTupleOf(T, E) = isTuple!T && is(MAGIC(T, E));

Re: Checking for Homogeneous Tuples

2015-09-15 Thread Nordlöw via Digitalmars-d-learn
On Tuesday, 15 September 2015 at 17:41:07 UTC, Meta wrote: I made a pull request for this a long time ago but it was rejected. https://github.com/D-Programming-Language/phobos/pull/1672 I'll try again because it's needed here https://github.com/D-Programming-Language/phobos/pull/3395 ;)

Re: Pretty Printing TickDuration

2015-09-17 Thread Nordlöw via Digitalmars-d-learn
On Thursday, 17 September 2015 at 16:54:02 UTC, Nordlöw wrote: How do I convert an instance of `TickDuration` to that format? Solution: writeln("> Query took ", sw.peek().to!Duration);

Pretty Printing TickDuration

2015-09-17 Thread Nordlöw via Digitalmars-d-learn
Currently import std.datetime: StopWatch; StopWatch sw; sw.start; writeln(sw.peek()); prints for instance TickDuration(279483) I've seen Phobos doing something much more clever such as pretty printing of time in the format: 1 hour, 2 seconds, 3 milliseconds, etc. How

Re: Adjacent Pairs Range

2015-09-13 Thread Nordlöw via Digitalmars-d-learn
On Sunday, 13 September 2015 at 01:49:56 UTC, deed wrote: zip(arr[0 .. $-1], arr[1 .. $]) ? Assumes arrays. Better is zip(arr.dropOne, arr)

Passing Elements of A Static Array as Function Parameters

2015-09-13 Thread Nordlöw via Digitalmars-d-learn
If I have a static array `x` defined as enum N = 3; int[N] x; how do I pass it's elements into a variadic function f(T...)(T xs) if (T.length >= 3) ?

Re: Purity of std.conv.to!string

2015-09-28 Thread Nordlöw via Digitalmars-d-learn
On Sunday, 27 September 2015 at 05:52:26 UTC, Jack Stouffer wrote: Please make an issue on https://issues.dlang.org and I'll take a look a this later. Most of the functions in std.conv are templated so it must be some internal function that's not properly annotated, or it's using manual memory

Checking that a template parameter is an enum

2015-09-30 Thread Nordlöw via Digitalmars-d-learn
How do I check that a template parameter is a CT-value or an enum symbol? I want this to restrict the following template: /** Returns: true iff all values $(D V) are the same. */ template allSame(V...) // TODO restrict to values only { static if (V.length <= 1) enum bool

Re: Checking that a template parameter is an enum

2015-10-01 Thread Nordlöw via Digitalmars-d-learn
On Thursday, 1 October 2015 at 02:06:48 UTC, Fusxfaranto wrote: /** Returns: true iff all values $(D V) are the same. */ template allSame(V...) // TODO restrict to values only { static if (V.length <= 1) enum bool allSame = true; else enum bool allSame = V[0] ==

Re: Checking that a template parameter is an enum

2015-10-01 Thread Nordlöw via Digitalmars-d-learn
On Thursday, 1 October 2015 at 02:06:48 UTC, Fusxfaranto wrote: /** Returns: true iff all values $(D V) are the same. */ template allSame(V...) // TODO restrict to values only { static if (V.length <= 1) enum bool allSame = true; else enum bool allSame = V[0] ==

Re: Checking that a template parameter is an enum

2015-10-01 Thread Nordlöw via Digitalmars-d-learn
On Thursday, 1 October 2015 at 22:37:57 UTC, Ali Çehreli wrote: Very quickly: import std.traits; template allSame(V...) if (isExpressions!(V)) { bool impl_(V...)() { static if (V.length > 1) { foreach (i, _; V[0 .. $ - 1]) { if (V[i] != V[i + 1]) {

Re: Cameleon: Stricter Alternative Implementation of VariantN

2015-10-03 Thread Nordlöw via Digitalmars-d-learn
On Monday, 21 September 2015 at 13:42:14 UTC, Nordlöw wrote: The code is here: https://github.com/nordlow/justd/blob/master/cameleon.d Moved to https://github.com/nordlow/justd/blob/master/vary.d Templates are no called: - FastVariant - PackedVariant

Re: Checking that a template parameter is an enum

2015-10-02 Thread Nordlöw via Digitalmars-d-learn
On Friday, 2 October 2015 at 16:21:22 UTC, Meta wrote: Could that memory usage be tested somehow? Your favourite process monitor I guess. Any suggestions on an evil D snippet that stress tests different implementations of the above mentioned traits?

Re: Checking that a template parameter is an enum

2015-10-02 Thread Nordlöw via Digitalmars-d-learn
On Friday, 2 October 2015 at 02:39:56 UTC, Meta wrote: Highly doubtful as CTFE already allocates like there's no tomorrow. Could that memory usage be tested somehow?

Purity of std.conv.to!string

2015-09-26 Thread Nordlöw via Digitalmars-d-learn
Why is the following code not pure: float x = 3.14; import std.conv : to; auto y = x.to!string; ??? Is there a reason for it not being pure? If not, this is a serious problem as this is such a fundamental function.

Re: Deduplicating Template Parameter List of std.variant.Algebraic

2015-09-25 Thread Nordlöw via Digitalmars-d-learn
On Thursday, 24 September 2015 at 20:20:42 UTC, Nordlöw wrote: I just noticed that Algebraic doesn't deduplicate its types before construction because this compiles: import std.variant : Algebraic; auto x = Algebraic!(int, int)(5); Is this really sane? How can a template parameter

Re: Deduplicating Template Parameter List of std.variant.Algebraic

2015-09-25 Thread Nordlöw via Digitalmars-d-learn
On Friday, 25 September 2015 at 18:11:51 UTC, Meta wrote: You can use http://dlang.org/phobos/std_meta.html#.NoDuplicates. I imagine this was an oversight in the implementation of Algebraic. Thanks

Cameleon: Stricter Alternative Implementation of VariantN

2015-09-21 Thread Nordlöw via Digitalmars-d-learn
Because I'm not satisfied with the current state of memory-layout-flexibility/pureness/safeness/nogc/nothrow-ness of `VariantN` I've hacked together a lightweight version of `VariantN`, I currently call `Cameleon`. The code is here: https://github.com/nordlow/justd/blob/master/cameleon.d

Re: Cameleon: Stricter Alternative Implementation of VariantN

2015-09-22 Thread Nordlöw via Digitalmars-d-learn
On Tuesday, 22 September 2015 at 12:54:47 UTC, Kagamin wrote: You can generate a union from allowed types, it will make copies type safe too, sort of set!(staticIndexOf(T, AllowedTypes))(rhs)... hmm... can it be an overload? I believe there is a trait somewhere that figures out the maximum

Deduplicating Template Parameter List of std.variant.Algebraic

2015-09-24 Thread Nordlöw via Digitalmars-d-learn
I just noticed that Algebraic doesn't deduplicate its types before construction because this compiles: import std.variant : Algebraic; auto x = Algebraic!(int, int)(5); Is this really sane?

Re: Container Purity

2015-12-09 Thread Nordlöw via Digitalmars-d-learn
On Wednesday, 9 December 2015 at 10:47:18 UTC, Nordlöw wrote: that uses std.experimental.container Correction: I mean std.experimental.allocator

Container Purity

2015-12-09 Thread Nordlöw via Digitalmars-d-learn
Is it currently possible for a container such as https://github.com/economicmodeling/containers/blob/master/src/containers/dynamicarray.d that uses std.experimental.container to be completely pure? If not can be made to? I wonder because only length(), empty(), front() and back() are tagged

Re: Container Purity

2015-12-09 Thread Nordlöw via Digitalmars-d-learn
On Wednesday, 9 December 2015 at 11:46:45 UTC, Kagamin wrote: Allocators usually use global state. Such code is usually treated as impure. What about containers that store their own local allocator? Will DMD infer all members of such containers to be pure if they only access locally

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 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**) auto ci = o.classinfo; auto init = cast(ubyte)ci.init; p[0..init.length] = init[]; if

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: 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

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: 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:

Dynamic cartesianProduct()

2015-12-11 Thread Nordlöw via Digitalmars-d-learn
Have anybody put together a lazy variant of cartesianProduct() that operates on a range of ranges: Sample call cartesianProductDynamic([["2", "3"], ["green", "red"], ["apples", "pears"]]) should return [["2", "green", "apples"], ["3", "green", "apples"], ["2", "red", "apples"], ["3",

Nothrow front() when not empty()

2016-01-06 Thread Nordlöw via Digitalmars-d-learn
At https://github.com/D-Programming-Language/phobos/pull/3752 it would be nice if return !haystack.empty && haystack.front.unaryFun!pred was made nothrow. Is this possible somehow?

vibe.d-example illustrating Dynamic Textual Web-Interface

2015-11-30 Thread Nordlöw via Digitalmars-d-learn
Can somebody please show a enlightening example of, so called, "revamp of the REST interface generator" added to release 0.7.26 at: http://vibed.org/blog/posts/vibe-release-0.7.26 I want to use vibe.d to add a modern dynamic web-interface to my knowledge graph I'm currently developing.

Re: how convert the range to slice ?

2016-06-09 Thread Nordlöw via Digitalmars-d-learn
On Monday, 2 February 2015 at 21:04:11 UTC, Nordlöw wrote: Made it PR at https://github.com/D-Programming-Language/dmd/pull/4371 Synched with DMD D conversion and improved isInputRange and message at: https://github.com/dlang/dmd/pull/4371

Searching for a T in a T[]

2016-06-22 Thread Nordlöw via Digitalmars-d-learn
Is there now algorithm (similar to `canFind`) that can search for a `T` in a `T[]`? Existing `canFind` only supports sub-sequence needles. I'm aware of `std.string.indexOf` but that's only for strings.

Re: Searching for a T in a T[]

2016-06-22 Thread Nordlöw via Digitalmars-d-learn
On Wednesday, 22 June 2016 at 08:07:51 UTC, David Nadlinger wrote: What about http://dlang.org/phobos/std_algorithm_searching.html#.canFind.canFind.2? My mistake. The reason for the template error message was another than I though of. Thanks.

Re: Variadic function with parameters all of a specific type

2016-06-18 Thread Nordlöw via Digitalmars-d-learn
On Friday, 17 June 2016 at 21:20:01 UTC, Timon Gehr wrote: void foo(T[] a...)@nogc{} void bar()@nogc{ foo(1,2,3); } Ahh, cool. I was completely unaware of this feature. Doc here: https://dlang.org/spec/function.html#typesafe_variadic_functions

Variadic function with parameters all of a specific type

2016-06-17 Thread Nordlöw via Digitalmars-d-learn
I want to create a function that takes a variadic number of arguments all of a specific type, say T, without having to create GC-allocated heap array. Is there a better way than: f(Args...)(Args args) if (allSameType!(Args, T); in terms of template bloat?

Voldemort Type Construction Error

2016-01-15 Thread Nordlöw via Digitalmars-d-learn
I've made progress at the helper findingSplitter at https://github.com/nordlow/justd/blob/master/substitution.d#L122 I need this for implementing a new Phobos lazy `substitute()` (or replace). I've done most logic (AFAICT in my head) but I can't make the call to Result() work as it fails as

Re: Voldemort Type Construction Error

2016-01-15 Thread Nordlöw via Digitalmars-d-learn
On Friday, 15 January 2016 at 16:51:24 UTC, Anon wrote: On Friday, 15 January 2016 at 14:04:50 UTC, Nordlöw wrote: What have I missed? In line 126, `static struct Result()` is a template. Either drop the parens there, or change the call on line 187 to `Result!()(haystack, needles)`. Ahh,

Index a parameter tuple with a run-time index

2016-01-15 Thread Nordlöw via Digitalmars-d-learn
How do I index a function parameter tuple with a run-time index?

Re: Scale-Hierarchy on ndslice

2016-01-14 Thread Nordlöw via Digitalmars-d-learn
On Wednesday, 13 January 2016 at 18:35:29 UTC, Ilya Yaroshenko wrote: Ok, great. BTW: What is Mir? https://github.com/DlangScience/mir --Ilya Nice.

Getting the template name of a template instantiation

2016-06-27 Thread Nordlöw via Digitalmars-d-learn
If I have a template parameter E = S!int where struct S(T) { S x; } how can I extract the template name part `S` from E`? Something like: static assert(is(templateName!(S!int) == S)); Is this already in Phobos somewhere?

Re: Getting the template name of a template instantiation

2016-06-27 Thread Nordlöw via Digitalmars-d-learn
On Monday, 27 June 2016 at 17:17:19 UTC, John wrote: import std.traits; __traits(identifier, TemplateOf!(S!int)); Scratch that, this is what you want: import std.traits; static assert(__traits(isSame, TemplateOf!(S!int), S)); I believe this is what import std.traits : isInstanceOf; is

Assert failure on 2.070.0 without stack trace

2016-01-28 Thread Nordlöw via Digitalmars-d-learn
After upgrading to 2.070.0 I get an assert failure in my application that wasn't there before: core.exception.AssertError@knet/linking.d(235): Assertion failure Why isn't there any stacktrace? I thought has been fixed. Please help.

Re: Assert failure on 2.070.0 without stack trace

2016-01-28 Thread Nordlöw via Digitalmars-d-learn
On Thursday, 28 January 2016 at 18:13:59 UTC, Vladimir Panteleev wrote: You can use Digger to find the exact compiler change that caused this assert to manifest, and Dustmite to find the minimal program which behaves differently in two compiler versions. Thanks, I'm aware of these tools.

Re: Assert failure on 2.070.0 without stack trace

2016-01-28 Thread Nordlöw via Digitalmars-d-learn
On Thursday, 28 January 2016 at 18:13:59 UTC, Vladimir Panteleev wrote: On Thursday, 28 January 2016 at 18:01:09 UTC, Nordlöw wrote: After upgrading to 2.070.0 I get an assert failure in my application that wasn't there before: core.exception.AssertError@knet/linking.d(235): Assertion

Re: std.algorithm.startsWith only predicate

2016-01-27 Thread Nordlöw via Digitalmars-d-learn
On Monday, 19 October 2015 at 19:20:15 UTC, Nordlöw wrote: https://github.com/D-Programming-Language/phobos/pull/3752 Is merged now!

Grouping variadic parameter tuples on offset and stride

2016-01-21 Thread Nordlöw via Digitalmars-d-learn
I'm currently developing a new lazy variadic generic range/algorithm substitute() at https://github.com/nordlow/justd/blob/master/substitution.d#L261 I plan to propose for Phobos. It is meant to be used as assert(`do_it`.substitute(`_`, ` `, `d`, `g`,

Re: Grouping variadic parameter tuples on offset and stride

2016-01-22 Thread Nordlöw via Digitalmars-d-learn
On Thursday, 21 January 2016 at 22:35:09 UTC, H. S. Teoh wrote: Try this: import std.meta; template Stride(size_t stride, size_t offset, Args...) if (stride > 0) { static if (offset >= Args.length) alias Stride = AliasSeq!();

Lazy Range of Graph Links

2016-02-16 Thread Nordlöw via Digitalmars-d-learn
In my knowledge hypergraph I currently have a struct Path { Node start; Step[] steps; } struct Step { Fact fact; Node node; } where Node and Fact a reference types (class). I now want to implement auto byLink(Path path); so that it returns a lazy range of Links where struct

Re: Lazy Range of Graph Links

2016-02-16 Thread Nordlöw via Digitalmars-d-learn
On Tuesday, 16 February 2016 at 08:45:42 UTC, Andrea Fontana wrote: Something like this: http://dpaste.dzfl.pl/de73cb4e7ac0 ? Thanks. Note that this can be simplified by using a variadic version of zip...

Decoding Pattern to a Tuple

2016-02-19 Thread Nordlöw via Digitalmars-d-learn
Have anybody put together a generalised form of findSplit that can split and decode using a compile time parameters somewhat like "(1)-(2.0)".decode!("(", int, ")", char, "(", double, ")") evaluates to to a tuple!(int, char, double) with value tuple(1, '-', 2.0)

Re: Decoding Pattern to a Tuple

2016-02-22 Thread Nordlöw via Digitalmars-d-learn
On Friday, 19 February 2016 at 22:16:10 UTC, Ali Çehreli wrote: On 02/19/2016 11:04 AM, Ali Çehreli wrote: > can be templatized: Not ready for prime time but now it's templatized: Thanks!

Re: Memory Efficient HashSet

2016-03-09 Thread Nordlöw via Digitalmars-d-learn
On Tuesday, 8 March 2016 at 12:25:36 UTC, Ola Fosheim Grøstad wrote: On Tuesday, 8 March 2016 at 08:12:04 UTC, Nordlöw wrote: sparse_hash_set<> contained in https://github.com/sparsehash/sparsehash It appears to be very slow? What do you need it for? My knowledge database engine I'm

Re: Memory Efficient HashSet

2016-03-10 Thread Nordlöw via Digitalmars-d-learn
On Wednesday, 9 March 2016 at 22:31:50 UTC, Nordlöw wrote: The consumption with Google's sparsehash unordered_set is about 50 MiB. See also: http://smerity.com/articles/2015/google_sparsehash.html

Re: Memory Efficient HashSet

2016-03-10 Thread Nordlöw via Digitalmars-d-learn
On Thursday, 10 March 2016 at 10:15:10 UTC, Martin Tschierschke wrote: With how many data sets at the end, you will have to deal? I need something close to the memory overhead of a sorted array of values. That is why I'm considering converting SparseHash's sparse_hash_set to D.

Re: Continuous integral range predicate

2016-03-31 Thread Nordlöw via Digitalmars-d-learn
On Thursday, 31 March 2016 at 11:41:17 UTC, Rene Zwanenburg wrote: std.algorithm.findAdjacent!((a, b) => a != b+1)(range).empty; Correction: Should be: std.algorithm.findAdjacent!((a, b) => a+1 != b)(range).empty; Thanks!

Re: Fiber and Thread Communication

2016-04-08 Thread Nordlöw via Digitalmars-d-learn
On Friday, 8 April 2016 at 11:01:21 UTC, Dicebot wrote: Doesn't std.concurrency support both right now? I remember seeing PR that adds message box support to fibers ages ago. What progress has been since post: http://forum.dlang.org/post/k4jsef$26h6$1...@digitalmars.com

Fiber and Thread Communication

2016-04-08 Thread Nordlöw via Digitalmars-d-learn
Are there any plans to unite fiber-to-fiber communication with thread-to-thread communication in Phobos? Does vibe.d give any solutions here?

Re: Fiber and Thread Communication

2016-04-08 Thread Nordlöw via Digitalmars-d-learn
On Friday, 8 April 2016 at 11:01:21 UTC, Dicebot wrote: Doesn't std.concurrency support both right now? I remember seeing PR that adds message box support to fibers ages ago. 1. What functions provide message box communication? 2. But Fibers cannot currently be moved between threads right?

  1   2   3   4   5   6   7   8   9   >