digitalmars.D.learn - Hash-Table-Based Multiple Arguments Replacement
- =?UTF-8?B?Tm9yZGzDtnc=?= (24/24) Oct 10 2015 Is there an algorithm somewhere in Phobos which performs when
- =?UTF-8?B?Tm9yZGzDtnc=?= (5/8) Oct 10 2015 Found it:
- =?UTF-8?B?Tm9yZGzDtnc=?= (6/10) Oct 10 2015 Ahh, but this doesn't use a hash-table because it doesn't support
- Meta (4/28) Oct 10 2015 There was something like this proposed quite awhile ago (can't
- =?UTF-8?B?Tm9yZGzDtnc=?= (3/6) Oct 10 2015 With static foreach in a switch we can do better. I'll put
- =?UTF-8?B?Tm9yZGzDtnc=?= (3/9) Oct 11 2015 Here's a solution:
- Per =?UTF-8?B?Tm9yZGzDtnc=?= (3/5) Oct 13 2015 Latest version contains a few fixes:
- ixid (3/27) Oct 12 2015 It would also be nice to have a splitter that can split on any of
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"; default: return x; } } ? Desired interface y = x.replaceWhole!("a","x", "b","y", "c","z") or perhaps y = x.replaceWhole!(tuple("a","x"), tuple("b","y"), tuple("c","z")) kind of like "a".among!("a", "b", "c") but for replacements.
Oct 10 2015
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 toFound 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.
Oct 10 2015
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 because it doesn't support taking its arguments as CT-params...so that doesn't qualify. Maybe we should add a new CT-param-only overload for `predSwitch` similar to `among`? Destroy!
Oct 10 2015
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 string replaceWhole(string a) { switch (x) { case "a": return "1"; case "b": return "2"; default: return x; } } ? Desired interface y = x.replaceWhole!("a","x", "b","y", "c","z") or perhaps y = x.replaceWhole!(tuple("a","x"), tuple("b","y"), tuple("c","z")) kind of like "a".among!("a", "b", "c") but for replacements.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.
Oct 10 2015
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 solution.
Oct 10 2015
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:Here's a solution: https://github.com/nordlow/justd/blob/f8519e8a1af68bc25cc00c6ef12d13efa791250c/comparison_ex.dThere 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 solution.
Oct 11 2015
On Sunday, 11 October 2015 at 11:17:29 UTC, Nordlöw wrote:Here's a solution: https://github.com/nordlow/justd/blob/f8519e8a1af68bc25cc00c6ef12d13efa791250c/comparison_ex.dLatest version contains a few fixes: https://github.com/nordlow/justd/blob/master/comparison_ex.d
Oct 13 2015
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 string replaceWhole(string a) { switch (x) { case "a": return "1"; case "b": return "2"; default: return x; } } ? Desired interface y = x.replaceWhole!("a","x", "b","y", "c","z") or perhaps y = x.replaceWhole!(tuple("a","x"), tuple("b","y"), tuple("c","z")) kind of like "a".among!("a", "b", "c") but for replacements.It would also be nice to have a splitter that can split on any of a number of conditions being fulfilled in a similar vein.
Oct 12 2015