Re: Return values from auto function

2020-11-07 Thread James Blachly via Digitalmars-d-learn
On 11/6/20 5:51 AM, Andrey Zherikov wrote: I have auto function 'f' that might return either an error (with some text) or a result (with some value). The problem is that the type of the error is not the same as the type of result so compilation fails. ... How can I make the original code

Re: Dub cmdline overrides?

2020-11-07 Thread James Blachly via Digitalmars-d-learn
On 11/7/20 7:58 AM, Arjan wrote: Is there a cmdline switch to DUB to override certain dub.sdl settings for a dependency? Like the addition or override to lib dirs or link-libs? For example once and a while I run into linking issues with symbols not found due to the `soname` being different on

Re: How to use bootstrap with vibe.d.

2020-11-05 Thread James Blachly via Digitalmars-d-learn
On Thursday, 5 November 2020 at 16:22:11 UTC, Alaindevos wrote: This is from the bootstrap documentation. I think you must adapt this to .dt files. Correct. It looks like flask_bootstrap is just a convenience that injects the js and css scripts or script URI for you into master flask

Re: How to use bootstrap with vibe.d.

2020-11-04 Thread James Blachly via Digitalmars-d-learn
On Wednesday, 4 November 2020 at 19:01:16 UTC, Alaindevos wrote: (title). In flask it is "from flask_bootstrap import Bootstrap". But what do you have to do with vibe.d ? I am not sure you really understand what bootstrap is?

Re: Why is vibe.d json serializer/deserializer so complex?

2020-11-01 Thread James Blachly via Digitalmars-d-learn
On 10/31/20 8:28 PM, Jesse Phillips wrote: Well I was putting this together, but didn't want to attempt submission until I felt I would be able to put in the time for the review process https://github.com/JesseKPhillips/DIPs/blob/serialize/attribute/DIPs/1NNN-jkp.md Bravo! An idea whose

Re: Why is vibe.d json serializer/deserializer so complex?

2020-10-31 Thread James Blachly via Digitalmars-d-learn
On 10/30/20 1:56 PM, Steven Schveighoffer wrote: I was looking to report an enhancement request to vibe.data.json (filed here: https://github.com/vibe-d/vibe.d/issues/2490), and I started looking at the serialization code for vibe. It's really really complicated, and I'm just wondering if this

Re: Is there something I'm not getting here?

2020-10-26 Thread James Blachly via Digitalmars-d-learn
On 10/26/20 9:19 PM, Ruby The Roobster wrote: Following code doesn't work(it's not the actual code but it represents it). Is there some rule about function overrides that I don't know about? ... The error I keep getting no matter what says: Error: Multiple Overrides of Same Function. Anybody

Re: Passing pointer to extern(C++) templated function

2020-10-13 Thread James Blachly via Digitalmars-d-learn
On 10/13/20 5:23 AM, Jamie wrote: Building with: g++ -c a.cpp dmd main.d a.o Throws the error: /usr/bin/ld: main.o: in function `_Dmain': main.d:(.text._Dmain[_Dmain]+0x31): undefined reference to `void func3(int*, int*)' /usr/bin/ld: main.d:(.text._Dmain[_Dmain]+0x3e): undefined reference to

Re: question on dub and postgresql

2020-10-05 Thread James Blachly via Digitalmars-d-learn
On 10/5/20 11:42 AM, Alaindevos wrote: Use "rangify" template to get forward range from answer Thanks, this answers the question on programmatic level. Yet I guess something is special with the answer datatype which makes foreach to fail. Instead of thinking of it as "foreach failing,"

Re: Can opDollar support a jagged 2D array?

2020-10-02 Thread James Blachly via Digitalmars-d-learn
On 10/2/20 9:32 AM, Steven Schveighoffer wrote: This seems like an oversight. But it's not impossible. Thank you Steve. Is there any chance that this mechanism will ever be revised? Presumably it would require a DIP. Just curry the information to the receiver. opDollar doesn't have to

Can opDollar support a jagged 2D array?

