Re: SumType alias can't be deduced?

2022-02-21 Thread Emmanuelle via Digitalmars-d-learn
On Monday, 21 February 2022 at 20:18:46 UTC, Paul Backus wrote: This is a long-standing limitation of the D compiler's template argument deduction: it cannot "see through" `alias` templates to deduce the underlying type. Oh, that’s an unfortunate limitation but at least there’s a workaround.

SumType alias can't be deduced?

2022-02-21 Thread Emmanuelle via Digitalmars-d-learn
See https://run.dlang.io/is/hNaSFh: ```d import std.sumtype; struct Unit {} alias Option(T) = SumType!(T, Unit); void foobar(T)(Option!T option) {} void main() { foobar(Option!int(123)); } ``` If you run this, the compiler should emit this error: ```d onlineapp.d(14): Error: template

Re: The compiler can't "see" an inner class

2019-10-27 Thread Emmanuelle via Digitalmars-d-learn
On Sunday, 27 October 2019 at 19:54:06 UTC, Simen Kjærås wrote: It's a bug: interface A { interface B : A { class C : B { } } // Fails: no property 'C' for type 'foo.A.B' void inside(A.B.C c) { } } // Works void outside(A.B.C c) { }

The compiler can't "see" an inner class

2019-10-27 Thread Emmanuelle via Digitalmars-d-learn
Hello! See snippet: --- interface AST { static interface Expr : AST { final static class Name : Expr { override void accept(AST.Visitor v) { v.visitName(this); } } } final static class Visitor { void visitName(AST.Expr.Name

Why is the fPIC switch missing?

2019-09-22 Thread Emmanuelle via Digitalmars-d-learn
Hello. My problem is exactly what it says on the title: my dmd (windows 7, x64) doesn't seem to have -fPIC: --- dmd -fPIC Error: unrecognized switch '-fPIC' run `dmd` to print the compiler manual run `dmd -man` to open browser on manual --- `dmd --help` also doesn't have

Re: Why is the fPIC switch missing?

2019-09-22 Thread Emmanuelle via Digitalmars-d-learn
Forgot to say: dmd v2.088.0. Also, weirdly enough, `dmd --version` outputs `DMD32 D Compiler v2.088.0-dirty`. Why is "dirty" there?

Re: Transform a function's body into a string for mixing in

2019-06-21 Thread Emmanuelle via Digitalmars-d-learn
On Friday, 21 June 2019 at 15:54:35 UTC, Adam D. Ruppe wrote: On Friday, 21 June 2019 at 15:42:56 UTC, Emmanuelle wrote: [...] This sounds very similar to something I hacked together a while ago and recently wrote about making cleaner code:

Re: Transform a function's body into a string for mixing in

2019-06-21 Thread Emmanuelle via Digitalmars-d-learn
On Thursday, 20 June 2019 at 20:38:48 UTC, Dennis wrote: On Thursday, 20 June 2019 at 19:09:11 UTC, Emmanuelle wrote: Is there any trait or Phobos function for transforming a function/delegate/lambda/whatever's body into a string suitable for `mixin(...)`? For example: See:

Transform a function's body into a string for mixing in

2019-06-20 Thread Emmanuelle via Digitalmars-d-learn
Hello! Is there any trait or Phobos function for transforming a function/delegate/lambda/whatever's body into a string suitable for `mixin(...)`? For example: --- __traits(getBody, (int a, int b) => a + b); // returns "(int a, int b) => a + b" //

Re: What's the difference between DIP25 and DIP1000?

2019-06-18 Thread Emmanuelle via Digitalmars-d-learn
On Tuesday, 18 June 2019 at 21:57:32 UTC, Jonathan M Davis wrote: -snip- Thank you, it's clear to me now :)

What's the difference between DIP25 and DIP1000?

2019-06-18 Thread Emmanuelle via Digitalmars-d-learn
Hi, I've been reading about DIP25 and DIP1000 and I'm not quite sure if I understand the difference between the two—is DIP1000 supposed to be a rework of DIP25? And what's the difference between `return ref` and `return scope`? Also, will there be any compiler version where `-preview=dip25`

Re: Strange closure behaviour

2019-06-15 Thread Emmanuelle via Digitalmars-d-learn
On Saturday, 15 June 2019 at 16:29:29 UTC, Rémy Mouëza wrote: I don't know if we can tell this is a compiler bug. The same behavior happens in Python. The logic being variable `x` is captured by the closure. That closure's context will contain a pointer/reference to x. Whenever x is updated

Re: Strange closure behaviour

2019-06-14 Thread Emmanuelle via Digitalmars-d-learn
On Saturday, 15 June 2019 at 00:30:43 UTC, Adam D. Ruppe wrote: On Saturday, 15 June 2019 at 00:24:52 UTC, Emmanuelle wrote: Is it a compiler bug? Yup, a very longstanding bug. You can work around it by wrapping it all in another layer of function which you immediately call (which is fairly

Strange closure behaviour

2019-06-14 Thread Emmanuelle via Digitalmars-d-learn
Take a look at this code: --- import std.stdio; void main() { alias Func = void delegate(int); int[][] nums = new int[][5]; Func[] funcs; foreach (x; 0 .. 5) { funcs ~= (int i) { nums[x] ~= i; }; } foreach (i, func; funcs) { func(cast(int) i); }

Re: Ordering of UDAs

2019-04-22 Thread Emmanuelle via Digitalmars-d-learn
On Monday, 22 April 2019 at 19:32:27 UTC, Adam D. Ruppe wrote: On Monday, 22 April 2019 at 19:02:57 UTC, Emmanuelle wrote: Hello! Does `__traits(getAttributes, ...)` return UDAs in the order they were declared in the source code, or is it unspecified? I think that is defined:

Ordering of UDAs

2019-04-22 Thread Emmanuelle via Digitalmars-d-learn
Hello! Does `__traits(getAttributes, ...)` return UDAs in the order they were declared in the source code, or is it unspecified?