Re: to compose or hack?

2021-07-06 Thread Jon Degenhardt via Digitalmars-d-learn
On Wednesday, 7 July 2021 at 01:44:20 UTC, Steven Schveighoffer wrote: This is pretty minimal, but does what I want it to do. Is it ready for inclusion in Phobos? Not by a longshot! A truly generic interleave would properly forward everything else that the range supports (like `length`,

Re: Need for speed

2021-04-01 Thread Jon Degenhardt via Digitalmars-d-learn
On Thursday, 1 April 2021 at 19:55:05 UTC, H. S. Teoh wrote: On Thu, Apr 01, 2021 at 07:25:53PM +, matheus via Digitalmars-d-learn wrote: [...] Since this is a "Learn" part of the Foruam, be careful with "-boundscheck=off". I mean for this little snippet is OK, but for a other projects

Re: Trying to reduce memory usage

2021-02-22 Thread Jon Degenhardt via Digitalmars-d-learn
On Tuesday, 23 February 2021 at 00:08:40 UTC, tsbockman wrote: On Friday, 19 February 2021 at 00:13:19 UTC, Jon Degenhardt wrote: It would be interesting to see how the performance compares to tsv-uniq (https://github.com/eBay/tsv-utils/tree/master/tsv-uniq). The prebuilt binaries turn on all

Re: Trying to reduce memory usage

2021-02-18 Thread Jon Degenhardt via Digitalmars-d-learn
On Wednesday, 17 February 2021 at 04:10:24 UTC, tsbockman wrote: I spent some time experimenting with this problem, and here is the best solution I found, assuming that perfect de-duplication is required. (I'll put the code up on GitHub / dub if anyone wants to have a look.) It would be

Re: std.algorithm.splitter on a string not always bidirectional

2021-01-22 Thread Jon Degenhardt via Digitalmars-d-learn
On Friday, 22 January 2021 at 17:29:08 UTC, Steven Schveighoffer wrote: On 1/22/21 11:57 AM, Jon Degenhardt wrote: I think the idea is that if a construct like 'xyz.splitter(args)' produces a range with the sequence of elements {"a", "bc", "def"}, then 'xyz.splitter(args).back' should

Re: std.algorithm.splitter on a string not always bidirectional

2021-01-22 Thread Jon Degenhardt via Digitalmars-d-learn
On Friday, 22 January 2021 at 14:14:50 UTC, Steven Schveighoffer wrote: On 1/22/21 12:55 AM, Jon Degenhardt wrote: On Friday, 22 January 2021 at 05:51:38 UTC, Jon Degenhardt wrote: On Thursday, 21 January 2021 at 22:43:37 UTC, Steven Schveighoffer wrote: auto sp1 = "a|b|c".splitter('|');

Re: std.algorithm.splitter on a string not always bidirectional

2021-01-21 Thread Jon Degenhardt via Digitalmars-d-learn
On Friday, 22 January 2021 at 05:51:38 UTC, Jon Degenhardt wrote: On Thursday, 21 January 2021 at 22:43:37 UTC, Steven Schveighoffer wrote: auto sp1 = "a|b|c".splitter('|'); writeln(sp1.back); // ok auto sp2 = "a.b|c".splitter!(v => !isAlphaNum(v)); writeln(sp2.back); // error, not

Re: std.algorithm.splitter on a string not always bidirectional

2021-01-21 Thread Jon Degenhardt via Digitalmars-d-learn
On Thursday, 21 January 2021 at 22:43:37 UTC, Steven Schveighoffer wrote: auto sp1 = "a|b|c".splitter('|'); writeln(sp1.back); // ok auto sp2 = "a.b|c".splitter!(v => !isAlphaNum(v)); writeln(sp2.back); // error, not bidirectional Why? is it an oversight, or is there a good reason for it?

Re: Why is BOM required to use unicode in tokens?

2020-09-15 Thread Jon Degenhardt via Digitalmars-d-learn
On Tuesday, 15 September 2020 at 14:59:03 UTC, Steven Schveighoffer wrote: On 9/15/20 10:18 AM, James Blachly wrote: What will it take (i.e. order of difficulty) to get this fixed -- will merely a bug report (and PR, not sure if I can tackle or not) do it, or will this require more in-depth

Re: Why is BOM required to use unicode in tokens?

2020-09-15 Thread Jon Degenhardt via Digitalmars-d-learn
On Tuesday, 15 September 2020 at 02:23:31 UTC, Paul Backus wrote: On Tuesday, 15 September 2020 at 01:49:13 UTC, James Blachly wrote: I wish to write a function including ∂x and ∂y (these are trivial to type with appropriate keyboard shortcuts - alt+d on Mac), but without a unicode byte order

Re: Install multiple executables with DUB

2020-09-04 Thread Jon Degenhardt via Digitalmars-d-learn
On Friday, 4 September 2020 at 07:27:33 UTC, glis-glis wrote: On Thursday, 3 September 2020 at 14:34:48 UTC, Jacob Carlborg wrote: Oh, multiple binaries, I missed that. You can try to add multiple configurations [1]. Or if you have executables depending on only one source file, you can use

Re: How to get the element type of an array?

2020-08-25 Thread Jon Degenhardt via Digitalmars-d-learn
On Tuesday, 25 August 2020 at 15:02:14 UTC, FreeSlave wrote: On Tuesday, 25 August 2020 at 03:41:06 UTC, Jon Degenhardt wrote: What's the best way to get the element type of an array at compile time? Something like std.range.ElementType except that works on any array type. There is

Re: How to get the element type of an array?

2020-08-25 Thread Jon Degenhardt via Digitalmars-d-learn
On Tuesday, 25 August 2020 at 12:50:35 UTC, Steven Schveighoffer wrote: The situation is still confusing though. If only 'std.range.ElementType' is imported, a static array does not have a 'front' member, but ElementType still gets the correct type. (This is where the documentation says it'll

Re: How to get the element type of an array?

2020-08-25 Thread Jon Degenhardt via Digitalmars-d-learn
On Tuesday, 25 August 2020 at 05:02:46 UTC, Basile B. wrote: On Tuesday, 25 August 2020 at 03:41:06 UTC, Jon Degenhardt wrote: What's the best way to get the element type of an array at compile time? Something like std.range.ElementType except that works on any array type. There is

Re: How to get the element type of an array?

2020-08-24 Thread Jon Degenhardt via Digitalmars-d-learn
On Tuesday, 25 August 2020 at 04:36:56 UTC, H. S. Teoh wrote: [...] Harry Gillanders, H.S. Teoh, Thank you both for the quick replies. Both methods address my needs. Very much appreciated, I was having trouble figuring this one out. --Jon

How to get the element type of an array?

2020-08-24 Thread Jon Degenhardt via Digitalmars-d-learn
What's the best way to get the element type of an array at compile time? Something like std.range.ElementType except that works on any array type. There is std.traits.ForeachType, but it wasn't clear if that was the right thing. --Jon

Re: getopt Basic usage

2020-08-15 Thread Jon Degenhardt via Digitalmars-d-learn
On Saturday, 15 August 2020 at 04:09:19 UTC, James Gray wrote: I am trying to use getopt and would not like the program to throw an unhandled exception when parsing command line options. Is the following, adapted from the first example in the getopt documentation, a reasonable approach? I

Re: Reading from stdin significantly slower than reading file directly?

2020-08-13 Thread Jon Degenhardt via Digitalmars-d-learn
On Thursday, 13 August 2020 at 14:41:02 UTC, Steven Schveighoffer wrote: But for sure, reading from stdin doesn't do anything different than reading from a file if you are using the File struct. A more appropriate test might be using the shell to feed the file into the D program: dprogram <

Re: Reading from stdin significantly slower than reading file directly?

2020-08-13 Thread Jon Degenhardt via Digitalmars-d-learn
On Wednesday, 12 August 2020 at 22:44:44 UTC, methonash wrote: Hi, Relative beginner to D-lang here, and I'm very confused by the apparent performance disparity I've noticed between programs that do the following: 1) cat some-large-file | D-program-reading-stdin-byLine() 2)

Re: getopt: How does arraySep work?

2020-07-16 Thread Jon Degenhardt via Digitalmars-d-learn
On Thursday, 16 July 2020 at 17:40:25 UTC, Steven Schveighoffer wrote: On 7/16/20 1:13 PM, Andre Pany wrote: On Thursday, 16 July 2020 at 05:03:36 UTC, Jon Degenhardt wrote: On Wednesday, 15 July 2020 at 07:12:35 UTC, Andre Pany wrote: [...] An enhancement is likely to hit some corner-cases

Re: getopt: How does arraySep work?

2020-07-15 Thread Jon Degenhardt via Digitalmars-d-learn
On Wednesday, 15 July 2020 at 07:12:35 UTC, Andre Pany wrote: On Tuesday, 14 July 2020 at 15:48:59 UTC, Andre Pany wrote: On Tuesday, 14 July 2020 at 14:33:47 UTC, Steven Schveighoffer wrote: On 7/14/20 10:22 AM, Steven Schveighoffer wrote: The documentation needs updating, it should say

Re: Looking for a Code Review of a Bioinformatics POC

2020-06-12 Thread Jon Degenhardt via Digitalmars-d-learn
On Friday, 12 June 2020 at 06:20:59 UTC, H. S. Teoh wrote: I glanced over the implementation of byLine. It appears to be the unhappy compromise of trying to be 100% correct, cover all possible UTF encodings, and all possible types of input streams (on-disk file vs. interactive console). It

Re: Looking for a Code Review of a Bioinformatics POC

2020-06-11 Thread Jon Degenhardt via Digitalmars-d-learn
On Friday, 12 June 2020 at 00:58:34 UTC, duck_tape wrote: On Thursday, 11 June 2020 at 23:45:31 UTC, H. S. Teoh wrote: Hmm, looks like it's not so much input that's slow, but *output*. In fact, it looks pretty bad, taking almost as much time as overlap() does in total! [snip...] I'll

Re: Idiomatic way to write a range that tracks how much it consumes

2020-04-27 Thread Jon Degenhardt via Digitalmars-d-learn
On Monday, 27 April 2020 at 05:06:21 UTC, anon wrote: To implement your option A you could simply use std.range.enumerate. Would something like this work? import std.algorithm.iteration : map; import std.algorithm.searching : until; import std.range : tee; size_t bytesConsumed; auto result =

Re: Idiomatic way to write a range that tracks how much it consumes

2020-04-26 Thread Jon Degenhardt via Digitalmars-d-learn
On Monday, 27 April 2020 at 04:51:54 UTC, Steven Schveighoffer wrote: On 4/26/20 11:38 PM, Jon Degenhardt wrote: Is there a better way to write this? I had exactly the same problems. I created this to solve the problem, I've barely tested it, but I plan to use it with all my parsing

Re: Idiomatic way to write a range that tracks how much it consumes

2020-04-26 Thread Jon Degenhardt via Digitalmars-d-learn
On Monday, 27 April 2020 at 04:41:58 UTC, drug wrote: 27.04.2020 06:38, Jon Degenhardt пишет: Is there a better way to write this? --Jon I don't know a better way, I think you enlist all possible ways - get a value using either `front` or special range member. I prefer the second variant,

Idiomatic way to write a range that tracks how much it consumes

2020-04-26 Thread Jon Degenhardt via Digitalmars-d-learn
I have a string that contains a sequence of elements, then a terminator character, followed by a different sequence of elements (of a different type). I want to create an input range that traverses the initial sequence. This is easy enough. But after the initial sequence has been traversed,

Re: Integration tests

2020-04-17 Thread Jon Degenhardt via Digitalmars-d-learn
On Friday, 17 April 2020 at 16:56:57 UTC, Russel Winder wrote: Hi, Thinking of trying to do the next project in D rather than Rust, but… Rust has built in unit testing on a module basis. D has this so no problem. Rust allows for integration tests in the tests directory of a project.

Re: How to correctly import tsv-utilites functions?

2020-04-15 Thread Jon Degenhardt via Digitalmars-d-learn
On Tuesday, 14 April 2020 at 20:25:08 UTC, p.shkadzko wrote: On Tuesday, 14 April 2020 at 20:05:28 UTC, Steven Schveighoffer wrote: On 4/14/20 3:34 PM, p.shkadzko wrote: [...] What about using dependency tsv-utils:common ? Looks like tsv-utils is a collection of subpackages, and the main

Re: Unexpected result with std.conv.to

2019-11-14 Thread Jon Degenhardt via Digitalmars-d-learn
On Friday, 15 November 2019 at 03:51:04 UTC, Joel wrote: I made a feature that converts, say, [9:59am] -> [10:00am] to 1 minute. but found '9'.to!int = 57 (not 9). Doesn't seem right... I'm guessing that's standard though, same with ldc. Use a string or char[] array. e.g.

Re: csvReader & specifying separator problems...

2019-11-14 Thread Jon Degenhardt via Digitalmars-d-learn
On Thursday, 14 November 2019 at 12:25:30 UTC, Robert M. Münch wrote: Just trying a very simple thing and it's pretty hard: "Read a CSV file (raw_data) that has a ; separator so that I can iterate over the lines and access the fields." csv_data = raw_data.byLine.joiner("\n") From the

Re: formatting a float or double in a string with all significant digits kept

2019-10-10 Thread Jon Degenhardt via Digitalmars-d-learn
On Thursday, 10 October 2019 at 17:12:25 UTC, dan wrote: Thanks also berni44 for the information about the dig attribute, Jon for the neat packaging into one line using the attribute on the type. Unfortunately, the version of gdc that comes with the version of debian that i am using does not

Re: formatting a float or double in a string with all significant digits kept

2019-10-09 Thread Jon Degenhardt via Digitalmars-d-learn
On Wednesday, 9 October 2019 at 05:46:12 UTC, berni44 wrote: On Tuesday, 8 October 2019 at 20:37:03 UTC, dan wrote: But i would like to be able to do this without knowing the expansion of pi, or writing too much code, especially if there's some d function like writeAllDigits or something

Re: Help me decide D or C

2019-08-02 Thread Jon Degenhardt via Digitalmars-d-learn
On Wednesday, 31 July 2019 at 18:38:02 UTC, Alexandre wrote: Should I go for C and then when I become a better programmer change to D? Should I start with D right now? In my view, the most important thing is the decision you've already made - to pick a programming language and learn it in a

Re: rdmd takes 2-3 seconds on a first-run of a simple .d script

2019-05-26 Thread Jon Degenhardt via Digitalmars-d-learn
On Saturday, 25 May 2019 at 22:18:16 UTC, Andre Pany wrote: On Saturday, 25 May 2019 at 08:32:08 UTC, BoQsc wrote: I have a simple standard .d script and I'm getting annoyed that it takes 2-3 seconds to run and see the results via rdmd. Also please keep in mind there could be other factors

Re: Poor regex performance?

2019-04-04 Thread Jon Degenhardt via Digitalmars-d-learn
On Thursday, 4 April 2019 at 10:31:43 UTC, Julian wrote: On Thursday, 4 April 2019 at 09:57:26 UTC, rikki cattermole wrote: If you need performance use ldc not dmd (assumed). LLVM has many factors better code optimizes than dmd does. Thanks! I already had dmd installed from a brief look at D

Dub: A json/sdl equivalent to --combined command line option?

2019-04-01 Thread Jon Degenhardt via Digitalmars-d-learn
In Dub, is there a way to specify the equivalent of the --combined command line argument in the json/sdl package config file? What I'd like to be able to do is create a custom build type such that $ dub build --build=build-xyz builds in combined mode, without needing to add the

Re: Which Docker to use?

2018-11-11 Thread Jon Degenhardt via Digitalmars-d-learn
On Monday, 22 October 2018 at 18:44:01 UTC, Jacob Carlborg wrote: On 2018-10-21 20:45, Jon Degenhardt wrote: The issue that caused me to go to Ubuntu 16.04 had to do with uncaught exceptions when using LTO with the gold linker and LDC 1.5. Problem occurred with 14.04, but not 16.04. I should

Re: d word counting approach performs well but has higher mem usage

2018-11-04 Thread Jon Degenhardt via Digitalmars-d-learn
On Saturday, 3 November 2018 at 14:26:02 UTC, dwdv wrote: Hi there, the task is simple: count word occurrences from stdin (around 150mb in this case) and print sorted results to stdout in a somewhat idiomatic fashion. Now, d is quite elegant while maintaining high performance compared to

Re: Which Docker to use?

2018-10-21 Thread Jon Degenhardt via Digitalmars-d-learn
On Sunday, 21 October 2018 at 18:11:37 UTC, Jacob Carlborg wrote: On 2018-10-18 01:15, Jon Degenhardt wrote: I need to use docker to build static linked Linux executables. My reason is specific, may be different than the OP's. I'm using Travis-CI to build executables. Travis-CI uses Ubuntu

Re: Which Docker to use?

2018-10-20 Thread Jon Degenhardt via Digitalmars-d-learn
On Friday, 19 October 2018 at 22:16:04 UTC, Ky-Anh Huynh wrote: On Wednesday, 17 October 2018 at 23:15:53 UTC, Jon Degenhardt wrote: I need to use docker to build static linked Linux executables. My reason is specific, may be different than the OP's. I'm using Travis-CI to build executables.

Re: Which Docker to use?

2018-10-17 Thread Jon Degenhardt via Digitalmars-d-learn
On Wednesday, 17 October 2018 at 08:08:44 UTC, Gary Willoughby wrote: On Wednesday, 17 October 2018 at 03:37:21 UTC, Ky-Anh Huynh wrote: Hi, I need to build some static binaries with LDC. I also need to execute builds on both platform 32-bit and 64-bit. From Docker Hub there are two image

Re: Error: variable 'xyz' has scoped destruction, cannot build closure

2018-10-05 Thread Jon Degenhardt via Digitalmars-d-learn
On Friday, 5 October 2018 at 16:34:32 UTC, Paul Backus wrote: On Friday, 5 October 2018 at 06:56:49 UTC, Nicholas Wilson wrote: On Friday, 5 October 2018 at 06:44:08 UTC, Nicholas Wilson wrote: Alas is does not because each does not accept additional argument other than the range. Shouldn't be

Re: Error: variable 'xyz' has scoped destruction, cannot build closure

2018-10-05 Thread Jon Degenhardt via Digitalmars-d-learn
On Friday, 5 October 2018 at 06:44:08 UTC, Nicholas Wilson wrote: On Friday, 5 October 2018 at 06:22:57 UTC, Nicholas Wilson wrote: tenRandomNumbers.each!((n,o) => o.appendln(n.to!string))(output); or tenRandomNumbers.each!((n, ref o) => o.appendln(n.to!string))(output); should hopefully

Error: variable 'xyz' has scoped destruction, cannot build closure

2018-10-04 Thread Jon Degenhardt via Digitalmars-d-learn
I got the compilation error in the subject line when trying to create a range via std.range.generate. Turns out this was caused by trying to create a closure for 'generate' where the closure was accessing a struct containing a destructor. The fix was easy enough: write out the loop by hand

Re: tupleof function parameters?

2018-08-28 Thread Jon Degenhardt via Digitalmars-d-learn
On Tuesday, 28 August 2018 at 06:20:37 UTC, Sebastiaan Koppe wrote: On Tuesday, 28 August 2018 at 06:11:35 UTC, Jon Degenhardt wrote: The goal is to write the argument list once and use it to create both the function and the Tuple alias. That way I could create a large number of these function

tupleof function parameters?

2018-08-28 Thread Jon Degenhardt via Digitalmars-d-learn
I'd like to create a Tuple alias representing a function's parameter list. Is there a way to do this? Here's an example creating a Tuple alias for a function's parameters by hand: import std.typecons: Tuple; bool fn(string op, int v1, int v2) { switch (op) {

Re: Splitting up large dirty file

2018-05-21 Thread Jon Degenhardt via Digitalmars-d-learn
On Monday, 21 May 2018 at 15:00:09 UTC, Dennis wrote: I want to be convinced that Range programming works like a charm, but the procedural approaches remain more flexible (and faster too) it seems. Thanks for the example. On Monday, 21 May 2018 at 22:11:42 UTC, Dennis wrote: In this case I

Re: Splitting up large dirty file

2018-05-17 Thread Jon Degenhardt via Digitalmars-d-learn
On Thursday, 17 May 2018 at 20:08:09 UTC, Dennis wrote: On Wednesday, 16 May 2018 at 15:47:29 UTC, Jon Degenhardt wrote: If you write it in the style of my earlier example and use counters and if-tests it will work. byLine by itself won't try to interpret the characters (won't auto-decode

Re: Splitting up large dirty file

2018-05-16 Thread Jon Degenhardt via Digitalmars-d-learn
On Wednesday, 16 May 2018 at 07:06:45 UTC, Dennis wrote: On Wednesday, 16 May 2018 at 02:47:50 UTC, Jon Degenhardt wrote: Can you show the program you are using that throws when using byLine? Here's a version that only outputs the first chunk: ``` import std.stdio; import std.range; import

Re: Splitting up large dirty file

2018-05-15 Thread Jon Degenhardt via Digitalmars-d-learn
On Tuesday, 15 May 2018 at 20:36:21 UTC, Dennis wrote: I have a file with two problems: - It's too big to fit in memory (apparently, I thought 1.5 Gb would fit but I get an out of memory error when using std.file.read) - It is dirty (contains invalid Unicode characters, null bytes in the

Re: What's the proper way to use std.getopt?

2017-12-12 Thread Jon Degenhardt via Digitalmars-d-learn
On Monday, 11 December 2017 at 20:58:25 UTC, Jordi Gutiérrez Hermoso wrote: What's the proper style, then? Can someone show me a good example of how to use getopt and the docstring it automatically generates? The command line tools I published use the approach described in a number of the

Re: splitter string/char different behavior

2017-09-30 Thread Jon Degenhardt via Digitalmars-d-learn
On Saturday, 30 September 2017 at 17:17:17 UTC, SrMordred wrote: writeln( "a.b.c".splitter('.').dropBack(1) ); //compiles ok writeln( "a.b.c".splitter(".").dropBack(1) ); //error: Error: template std.range.dropBack cannot deduce function from argument types !()(Result, int), candidates are:

Re: splitter string/char different behavior

2017-09-30 Thread Jon Degenhardt via Digitalmars-d-learn
On Saturday, 30 September 2017 at 19:26:14 UTC, SrMordred wrote: For "a.b.c"splitter(x), Range r is a string, r.front is a char. The template can only be instantiated if the predicate function is valid. The predicate function is "a == b". Since r.front is a char, then s must be a type that can

Re: splitter string/char different behavior

2017-09-30 Thread Jon Degenhardt via Digitalmars-d-learn
On Saturday, 30 September 2017 at 17:17:17 UTC, SrMordred wrote: writeln( "a.b.c".splitter('.').dropBack(1) ); //compiles ok writeln( "a.b.c".splitter(".").dropBack(1) ); //error: Error: template std.range.dropBack cannot deduce function from argument types !()(Result, int), candidates are:

Re: Region-based memory management and GC?

2017-09-30 Thread Jon Degenhardt via Digitalmars-d-learn
On Saturday, 30 September 2017 at 07:41:21 UTC, Igor wrote: On Friday, 29 September 2017 at 22:13:01 UTC, Jon Degenhardt wrote: Have there been any investigations into using region-based memory management (aka memory arenas) in D, possibly in conjunction with GC allocated memory? Sounds like

Region-based memory management and GC?

2017-09-29 Thread Jon Degenhardt via Digitalmars-d-learn
Have there been any investigations into using region-based memory management (aka memory arenas) in D, possibly in conjunction with GC allocated memory? This would be a very speculative idea, but it'd be interesting to know if there have been looks at this area. My own interest is

Re: DUB and LTO?

2017-09-05 Thread Jon Degenhardt via Digitalmars-d-learn
On Tuesday, 5 September 2017 at 11:36:06 UTC, Sönke Ludwig wrote: Am 24.01.2017 um 17:02 schrieb Las: How do I enable LTO in DUB in a sane way? I could add it to dflags, but I only want it on release builds. You can put a "buildTypes" section in your package recipe and override default

Re: Help Required on Getopt

2017-09-01 Thread Jon Degenhardt via Digitalmars-d-learn
On Friday, 1 September 2017 at 19:04:39 UTC, Daniel Kozak wrote: I have same issue. How this help you? Catching exception does not help. How do I catch exception and still print help message? Your are correct, sorry about that. What my response showed is how to avoid printing the full stack

Re: Help Required on Getopt

2017-09-01 Thread Jon Degenhardt via Digitalmars-d-learn
On Friday, 1 September 2017 at 13:13:39 UTC, Vino.B wrote: Hi All, When i run the below program without any arguments "D1.d -r" it is throwing error, but i need it to show the help menu [snip...] Hi Vino, To get good error message behavior you need to put the construct in a try-catch

Re: General performance tip about possibly using the GC or not

2017-08-28 Thread Jon Degenhardt via Digitalmars-d-learn
On Tuesday, 29 August 2017 at 00:52:11 UTC, Cecil Ward wrote: I am vacillating - considering breaking a lifetime's C habits and letting the D garbage collector make life wonderful by just cleaning up after me and ruining my future C disciple by not deleting stuff myself. The tsv command line

Re: std.range.put vs R.put: Best practices?

2017-08-21 Thread Jon Degenhardt via Digitalmars-d-learn
On Monday, 21 August 2017 at 05:58:01 UTC, Jonathan M Davis wrote: On Monday, August 21, 2017 02:34:23 Mike Parker via Digitalmars-d-learn wrote: On Sunday, 20 August 2017 at 18:08:27 UTC, Jon Degenhardt wrote: > Documentation for std.range.put >

std.range.put vs R.put: Best practices?

2017-08-20 Thread Jon Degenhardt via Digitalmars-d-learn
Documentation for std.range.put (https://dlang.org/phobos/std_range_primitives.html#.put) has the intriguing line: put should not be used "UFCS-style", e.g. r.put(e). Doing this may call R.put directly, by-passing any transformation feature provided by Range.put. put(r, e) is prefered.

Re: Efficiently streaming data to associative array

2017-08-10 Thread Jon Degenhardt via Digitalmars-d-learn
On Wednesday, 9 August 2017 at 13:36:46 UTC, Steven Schveighoffer wrote: On 8/8/17 3:43 PM, Anonymouse wrote: On Tuesday, 8 August 2017 at 16:00:17 UTC, Steven Schveighoffer wrote: I wouldn't use formattedRead, as I think this is going to allocate temporaries for a and b. What would you

Re: Too slow readln

2017-07-16 Thread Jon Degenhardt via Digitalmars-d-learn
On Sunday, 16 July 2017 at 17:03:27 UTC, unDEFER wrote: [snip] How to write in D grep not slower than GNU grep? GNU grep is pretty fast, it's tough to beat it reading one line at a time. That's because it can play a bit of a trick and do the initial match ignoring line boundaries and

Re: Getopt default int init and zero

2017-05-20 Thread Jon Degenhardt via Digitalmars-d-learn
On Friday, 19 May 2017 at 12:09:38 UTC, Suliman wrote: I would like to check if user specified `0` as getopt parameter. But the problem that `int`'s are default in `0`. So if user did not specified nothing `int x` will be zero, and all other code will work as if it's zero. One way to do this

Re: Processing a gzipped csv-file by line-by-line

2017-05-11 Thread Jon Degenhardt via Digitalmars-d-learn
On Wednesday, 10 May 2017 at 22:20:52 UTC, Nordlöw wrote: What's fastest way to on-the-fly-decompress and process a gzipped csv-fil line by line? Is it possible to combine http://dlang.org/phobos/std_zlib.html with some stream variant of File(path).byLineFast ? I was curious what

Re: Command Line Parsing

2017-04-15 Thread Jon Degenhardt via Digitalmars-d-learn
On Wednesday, 12 April 2017 at 09:51:34 UTC, Russel Winder wrote: Are Argon https://github.com/markuslaker/Argon or darg https://github. com/jasonwhite/darg getting traction as the default command line handling system for D or are they just peripheral and everyone just uses std.getopt

Re: length = 0 clears reserve

2017-04-11 Thread Jon Degenhardt via Digitalmars-d-learn
On Tuesday, 11 April 2017 at 20:00:48 UTC, Jethro wrote: On Tuesday, 11 April 2017 at 03:00:29 UTC, Jon Degenhardt wrote: On Tuesday, 11 April 2017 at 01:59:57 UTC, Jonathan M Davis wrote: On Tuesday, April 11, 2017 01:42:32 Jethro via Digitalmars-d-learn wrote: [...] You can't reuse the

Re: length = 0 clears reserve

2017-04-10 Thread Jon Degenhardt via Digitalmars-d-learn
On Tuesday, 11 April 2017 at 01:59:57 UTC, Jonathan M Davis wrote: On Tuesday, April 11, 2017 01:42:32 Jethro via Digitalmars-d-learn wrote: arrays have the ability to reserve but when setting the length to 0, it removes the reserve!! ;/ char[] buf; buf.reserve = 1000; buf.length = 0;

Re: pointer not aligned

2017-04-02 Thread Jon Degenhardt via Digitalmars-d-learn
On Friday, 31 March 2017 at 04:41:10 UTC, Joel wrote: Linking... ld: warning: pointer not aligned at address 0x10017A4C9 (_D30TypeInfo_AxS3std4file8DirEntry6__initZ + 16 from .dub/build/application-debug-posix.osx-x86_64-dmd_2072-EFDCDF4D45F944F7A9B1AEA5C32F81ED/spellit.o) ... and this goes

Re: Output range and writeln style functions

2017-01-23 Thread Jon Degenhardt via Digitalmars-d-learn
On Monday, 23 January 2017 at 22:20:59 UTC, Ali Çehreli wrote: On 01/23/2017 12:48 PM, Jon Degenhardt wrote: [snip] > So, what I'm really wondering is if there is built-in way to get closer to: outputStream.writefln(...); If it's about formatted output then perhaps formattedWrite?

Re: Output range and writeln style functions

2017-01-23 Thread Jon Degenhardt via Digitalmars-d-learn
On Monday, 23 January 2017 at 08:03:14 UTC, Ali Çehreli wrote: On 01/22/2017 01:54 PM, Jon Degenhardt wrote: I've been increasingly using output ranges in my code (the "component programming" model described in several articles on the D site). It works very well, except that it would often be

Output range and writeln style functions

2017-01-22 Thread Jon Degenhardt via Digitalmars-d-learn
I've been increasingly using output ranges in my code (the "component programming" model described in several articles on the D site). It works very well, except that it would often be more convenient to use writeln style functions rather than 'put'. Especially when you start by drafting a

Re: compile-time test against dmd/phobos version number

2017-01-06 Thread Jon Degenhardt via Digitalmars-d-learn
On Saturday, 7 January 2017 at 02:41:54 UTC, ketmar wrote: On Saturday, 7 January 2017 at 02:30:53 UTC, Jon Degenhardt wrote: Is there a way to make a compile time check against the dmd/phobos version number? Functionally, what I'd like to achieve would be equivalent to:

compile-time test against dmd/phobos version number

2017-01-06 Thread Jon Degenhardt via Digitalmars-d-learn
Is there a way to make a compile time check against the dmd/phobos version number? Functionally, what I'd like to achieve would be equivalent to: version(dmdVersion >= 2.070.1) { } else { ... } I think I've seen something like this, probably using

Re: Constructing a variadic template parameter with source in two files

2016-12-22 Thread Jon Degenhardt via Digitalmars-d-learn
On Thursday, 22 December 2016 at 07:33:42 UTC, Ali Çehreli wrote: On 12/21/2016 07:59 PM, Jon Degenhardt wrote: > construct the 'opts' parameter from > definitions stored in two or more files. The reason for doing this is to > create a customization mechanism where-by there are a number of

Constructing a variadic template parameter with source in two files

2016-12-21 Thread Jon Degenhardt via Digitalmars-d-learn
I'd like to find a way to define programming constructs in one file and reference them in a getopt call defined in another file. getopt uses variadic template argument, so the argument list must be known at compile time. The std.getopt.getopt signature: GetoptResult getopt(T...)(ref

Re: [Semi-OT] I don't want to leave this language!

2016-12-07 Thread Jon Degenhardt via Digitalmars-d-learn
On Wednesday, 7 December 2016 at 16:33:03 UTC, bachmeier wrote: On Wednesday, 7 December 2016 at 12:12:56 UTC, Ilya Yaroshenko wrote: R, Matlab, Python, Mathematica, Gauss, and Julia use C libs. --Ilya You can call into those same C libs using D. Only if you want a pure D solution do you

Re: Impressed with Appender - Is there design/implementation description?

2016-12-06 Thread Jon Degenhardt via Digitalmars-d-learn
On Tuesday, 6 December 2016 at 15:29:59 UTC, Jonathan M Davis wrote: On Tuesday, December 06, 2016 13:19:22 Anonymouse via Digitalmars-d-learn wrote: On Tuesday, 6 December 2016 at 10:52:44 UTC, thedeemon wrote: [...] > 2. Up until 4 KB it reallocates when growing, but after 4 KB > the array

Impressed with Appender - Is there design/implementation description?

2016-12-04 Thread Jon Degenhardt via Digitalmars-d-learn
I've been using Appender quite a bit recently, typically when I need append-only arrays with variable and unknown final sizes. I had been prepared to write a custom data structure when I started using it with large amounts of data, but very nicely this has not surfaced as a need. Appender has

Re: passing static arrays to each! with a ref param [Re: Why can't static arrays be sorted?]

2016-10-11 Thread Jon Degenhardt via Digitalmars-d-learn
On Tuesday, 11 October 2016 at 19:46:31 UTC, Jon Degenhardt wrote: On Tuesday, 11 October 2016 at 18:18:41 UTC, ag0aep6g wrote: On 10/11/2016 06:24 AM, Jon Degenhardt wrote: The example I gave uses ref parameters. On the surface it would seem reasonable to that passing a static array by ref

Re: passing static arrays to each! with a ref param [Re: Why can't static arrays be sorted?]

2016-10-11 Thread Jon Degenhardt via Digitalmars-d-learn
On Tuesday, 11 October 2016 at 18:18:41 UTC, ag0aep6g wrote: On 10/11/2016 06:24 AM, Jon Degenhardt wrote: The example I gave uses ref parameters. On the surface it would seem reasonable to that passing a static array by ref would allow it to be modified, without having to slice it first.

passing static arrays to each! with a ref param [Re: Why can't static arrays be sorted?]

2016-10-10 Thread Jon Degenhardt via Digitalmars-d-learn
On Monday, 10 October 2016 at 16:46:55 UTC, Jonathan M Davis wrote: On Monday, October 10, 2016 16:29:41 TheGag96 via Digitalmars-d-learn wrote: On Saturday, 8 October 2016 at 21:14:43 UTC, Jon Degenhardt wrote: > This distinction is a bit on the nuanced side. Is it > behaving as it should? >

Re: Why can't static arrays be sorted?

2016-10-08 Thread Jon Degenhardt via Digitalmars-d-learn
On Thursday, 6 October 2016 at 20:11:17 UTC, ag0aep6g wrote: On 10/06/2016 09:54 PM, TheGag96 wrote: Interestingly enough, I found that using .each() actually compiles without the [] [...] why can the compiler consider it a range here but not .sort()? each is not restricted to ranges. It

Re: Iterate over two arguments at once

2016-09-19 Thread Jon Degenhardt via Digitalmars-d-learn
On Monday, 19 September 2016 at 18:10:22 UTC, bachmeier wrote: Suppose I want to iterate over two arrays at once: foreach(v1, v2; [1.5, 2.5, 3.5], [4.5, 5.5, 6.5]) { ... } I have seen a way to do this but cannot remember what it is and cannot find it. range.lockstep:

Re: Instantiating a class with range template parameter

2016-09-08 Thread Jon Degenhardt via Digitalmars-d-learn
On Thursday, 8 September 2016 at 08:44:54 UTC, Lodovico Giaretta wrote: On Thursday, 8 September 2016 at 08:20:49 UTC, Jon Degenhardt wrote: [snip] I think that auto x = new Derived!(typeof(stdout.lockingTextWriter()))(); // note the parenthesis should work. But usually, you save the

Instantiating a class with range template parameter

2016-09-08 Thread Jon Degenhardt via Digitalmars-d-learn
I've been generalizing output routines by passing an OutputRange as an argument. This gets interesting when the output routine is an virtual function. Virtual functions cannot be templates, so instead the template parameters need to be part of class definition and specified when instantiating

Re: Template constraints for reference/value types?

2016-09-06 Thread Jon Degenhardt via Digitalmars-d-learn
On Wednesday, 7 September 2016 at 00:40:27 UTC, Jonathan M Davis wrote: On Tuesday, September 06, 2016 21:16:05 Jon Degenhardt via Digitalmars-d-learn wrote: On Tuesday, 6 September 2016 at 21:00:53 UTC, Lodovico Giaretta wrote: > On Tuesday, 6 September 2016 at 20:46:54 UTC, Jon Degenha

Re: Template constraints for reference/value types?

2016-09-06 Thread Jon Degenhardt via Digitalmars-d-learn
On Tuesday, 6 September 2016 at 21:00:53 UTC, Lodovico Giaretta wrote: On Tuesday, 6 September 2016 at 20:46:54 UTC, Jon Degenhardt wrote: Is there a way to constrain template arguments to reference or value types? I'd like to do something like: T foo(T)(T x) if (isReferenceType!T) { ...

Template constraints for reference/value types?

2016-09-06 Thread Jon Degenhardt via Digitalmars-d-learn
Is there a way to constrain template arguments to reference or value types? I'd like to do something like: T foo(T)(T x) if (isReferenceType!T) { ... } --Jon

Re: Why D isn't the next "big thing" already

2016-07-31 Thread Jon Degenhardt via Digitalmars-d-learn
On Saturday, 30 July 2016 at 22:52:23 UTC, bachmeier wrote: On Saturday, 30 July 2016 at 12:30:55 UTC, LaTeigne wrote: On Saturday, 30 July 2016 at 12:24:55 UTC, ketmar wrote: On Saturday, 30 July 2016 at 12:18:08 UTC, LaTeigne wrote: it you think that you know the things better than somebody

Re: Is there a way to clear an OutBuffer?

2016-05-25 Thread Jon Degenhardt via Digitalmars-d-learn
On Wednesday, 25 May 2016 at 19:42:43 UTC, Gary Willoughby wrote: On Monday, 23 May 2016 at 03:03:12 UTC, Jon Degenhardt wrote: Currently not possible. Enhancement request perhaps? Looking at the implementation, setting its 'offset' member seems to work. Based on example from documentation:

Re: Is there a way to clear an OutBuffer?

2016-05-22 Thread Jon Degenhardt via Digitalmars-d-learn
On Sunday, 22 May 2016 at 23:01:07 UTC, Ali Çehreli wrote: On 05/22/2016 11:59 AM, Jon Degenhardt wrote: Is there a way to clear an OutBuffer, but without freeing the internally managed buffer? Something similar to std.array.appender.clear method. Intent would be to reuse the OutBuffer, but

Is there a way to clear an OutBuffer?

2016-05-22 Thread Jon Degenhardt via Digitalmars-d-learn
Is there a way to clear an OutBuffer, but without freeing the internally managed buffer? Something similar to std.array.appender.clear method. Intent would be to reuse the OutBuffer, but without reallocating memory for the buffer. --Jon