2020-10-01 Thread James Blachly via Digitalmars-d-learn
Suppose I have a data structure encoding sequence lengths: seq1: 0 1 2 ... N seq2: 0 1 2 3 4 ... M seq3: 0 1 ... P I would like to write opIndex and opDollar to support the notation obj[seq, x .. $] to retrieve sequences. However, given that opDollar is templated on dimension (always 1 in

Re: what's the best way to convert a sysTime to local machine's time (zone)?

2020-09-24 Thread James Blachly via Digitalmars-d-learn
On 9/24/20 6:22 PM, mw wrote: Hi, I'm just wondering what's the best way to convert sysTime to local machine's time (zone)? Is there any library function does this already? https://dlang.org/phobos/std_datetime_systime.html#SysTime (The time in SysTime is kept internally in hnsecs from

Re: DDoc generation

2020-09-18 Thread James Blachly via Digitalmars-d-learn
On 9/18/20 9:35 AM, Russel Winder wrote: On Fri, 2020-09-18 at 09:02 -0400, Steven Schveighoffer via Digitalmars-d- learn wrote: […] it ddoc files, and compile those along with your application. https://dlang.org/spec/ddoc.html#using_ddoc_for_other_documentation Any small project examples

Re: Proper way to exit with specific exit code?

2020-09-17 Thread James Blachly via Digitalmars-d-learn
On 9/17/20 12:46 PM, IGotD- wrote: The only way is to return from main. The thing is that druntime runs initialization before main and then returning from main it runs all the tear down code including cleaning up the GC. This means there is no equivalent of the exit function in the C library.

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

2020-09-15 Thread James Blachly via Digitalmars-d-learn
On 9/15/20 8:24 PM, James Blachly wrote: Again with the self-reply :/ Forgot the reference: https://www.unicode.org/versions/Unicode13.0.0/ch22.pdf

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

2020-09-15 Thread James Blachly via Digitalmars-d-learn
On 9/15/20 8:10 PM, James Blachly wrote: Steve: It sounds as if the spec is correct but the glyph (codepoint?) range is outdated. If this is the case, it would be a worthwhile update. Do you really think it would be rejected out of hand? OK interestingly this code point 0x2202 falls within

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

2020-09-15 Thread James Blachly via Digitalmars-d-learn
On 9/15/20 10:59 AM, Steven Schveighoffer wrote: Thanks to Paul, Jon, Dominikus and H.S. for thoughtful responses. 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 James Blachly via Digitalmars-d-learn
On 9/15/20 4:36 AM, Dominikus Dittes Scherkl wrote: On Tuesday, 15 September 2020 at 06:49:08 UTC, Jon Degenhardt wrote: On Tuesday, 15 September 2020 at 02:23:31 UTC, Paul Backus wrote: Identifiers start with a letter, _, or universal alpha, and are followed by any number of letters, _,

Why is BOM required to use unicode in tokens?

2020-09-14 Thread James Blachly via Digitalmars-d-learn
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 mark at the beginning of the file, the lexer rejects the tokens. It is not apparently easy to insert such marks (AFAICT no common

Re: Call C variadic function from D variadic function

2020-09-13 Thread James Blachly via Digitalmars-d-learn
On 9/13/20 2:35 PM, ag0aep6g wrote: Easy peasy:     import std.meta: Repeat;     Repeat!(kvargs.length, const(char)*) zs;     foreach (i, ref z; zs) z = toStringz(kvargs[i]);     return sam_hdr_add_line(this.h, type.ptr, zs, null); Great, thank you! By the way, `kvargs`

Call C variadic function from D variadic function

2020-09-13 Thread James Blachly via Digitalmars-d-learn
Summary: Can a typesafe D variadic function, or D variadic template pass its parameters to a C variadic function? Background: I maintain a library binding [0] to htslib, a high-performance and very widely used C library for high-throughput sequencing (hts) data files. We use this internally

Re: Vibe-D File Question

2020-09-11 Thread James Blachly via Digitalmars-d-learn
On 9/11/20 7:28 AM, Daniel Kozak wrote: void fun(HTTPServerRequest req, HTTPServerResponse res) nothrow { try { res.headers["Content-Disposition"] = "filename=\"muj.csv\""; res.writeBody("some;csv;data", "text/csv"); } catch (Exception e) {} } Selim, note the Content-Disposition header in

Re: I think Associative Array should throw Exception

2020-09-01 Thread James Blachly via Digitalmars-d-learn
On 9/1/20 2:55 PM, Steven Schveighoffer wrote: On 9/1/20 2:20 PM, Jesse Phillips wrote: Using RangeError is nice as it allows code to use array index inside `nothrow.` This is the big sticking point -- code that is nothrow would no longer be able to use AAs. It makes the idea,

Re: How do I statically build a project using DUB?

2020-08-29 Thread James Blachly via Digitalmars-d-learn
On Saturday, 29 August 2020 at 11:27:28 UTC, Kirill wrote: I need a stand-alone executable that does not require the user to install any libraries on their computer. Everything should be packed into the executable. I understand that I need to statically link all of the libraries I use in my

Re: Vibe.d timer - change callback?

2020-08-27 Thread James Blachly via Digitalmars-d-learn
On Tuesday, 25 August 2020 at 18:42:53 UTC, codic wrote: I'd like to be able to change the callback of a vibe.d Timer (eg created with http://vibe-core.dpldocs.info/v1.9.3/vibe.core.core.createTimer.html) after creation, something like: auto timer = createTimer(); timer.rearm(duration,

in; scope; scope ref; DIP1000; documentation

2020-08-27 Thread James Blachly via Digitalmars-d-learn
Peeling off from Mathias Lang's thread in General about making 'in' useful, for some novice questions: 1. The thread involves 'in' qualifier. Documentation (https://dlang.org/spec/function.html#param-storage) indicates that `in` is defined as `scope const` and should not be used as it is

Re: Master Thesis using D Programming language.

2020-08-24 Thread James Blachly via Digitalmars-d-learn
On Monday, 24 August 2020 at 19:56:49 UTC, Tariq Siddiqui wrote: Hello everyone, I am looking for a master thesis topic using D Programming language. Earlier I choose Design by Introspection, but I did not find enough material in academic journals. DbI total material which I found is DConf

Re: How to sort a multidimensional ndslice?

2020-08-18 Thread James Blachly via Digitalmars-d-learn
On Tuesday, 18 August 2020 at 13:07:56 UTC, Arredondo wrote: On Tuesday, 18 August 2020 at 04:07:56 UTC, 9il wrote: To reorder the columns data according to precomputed index: auto index = a.byDim!1.map!sum.slice; Hello Ilya, thanks for the answer! Unfortunately I can't use it because I

Re: vibe.d and my first web service

2020-08-12 Thread James Blachly via Digitalmars-d-learn
On 7/18/20 8:16 AM, Andre Pany wrote: On Saturday, 18 July 2020 at 09:10:04 UTC, Mr. Backup wrote: >> ... I started the program with "dub" command and everything worked as I expected. Except that there were a lot "deprecation" warnings and long time to compile.But when I exit the service by

Re: generating random numbers

2020-08-10 Thread James Blachly via Digitalmars-d-learn
On 8/10/20 1:51 AM, Andy Balba wrote: generating random numbers using https://dlang.org/library/std/random/uniform01.html I find the example given in this section totally incomprehensible .. Can any help me answer two simple questions: How to generate a random floating number in range [0,1) ?

Re: Get symbols (and/or UDAs) of subclass from superclass

2020-03-16 Thread James Blachly via Digitalmars-d-learn
On 3/15/20 5:28 PM, Simen Kjærås wrote: ... Since toStringImpl will always call toStringBase, this could perhaps better be modeled with a template mixin: mixin template DerivedToString() {     override string toStringImpl() {     return this.toStringBase();     } } class Derived2 :

Get symbols (and/or UDAs) of subclass from superclass

2020-03-15 Thread James Blachly via Digitalmars-d-learn
I would like to programmatically retrieve members of a subclass to create a self-documenting interface. I am afraid that my approach is not possible due to need for compile time __traits / std.traits, and runtime typeinfo. My proposed approach is as follows: class Base { string whatever;

Re: weekly news?

2020-01-23 Thread James Blachly via Digitalmars-d-learn
On 1/23/20 8:13 PM, Mike Parker wrote: On Thursday, 23 January 2020 at 15:44:10 UTC, Adam D. Ruppe wrote: Or delete all that wordpress junk and make something in D :P I intend to delete all that Wordpress junk and go completely static eventually. Mike, I know we're not a golang shop, but

Re: weekly news?

2020-01-23 Thread James Blachly via Digitalmars-d-learn
On 1/22/20 7:58 PM, Adam D. Ruppe wrote: On Thursday, 23 January 2020 at 00:52:10 UTC, Mike Parker wrote: Got any examples? No one has reported this to me before and I haven’t encountered a 404 in a while. Almost all of them! Hit F12 to open browser tools and notice the network tab:

Re: Some comments on learning D using the tour

2020-01-16 Thread James Blachly via Digitalmars-d-learn
On 1/15/20 3:06 PM, mark wrote: I am learning D for the first time. While I wait for Mike Parker's "Learning D" book to arrive, I have started using the tour. I really like the tour, especially the fact that you can run and tweak the code as well as read the explanations. However, ...

Re: druntime 2.087 regression? (was: Old codebase stops compiling at 2.087)

2019-12-03 Thread James Blachly via Digitalmars-d-learn
On 11/17/19 7:15 PM, Steven Schveighoffer wrote: On 11/17/19 10:45 AM, James Blachly wrote: /home/james/dmd2.087/dmd2/linux/bin64/../../src/druntime/import/object.d(3453,36): Error: cannot implicitly convert expression aa of type shared(GSeqAllele[string]) to const(shared(GSeqAllele)[string])

druntime 2.087 regression? (was: Old codebase stops compiling at 2.087)

2019-11-17 Thread James Blachly via Digitalmars-d-learn
TL;DR druntime regression? https://gist.github.com/jblachly/78c5762bbfea65b09e7a1417ad763019 --- Our team has an older codebase that compiled fine up until frontend version 2.087 (builds with 2.086.1). Now, compiler (DMD2 and LDC2) complains about implicit conversion of shared(AA) to

Re: How to Unqual an array?

2019-11-17 Thread James Blachly via Digitalmars-d-learn
On 11/16/19 10:20 AM, James Blachly wrote: On 11/16/19 9:48 AM, James Blachly wrote: I am trying to write templated code that will take a character array -- mutable, const, or immutable (string). I am aware of isSomeString, but I am still curious about Unqual array from a learning

Re: How to Unqual an array?

2019-11-16 Thread James Blachly via Digitalmars-d-learn
On 11/16/19 9:48 AM, James Blachly wrote: I am trying to write templated code that will take a character array -- mutable, const, or immutable (string). I am aware of isSomeString, but I am still curious about Unqual array from a learning perspective.

How to Unqual an array?

2019-11-16 Thread James Blachly via Digitalmars-d-learn
I am trying to write templated code that will take a character array -- mutable, const, or immutable (string). static assert(is(Unqual!(const char) == char)); (Succeeds) static assert(is(Unqual!(const(char)[]) == char[])); Error: static assert: `is(const(char)[] == char[])` is false Is

Re: Why is sformat and formattedWrite (appender) allocating GC mem here?

2019-09-03 Thread James Blachly via Digitalmars-d-learn
On 8/31/19 5:12 PM, ag0aep6g wrote: I've made a pull request to get rid of those allocations: https://github.com/dlang/phobos/pull/7163 Wonderful! For my own learning, why was a unittest to ensure no GC added to sformat instead of a @nogc annotation?

Do I understand std.experimental.allocator composition correctly?

2019-08-25 Thread James Blachly via Digitalmars-d-learn
The documentation for std.experimental.allocator is a little dense and I wanted to make sure I am understanding composition correctly. Suppose I have the following, taken more-or-less direct from the docs: auto batchAllocator = AllocatorList!( (size_t n) => Region!Mallocator(max(n,

Re: How to get name of my application (project)

2019-08-03 Thread James Blachly via Digitalmars-d-learn
On 8/3/19 5:26 AM, Andrey wrote: Hello, how to get name of my application (project) that we write in dub.json? Is there any compile-time constant like __MODULE__? Dear Andrey: Perhaps this is similar to what you are looking for: https://dlang.org/spec/grammar.html#SpecialKeyword

Re: Basic Linear Algebra and D's Array Operation

2019-05-19 Thread James Blachly via Digitalmars-d-learn
On 5/19/19 2:34 AM, Andrew Edwards wrote: P.S. Why do we still have two sets of documentations ([1],[2]) for the language? Which is the official one and when can we get rid of the other? [1] https://dlang.org/library/std/array.html [2] https://dlang.org/phobos/std_array.html I have wondered

Re: dub preBuildCommand removed?

2019-05-04 Thread James Blachly via Digitalmars-d-learn
On 5/4/19 5:27 PM, Andre Pany wrote: On Saturday, 4 May 2019 at 21:16:25 UTC, James Blachly wrote: It is listed in the build settings table of the referenced link. Kind regards Andre Somehow firefox enabled "whole word" search *rolleyes*, which I did not even realize was a thing. Thanks

dub preBuildCommand removed?

2019-05-04 Thread James Blachly via Digitalmars-d-learn
the preBuildCommand is no longer listed in the dub format spec[1] although it shows up in the google cache for the page. When was it removed, and why? I can't find any announcement. [1] https://dub.pm/package-format-json.html

Re: Cast ptr/len to D-style array

2019-05-04 Thread James Blachly via Digitalmars-d-learn
On 5/3/19 5:42 AM, Ali Çehreli wrote: On 05/02/2019 08:21 PM, James Blachly wrote: On 5/2/19 4:05 PM, ag0aep6g wrote: Just slice the pointer with the length: int* ptr; size_t len; int[] arr = ptr[0 .. len]; Perfect thanks. I searched but without using the magic word "slice" I

Re: Cast ptr/len to D-style array

2019-05-02 Thread James Blachly via Digitalmars-d-learn
On 5/2/19 4:05 PM, ag0aep6g wrote: Just slice the pointer with the length:     int* ptr;     size_t len;     int[] arr = ptr[0 .. len]; Perfect thanks. I searched but without using the magic word "slice" I couldn't find meaningful results. Thanks again.

Cast ptr/len to D-style array

2019-05-02 Thread James Blachly via Digitalmars-d-learn
I work a lot with C functions, many of which yield pointer + length. Is there a way to cast this or materialize a D-style array backed by the already allocated data (with length) to avoid copies which slow things down? I recognize memory management is a complication. Typically, I would be

Re: Easiest way to use Linux system C files / tiny C libraries

2019-04-07 Thread James Blachly via Digitalmars-d-learn
On 3/29/19 7:52 PM, H. S. Teoh wrote: On Fri, Mar 29, 2019 at 10:48:47PM +, Chris Katko via Digitalmars-d-learn wrote: ...> There are probably other similar gotchas, but these are the ones off the top of my head. Feel free to ask if you're having trouble correctly translating something

Re: Member is @disable this(this), parent uncopyable

2019-03-22 Thread James Blachly via Digitalmars-d-learn
On 3/22/19 9:24 AM, Alex wrote: On Friday, 22 March 2019 at 12:08:39 UTC, James Blachly wrote: First, how do we deal with toString, std.format, writeln, etc. with un-copyable objects, when it is only a member that is uncopyable?  In my case I got around this by creating a pointer and moving

Member is @disable this(this), parent uncopyable

2019-03-22 Thread James Blachly via Digitalmars-d-learn
I have a struct S with member containers.UnrolledList [1]. UnrolledList is @disable this(this), but this unfortunately makes my struct S also un-copyable, which now breaks some of my debugging statements which rely on toString, as writeln, format, etc. all copy the object. This leaves me in

Re: Where is GDC being developed?

2019-03-21 Thread James Blachly via Digitalmars-d-learn
On 3/21/19 6:51 PM, James Blachly wrote: On 3/21/19 6:01 AM, Johannes Pfau wrote: On Thursday, 21 March 2019 at 08:19:56 UTC, Per Nordlöw wrote: At https://github.com/D-Programming-GDC/GDC/commits/master there's the heading "This repository has been archived by the owner. It is now

Re: Where is GDC being developed?

2019-03-21 Thread James Blachly via Digitalmars-d-learn
On 3/21/19 6:01 AM, Johannes Pfau wrote: On Thursday, 21 March 2019 at 08:19:56 UTC, Per Nordlöw wrote: At https://github.com/D-Programming-GDC/GDC/commits/master there's the heading "This repository has been archived by the owner. It is now read-only." Where will the development of GDC

Re: How can I make a nested array and flatten it at run time in D?

2019-03-07 Thread James Blachly via Digitalmars-d-learn
On 3/7/19 8:00 PM, Philos Kim wrote: I want to make a nested array and flatten it at run-time like this. auto nestedArray = [1, 2, [3, 4], 5]; auto flattenedArray = myFun(nestedArray); writeln(flattenedArray);   // => [1, 2, 3, 4, 5] How can I do this in D? Please help me out! There are

Re: DMD2 vs LDC2 inliner

2019-02-25 Thread James Blachly via Digitalmars-d-learn
On 2/25/19 2:09 AM, Nicholas Wilson wrote: Leaving aside the issue of why DMD can't handle this, the entire reason pragma(inline, bool) takes a bool is for it to be (potentially) predicated. In this case you want: version(DigitalMars)   private enum inline_overlaps = false; else //

Re: DMD2 vs LDC2 inliner

2019-02-25 Thread James Blachly via Digitalmars-d-learn
On 2/25/19 2:09 AM, Nicholas Wilson wrote: Leaving aside the issue of why DMD can't handle this, the entire reason pragma(inline, bool) takes a bool is for it to be (potentially) predicated. In this case you want: version(DigitalMars) private enum inline_overlaps = false; else // assuming

DMD2 vs LDC2 inliner

2019-02-24 Thread James Blachly via Digitalmars-d-learn
Any ideas why DMD2 cannot inline this, but LDC2 has no problem doing so -- or suggestions for what I can do to make DMD2 inline it? Alternatively, I could version(DigitalMars) and version(LDC), but AFAICT this requires me to duplicate the entire template, because I cannot figure out how to

Re: std.container.rbtree as Interval Tree?

2019-02-05 Thread James Blachly via Digitalmars-d-learn
On Tuesday, 5 February 2019 at 16:24:03 UTC, Eduard Staniloiu wrote: I think you are making a slight confusion. Your `Interval` struct and the `Elem` type that `lowerBound` takes, are the same type. You can define your RBTree and Interval as follows ``` struct Interval { int start;

Re: std.container.rbtree as Interval Tree?

2019-02-05 Thread James Blachly via Digitalmars-d-learn
On Tuesday, 5 February 2019 at 10:10:44 UTC, RazvanN wrote: On Monday, 4 February 2019 at 22:54:01 UTC, James Blachly wrote: I tried to implement an interval tree backed by std.container.rbtree today and fell flat. [...] You can use alias this [1] in your interval element type: struct

std.container.rbtree as Interval Tree?

2019-02-04 Thread James Blachly via Digitalmars-d-learn
I tried to implement an interval tree backed by std.container.rbtree today and fell flat. A standard way to make an interval tree is to make an augmented tree; I supposed since rbtree was a generic container and because I could define opCmp, this should be a cinch. I ran into two problems.

Re: Shared, ref, arrays, and reserve template instantiation

2018-09-12 Thread James Blachly via Digitalmars-d-learn
Great -- Thank you both. I previously found Unqual, but it looks like that needs template support so wasn't feasible, hence my question. Neia is right that I tried to cast as in the second case ( but without UFCS -- reserve( cast(int[]), N); ). As an aside, what is going on behind the

Shared, ref, arrays, and reserve template instantiation

2018-09-12 Thread James Blachly via Digitalmars-d-learn
When I add the "shared" attribute to an array, I am no longer able to call reserve because the template won't instantiate: Error: template object.reserve cannot deduce function from argument types !()(shared(int[]), int), candidates are:

Re: extern __gshared const(char)* symbol fails

2018-08-31 Thread James Blachly via Digitalmars-d-learn
On Friday, 31 August 2018 at 17:50:17 UTC, Steven Schveighoffer wrote: What the C compiler is doing is storing it as data, and then storing the symbol to point at the first element in the data. When you use const char* in D, it's expecting a *pointer* to be stored at that address, not the

Re: extern __gshared const(char)* symbol fails

2018-08-31 Thread James Blachly via Digitalmars-d-learn
On Friday, 31 August 2018 at 17:18:58 UTC, Neia Neutuladh wrote: On Friday, 31 August 2018 at 06:20:09 UTC, James Blachly wrote: Hi all, ... When linking to this library from D, I have declared it as: extern __gshared const(char)* seq_nt16_str; ***But this segfaults when I treat it like an

Re: Is there any reason to use non-ref foreach?

2018-08-31 Thread James Blachly via Digitalmars-d-learn
On Friday, 31 August 2018 at 12:52:17 UTC, bauss wrote: So basically ... Instead of copying the value, you're just copying the address. I can't see the benefit other than added complexity. I assume a benefit could be observed if you are copying a large struct instead of an int.

extern __gshared const(char)* symbol fails

2018-08-31 Thread James Blachly via Digitalmars-d-learn
Hi all, I am linking to a C library which defines a symbol, const char seq_nt16_str[] = "=ACMGRSVTWYHKDBN"; In the C sources, this is an array of 16 bytes (17 I guess, because it is written as a string). In the C headers, it is listed as extern const char seq_nt16_str[]; When linking to

Re: InputRange help: (1) repeated dtor calls and (2) managing resources needing free()

2018-08-19 Thread James Blachly via Digitalmars-d-learn
On Monday, 13 August 2018 at 13:20:25 UTC, Seb wrote: BTW it's very uncommon for empty to do work, it's much more common to do such lazy initialization in `.front`. Thanks Seb, that entire reply is a huge help. By lazy initialization in `.front`, do you mean that I should find a way for

Re: InputRange help: (1) repeated dtor calls and (2) managing resources needing free()

2018-08-12 Thread James Blachly via Digitalmars-d-learn
On Thursday, 14 June 2018 at 00:42:25 UTC, James Blachly wrote: ... I assume the (apparent) lack of parity between ctor and dtor is because the "default postblit" (which I figured out for a struct means an empty `this(this)` ctor) is called when a copy is made. My understanding is that I

InputRange help: (1) repeated dtor calls and (2) managing resources needing free()

2018-06-13 Thread James Blachly via Digitalmars-d-learn
Hi all, I now really appreciate the power Ranges provide and am an avid consumer, but am only slowly becoming accustomed to implementing my own. In the present problem, I am writing a binding to a C library (htslib) that provides many functions related to high-throughput sequencing files.

What is special about an immutable array of class objects, and why can I not .dup ?

2018-05-28 Thread James Blachly via Digitalmars-d-learn
Consider the below: ``` class C { int x; } struct S { int x; } void main() { immutable C[] c = [ new C(), new C()]; immutable S[] s = [ S(), S() ]; immutable int[] i = [ 1, 2 ]; auto x = c.dup; auto y = s.dup; auto z = i.dup; } ``` This fails to

Why does enumerate over range return dchar, when ranging without returns char?

2018-05-02 Thread James Blachly via Digitalmars-d-learn
I am puzzled why enumerating in a foreach returns a dchar (which forces me to cast), whereas without the enumerate the range returns a char as expected. Example: ``` import std.stdio; import std.range : enumerate; void main() { char[] s = ['a','b','c']; char[3] x; auto i =

Re: What is the "right" way to create a generic type getter (and setter) ?

2018-03-15 Thread James Blachly via Digitalmars-d-learn
On Wednesday, 14 March 2018 at 22:58:25 UTC, ag0aep6g wrote: You can probably get around the (manually maintained?) `FIELDS` array with `.tupleof` or something similar: static foreach (i, f; S.tupleof) { case __traits(identifier, f): } Any pointers / design patterns on this

What is the "right" way to create a generic type getter (and setter) ?

2018-03-14 Thread James Blachly via Digitalmars-d-learn
For context, please keep in mind I am coming from a python background, but am very much enjoying strong typing, although it is taking some significant adjustment. Suppose I have a struct (which is really a memory map of a data file I am reading in) with too many data members to reasonably