Linking D Runtime

2019-08-23 Thread Jonathan Levi via Digitalmars-d-learn
I am trying to find the D runtime/standard-library object(.o)/library(.a) files inorder to link them with some foreign code (Haskell as it happens). I am writing a program in Haskell but want to use D for some of the imperative style logic. I expect to have a large section of code in D so I

Re: Linking D Runtime

2019-08-23 Thread Jonathan Levi via Digitalmars-d-learn
On Saturday, 24 August 2019 at 01:19:01 UTC, H. S. Teoh wrote: Not sure what's the "right" approach, but you could try compiling with dmd -v to find the path(s) to the runtime libraries that you'll need to link. Oh, cool, I managed to find them on my current system. I would love a more porta

Re: Linking D Runtime

2019-09-02 Thread Jonathan Levi via Digitalmars-d-learn
On Saturday, 24 August 2019 at 00:26:43 UTC, Jonathan Levi wrote: I am trying to find the D runtime/standard-library object(.o)/library(.a) files inorder to link them with some foreign code (Haskell as it happens). I am writing a program in Haskell but want to use D for some of the imperative

Duration to Decimal Total

2019-11-06 Thread Jonathan Levi via Digitalmars-d-learn
`core.time.Duration` has a `total` function for extracting the value withing the Duration. `total` returns a whole number (`long`). Is there a function that returns a decimal (`double` or `float`)? I cannot find one in `core.time`. How would I do it then? I know I can get finer precision (s

Static if a Function Exists

2020-04-02 Thread Jonathan Levi via Digitalmars-d-learn
I am trying to make a templated function for any arguments which will work for another. Like this: ``` class Cls { auto opBinary(string op, T)(T b) if (__traits(compiles, opBinaryImpl!op(this, b))) { return opBinaryImpl!op(this, b); } } auto opBinaryImpl(string op, T)(Cl

Re: Static if a Function Exists

2020-04-04 Thread Jonathan Levi via Digitalmars-d-learn
On Friday, 3 April 2020 at 07:08:03 UTC, WebFreak001 wrote: maybe not the optimal solution because stringof isn't properly defined, but currently I don't think there is a better way than: template matchesTemplateConstraints(alias fn, Args...) { enum def = fn.stringof; // private void te

Re: How can I get a backtrace on segfault?

2020-12-11 Thread Jonathan Levi via Digitalmars-d-learn
On Wednesday, 14 September 2011 at 12:16:02 UTC, Steven Schveighoffer wrote: In any case, have you tried this? Works on unixen only. import core.stdc.signal; extern(C) void handleSegv(int) { assert(0); } void main() { signal(SIGSEGV, &handleSegv); ... } Not sure if it prints a stack tra

Variadic Struct Parameter

2021-01-12 Thread Jonathan Levi via Digitalmars-d-learn
Why is this not working? ``` struct S { int x; string y; } void fun(S s ...) { writeln(s); } void main() { fun(S(5,"hi")); fun(5,"hi"); } ``` Why does `fun` compile if calling it does not?

Re: Variadic Struct Parameter

2021-01-12 Thread Jonathan Levi via Digitalmars-d-learn
On Tuesday, 12 January 2021 at 17:46:14 UTC, Q. Schroll wrote: It's obvious why arrays work, it's the primary use case. I have no idea why classes are allowed. That classes are allowed, but structs are not, makes no sense to me. I like the variadic feature for classes, but I wish it worked for

__traits(compiles) is true with warnings as errors

2021-10-13 Thread Jonathan Levi via Digitalmars-d-learn
When dmd is passed the "-w" tag, it "treats warnings as errors" but not with the "__traits(compiles)" expression. Is this the intended action? This code should compile even with "-w", but it does not. int i; static if (__traits(compiles,i += 5.2)) i += 5.2; `pragma(msg, __tr

Implement Interface Using Super

2019-01-26 Thread Jonathan Levi via Digitalmars-d-learn
This works in LDC but not DMD? ``` class A : B, I { alias i = typeof(super).i; } class B { void i() { writeln("i"); } } interface I { void i(); } ``` Is this a bug in DMD or in LDC? How can I get this effect correctly?

Re: Implement Interface Using Super

2019-01-28 Thread Jonathan Levi via Digitalmars-d-learn
On Sunday, 27 January 2019 at 09:31:46 UTC, bauss wrote: On Sunday, 27 January 2019 at 05:37:57 UTC, Jonathan Levi wrote: This works in LDC *but not* DMD? . . . Is this a bug in DMD *or* in LDC? There is no bug here. So... LDC is the one that is bugged? I think it would have been nice to ha

Memory reference that does not stop garbage collection.

2019-02-08 Thread Jonathan Levi via Digitalmars-d-learn
I have observers and listeners. class Observer { Listener[] listeners; } class Listener {} The observers keep references to listeners, but I would like the GC to garbage collect listeners even if observers have references to it and remove the references in observers. I should be able to u