Re: How bundles a Dlang application and all its dependencies into a single .exe package?

2019-12-01 Thread Dennis via Digitalmars-d-learn
On Sunday, 1 December 2019 at 20:05:40 UTC, Marcone wrote: How bundles a Dlang application and all its dependencies into a single .exe package? You can embed files in the .exe using the import statement: https://p0nce.github.io/d-idioms/#Embed-a-dynamic-library-in-an-executable

Re: static assert(version(x)) ?

2019-11-26 Thread Dennis via Digitalmars-d-learn
On Tuesday, 26 November 2019 at 10:24:00 UTC, Robert M. Münch wrote: How can I write something like this to check if any of a set of specific versions is used? ``` version(a) {} else version(b) {} else version(c) {} else { static assert(0, "only versions a, b and c are supported"); } ```

Re: How to catch a signal

2019-11-09 Thread Dennis via Digitalmars-d-learn
On Saturday, 9 November 2019 at 12:44:20 UTC, W.Boeke wrote: What should be the right way to accomplish this? Put an ampersand before the function to get its address: signal.signal(SIGWINCH,cast(void function(int)) _winch); In C you can omit the & when taking a function address, but when

Re: Duration to Decimal Total

2019-11-06 Thread Dennis via Digitalmars-d-learn
On Wednesday, 6 November 2019 at 19:13:46 UTC, Jonathan Levi wrote: I would think a function that this would be appropriate to belong in the module. Am I missing it? Or, how would you recommend calculating it? The author of the module has explained before that this is very intentional:

Re: Unable to pass a D function member to a C callback

2019-11-02 Thread Dennis via Digitalmars-d-learn
On Saturday, 2 November 2019 at 20:42:29 UTC, Luh wrote: Yup that's it ! Many thanks ! One word of warning: ensure the C library does not have the only reference to your Game class instance, or the garbage collector might deallocate it since it does not scan threads created by C libraries.

Re: Unable to pass a D function member to a C callback

2019-11-02 Thread Dennis via Digitalmars-d-learn
On Saturday, 2 November 2019 at 19:42:54 UTC, Luh wrote: So I think I just can't. :( Is that `void* c` in the callback a context pointer by any chance? That's a common thing in C callbacks precisely for purposes like this. You can cast your class to a void* when you register the callback and

Re: Documentation: is it intentional that template constraints are displayed after the signature?

2019-11-01 Thread Dennis via Digitalmars-d-learn
Template constraints are not allowed before the signature in the language, so it can be expected the documentation does not swap that order. On Thursday, 31 October 2019 at 13:34:35 UTC, Tobias Pankrath wrote: I was confused at first by the trailing if (!is(T == struct) && !is(T ==

Re: Why Dlang use parsing expression grammar (PEG) parser not BNF?

2019-11-01 Thread Dennis via Digitalmars-d-learn
On Thursday, 31 October 2019 at 08:40:42 UTC, lili wrote: Hi: I want implementation Lua on D, I find that a PEG parser https://github.com/PhilippeSigaud/Pegged why do not use BNF parser. Is PEG better than BNF? The readme has a link to the reference article:

Re: About the in expression, Why can't use with array.

2019-10-25 Thread Dennis via Digitalmars-d-learn
On Friday, 25 October 2019 at 19:49:05 UTC, Ali Çehreli wrote: I'm still not completely sold on the whole idea though because it's not a clear win. Do others see other advantages in other places like templates? For example, could templates really be written generically for arrays and

Re: About the in expression, Why can't use with array.

2019-10-25 Thread Dennis via Digitalmars-d-learn
On Friday, 25 October 2019 at 05:17:35 UTC, Ali Çehreli wrote: - Big O is different No it isn't. Worst case lookup of an associative array lookup is O(n) too. It can easily be 'achieved' by having a key type with: ``` size_t toHash() const scope pure { return 0; } ``` The fact that

Re: Error: need this for method of type

2019-10-23 Thread Dennis via Digitalmars-d-learn
On Wednesday, 23 October 2019 at 11:48:29 UTC, Dennis wrote: You can change `method(1)` into `x.method(1)` and it should work. Wait, but that's only because the local alias and member function have the same name 'method'. I think you just have to keep the method name as a string instead of

Re: Error: need this for method of type

2019-10-23 Thread Dennis via Digitalmars-d-learn
On Wednesday, 23 October 2019 at 11:40:09 UTC, Márcio Martins wrote: This is a bug, right? If not, why, and how can I get around it and call `method`? An alias refers just to a symbol, in this case a member function of struct X. The fact that you polled it on instance 'x' is not something an

Re: arsd errors on windows

2019-10-17 Thread Dennis via Digitalmars-d-learn
On Thursday, 17 October 2019 at 21:32:34 UTC, WhatMeWorry wrote: DUB version 1.11.0, built on Oct 6 2018 `dub add` got added at the end of 2018 IIRC, so you need to upgrade Dub.

Re: arsd errors on windows

2019-10-17 Thread Dennis via Digitalmars-d-learn
On Thursday, 17 October 2019 at 20:17:53 UTC, Greatsam4sure wrote: the same error That was meant for Adam to put in the dub package file of arsd, in your project it won't affect the compilation of the dependency. (Though you can still try adding it in your local download of arsd to quickly

Re: arsd errors on windows

2019-10-17 Thread Dennis via Digitalmars-d-learn
On Thursday, 17 October 2019 at 12:06:49 UTC, Dennis wrote: You can put "buildRequirements": "allowWarnings" in your dub.json. Should be "buildRequirements": ["allowWarnings"]

Re: arsd errors on windows

2019-10-17 Thread Dennis via Digitalmars-d-learn
On Thursday, 17 October 2019 at 11:35:26 UTC, Adam D. Ruppe wrote: ugh dub insists on this stupid warning as error nonsense and the warnings suck so they slip through me sometimes. You can put "buildRequirements": "allowWarnings" in your dub.json. (buildRequirements "allowWarnings" in dub.sdl)

Re: arsd errors on windows

2019-10-17 Thread Dennis via Digitalmars-d-learn
On Thursday, 17 October 2019 at 04:05:40 UTC, Greatsam4sure wrote: what is the way out. I made a pull request fixing it: https://github.com/adamdruppe/arsd/pull/222 In the mean time, you can add the subpackage "arsd-official:simpledisplay" as a depdendency instead so cgi.d won't be included

Re: std.algorithm.cmp doesn't seem to support numeric types?

2019-10-16 Thread Dennis via Digitalmars-d-learn
On Wednesday, 16 October 2019 at 20:07:10 UTC, Adam D. Ruppe wrote: Notice that the docs say "a negative value" rather than -1 specifically. That's because the implementation for integers an be as simple as return a - b; // if b > a, you get a negative value Except that e.g. -2 - int.max

Re: Mixin and introspection ordering

2019-10-16 Thread Dennis via Digitalmars-d-learn
On Wednesday, 16 October 2019 at 10:09:51 UTC, Sebastiaan Koppe wrote: Do we want to be able to catch things in their 'before' state? Or is it a bug? The 'before' and 'after' are implementation details showing up as a result of underspecification. Module level declarations are supposed to

Re: selective tests

2019-10-12 Thread Dennis via Digitalmars-d-learn
On Saturday, 12 October 2019 at 09:52:59 UTC, Jonathan M Davis wrote: You could set up your build so that you had targets which only compiled specific directories so that the only unit tests that were run were the ones in those directories, but I don't think that it's possible to do anything

Re: Template mixin + operator overloading question

2019-10-11 Thread Dennis via Digitalmars-d-learn
On Friday, 11 October 2019 at 12:45:59 UTC, Boyan Lazov wrote: Any ideas what I'm doing wrong? Nothing, it's a bug. https://issues.dlang.org/show_bug.cgi?id=19476

Have DUB sub packages inherit settings

2019-10-09 Thread Dennis via Digitalmars-d-learn
I want to split my package into sub packages for faster compilation, but I have some custom settings that I don't want to copy-paste 10 times since that makes editing them really annoying. Is there a way to inherit the settings from the main-package, or avoid repetition in another way? I

Re: How does D distnguish managed pointers from raw pointers?

2019-10-04 Thread Dennis via Digitalmars-d-learn
On Friday, 4 October 2019 at 18:53:30 UTC, H. S. Teoh wrote: Here's an actual working example that illustrates the pitfall of this implicit conversion: Luckily it's caught by -dip1000

Re: How does D distnguish managed pointers from raw pointers?

2019-10-04 Thread Dennis via Digitalmars-d-learn
On Friday, 4 October 2019 at 19:08:04 UTC, Adam D. Ruppe wrote: (personally though I like to explicitly slice it all the time though, it is more clear and the habit is nice) Turns out I have this habit as well. I'm looking through some of my code and see redundant slicing everywhere.

Re: How does D distnguish managed pointers from raw pointers?

2019-10-04 Thread Dennis via Digitalmars-d-learn
On Friday, 4 October 2019 at 18:43:34 UTC, H. S. Teoh wrote: Actually, it *does* automatically convert the static array to a slice. You're right, I'm confused. I recall there was a situation where you had to explicitly slice a static array, but I can't think of it now.

Re: How does D distnguish managed pointers from raw pointers?

2019-10-04 Thread Dennis via Digitalmars-d-learn
On Friday, 4 October 2019 at 18:30:17 UTC, IGotD- wrote: What if you pass a static array to a function that expects a dynamic array. Will D automatically create a dynamic array from the static array? No, you have to append [] to create a slice from the static array.

Re: Looking for a Simple Doubly Linked List Implementation

2019-09-21 Thread Dennis via Digitalmars-d-learn
On Saturday, 21 September 2019 at 08:34:09 UTC, Ron Tarrant wrote: Thanks, Dennis. Not performant... It doesn't work? I was hoping for a complete, working example, but maybe this'll help. Bad word choice (it appears it's debatable whether 'performant' even is a word), I meant it was a simple

Re: Looking for a Simple Doubly Linked List Implementation

2019-09-20 Thread Dennis via Digitalmars-d-learn
On Friday, 20 September 2019 at 20:26:03 UTC, Ron Tarrant wrote: If someone could please post a minimal example (if there's extra stuff in there, I'll get confused; I'm getting that old, dammit) I'd be ever so grateful. Below is a simple doubly linked list with Garbage Collected memory. It's

Re: Questions regarding a port (bindbc-cimgui)

2019-09-16 Thread Dennis via Digitalmars-d-learn
On Sunday, 15 September 2019 at 08:17:20 UTC, sytnax wrote: So, the question is: should I share this somehow (despite the limitations listed below)? Considering the circumstances you mentioned, I'd say either don't publish it or simply make it a public GitHub repository with these

Re: Throwing from a lambda isn't supported by the compiler

2019-09-09 Thread Dennis via Digitalmars-d-learn
On Monday, 9 September 2019 at 13:22:22 UTC, Johannes Loher wrote: This is incorrect. It was rejected because the proposal was not solid enough. I put that a bit bluntly, but as far as I see it, the DIP focused too much on only adding a way to mark functions as 'no return' that people were

Re: Throwing from a lambda isn't supported by the compiler

2019-09-09 Thread Dennis via Digitalmars-d-learn
On Monday, 9 September 2019 at 09:37:25 UTC, a11e99z wrote: cuz throwing exception ever is not compatible with any return type so I dont see reasons do not allow such expressions A throw statement can actually be seen as an expression returning a 'never' / 'bottom' type which is implicitly

Re: Quick question regarding dynamic array deletions

2019-09-01 Thread Dennis via Digitalmars-d-learn
On Sunday, 1 September 2019 at 18:26:20 UTC, WhatMeWorry wrote: Maybe my question is when would be want to use 3) without also adjusting the .ptr ? It matters when casting to a boolean, since an empty array with a non-null pointer is still `true` while an array with null pointer casts to

Re: Linker errors to Windows functions

2019-08-20 Thread Dennis via Digitalmars-d-learn
On Tuesday, 20 August 2019 at 17:17:01 UTC, Vladimirs Nordholm wrote: In code I have `import core.sys.windows.winuser;`, but still get this error. Importing only specifies that you expect the symbols to be there, it doesn't mean the functions are linked in. On Windows there are three

Re: Speed of Random Numbers

2019-08-03 Thread Dennis via Digitalmars-d-learn
On Saturday, 3 August 2019 at 16:35:34 UTC, Giovanni Di Maria wrote: Do you know other faster functions or methods to generate random numbers? For me the "goodness of random" is NOT important. I found some nice random functions in this public-domain C single-header library collection, one

Re: Can one customize unit tests?

2019-08-03 Thread Dennis via Digitalmars-d-learn
The out-of-the box unittest runner is pretty bare by design. It just runs unittest blocks in serial as functions where assert() failures are not undefined behavior. Assert messages are not very helpful, though the recently added flag `-checkaction=context` helps a lot. Luckily there is a

Re: accuracy of floating point calculations: d vs cpp

2019-07-22 Thread Dennis via Digitalmars-d-learn
On Monday, 22 July 2019 at 12:49:24 UTC, drug wrote: Before I start investigating I would like to ask if this issue (different results of floating points calculation for D and C++) is well known? This likely has little to do with the language, and more with the implementation. Basic floating

Re: Quotes inside wysiwyg strings, or alternative solution?

2019-07-18 Thread Dennis via Digitalmars-d-learn
On Thursday, 18 July 2019 at 11:38:55 UTC, Paul wrote: What is the solution in D for wysiwyg strings (or similar) spanning multiple lines containing quotes and apostrophes? Take a look at: https://dlang.org/spec/lex.html#string_literals All string literals may span multiple lines. If you

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

2019-06-20 Thread Dennis via Digitalmars-d-learn
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: https://forum.dlang.org/post/kozwskltzidfnatbp...@forum.dlang.org If not,

Re: Where can find fix length array memory layout document

2019-06-18 Thread Dennis via Digitalmars-d-learn
On Tuesday, 18 June 2019 at 12:26:14 UTC, lili wrote: Hi guys: Is the Dlang fix-length array alloc on stack? when a test writeln([1]).sizeof //16 writeln([2]).sizeof //16 Why, What is the fix-length array memory layout. I'm assuming you mean writeln([1].sizeof). An array

Re: File Exception, Access is denied - prompting for administrator's rights

2019-06-04 Thread Dennis via Digitalmars-d-learn
On Tuesday, 4 June 2019 at 16:30:41 UTC, BoQsc wrote: Is there any way to prompt for administrator's rights, to save the additional effort of lots of clicks? Looking at: https://stackoverflow.com/questions/31844584/is-there-an-api-call-to-prompt-user-for-uac-elevation You can try something

Re: What does ! Stand for in map! and filter! function calls?

2019-06-02 Thread Dennis via Digitalmars-d-learn
On Sunday, 2 June 2019 at 16:39:57 UTC, Rnd wrote: Is it not possible in the language to have template map function also to called as map(x=>... ? That would be slower, and std.algorithm generally disallows easy but slow functions. In Java, you can sort a linked list. In D, sort requires an

Re: Extract code of function

2019-05-26 Thread Dennis via Digitalmars-d-learn
On Sunday, 26 May 2019 at 18:14:23 UTC, Jacob Carlborg wrote: No, that's not possible. Some hacky solutions are possible by importing a source file as a string and parsing it manually. dglsl actually extracts D function code to put into glsl shaders. Here's the snippet. See:

Does slicing have an effect?

2019-05-21 Thread Dennis via Digitalmars-d-learn
I was replacing a memcpy with a slice assignment and accidentally used == instead of =. Usually the compiler protects me from mistakes like that: ``` int[4] a; a == a; ``` Error: a == a has no effect However, because I was using slices it didn't: ``` int[4] a; a[] == a[]; ``` No errors Does

Re: Impose structure on array

2019-05-20 Thread Dennis via Digitalmars-d-learn
On Monday, 20 May 2019 at 12:09:02 UTC, Alex wrote: void* data; auto x = cast(byte[A,B,C])data; X is then an AxBxC matrix. It sounds like you're looking for ndslide from mir http://code.dlang.org/packages/mir-algorithm ``` ubyte data[]; auto x = x.sliced(A, B, C); ``` It should be pretty

Re: Is using floating point type for money/currency a good idea?

2019-05-20 Thread Dennis via Digitalmars-d-learn
On Monday, 20 May 2019 at 11:10:32 UTC, Boqsc wrote: I'm frozen in learning basics of D lang since I want to create a simple game and I really would like a clean and simple code, For a simple game, I think it's the easiest to just store an integer of cents (or the lowest amount of currency

Re: alias parameters, what for?

2019-05-09 Thread Dennis via Digitalmars-d-learn
On Thursday, 9 May 2019 at 09:52:21 UTC, XavierAP wrote: alias parameters are used for functions (in the general sense). Why this instead of specifying and typing the parameter functions or delegates? With function pointers, there is extra indirection and the function can not be inlined.

Re: alias to fully qualified symbol gives error, but when module is also a symbol

2019-05-05 Thread Dennis via Digitalmars-d-learn
On Sunday, 5 May 2019 at 18:07:10 UTC, Adam D. Ruppe wrote: The std.stdio one is supposed to be an error; the old buggy behavior was to bypass the private import in these cases and that is why it is deprecated pending changes. Thanks, that answers my question. The old private-bypassing

alias to fully qualified symbol gives error, but when module is also a symbol

2019-05-05 Thread Dennis via Digitalmars-d-learn
I was trying to rename an imported `sqrt` (wrongly), but I stumbled upon this weird behavior: ``` void main() { import core.stdc.math: sqrtf, sqrt; alias sqrtd = core.stdc.math.sqrt; auto a = sqrtd(1); } ``` onlineapp.d(3): Error: undefined identifier core.stdc.math.sqrt However,

Re: dmd + optlink Symbol Undefined _StretchDIBits@52

2019-05-03 Thread Dennis via Digitalmars-d-learn
On Friday, 3 May 2019 at 06:20:37 UTC, Mike Parker wrote: If you compile with -m32mscoff for 32-bit or -m64, DMD will use the Microsoft linker and import libraries if you have Visual Studio or the MS Build tools installed, and the LDC linker with some import libraries from MinGW if you don’t.

Re: Does D have a tool like pySnooper?

2019-04-25 Thread Dennis via Digitalmars-d-learn
On Monday, 22 April 2019 at 16:24:53 UTC, Taylor Hillegeist wrote: Or would this not be easy at all with D? I don't think so. While there are lots of traits for introspection of declarations, there is no way to introspect lines of code. The whole function would need to be wrapped into a

Re: Are static variables available to other static variables?

2019-04-12 Thread Dennis via Digitalmars-d-learn
On Friday, 12 April 2019 at 10:49:19 UTC, Jamie wrote: I was trying to declare a static variable dependent on another static variable, but it didn't work. Are static variables not known to other static variables at compile time? Add `const` or `immutable` to A and it will work. I don't know

Re: I really don't understand DUB

2019-04-08 Thread Dennis via Digitalmars-d-learn
On Monday, 8 April 2019 at 19:54:28 UTC, WhatMeWorry wrote: Now, I've studied the on-line documentation and even walked through the code somewhat but I'm not making an headway. Very relatable. My tips so far are: - Look for projects in github with a similar structure to yours and look at

Re: Iterate/sort associative array by value?

2019-04-08 Thread Dennis via Digitalmars-d-learn
On Monday, 8 April 2019 at 18:04:28 UTC, kdevel wrote: What's the purpose of .release? The documentation in https://dlang.org/phobos/std_range.html#.SortedRange.release is rather monosyllabic. The sort function returns a SortedRange, which is usually an array wrapper with the extra type

Re: Iterate/sort associative array by value?

2019-04-08 Thread Dennis via Digitalmars-d-learn
On Monday, 8 April 2019 at 07:53:23 UTC, Robert M. Münch wrote: Why does DMD not give a hint, that an import from the standard lib might be missing? I find these explicit import statements very annyoing. There currently are a few hard-coded import hints for common functions:

Re: Iterate/sort associative array by value?

2019-04-07 Thread Dennis via Digitalmars-d-learn
On Sunday, 7 April 2019 at 18:22:00 UTC, Robert M. Münch wrote: Error: no property sort for type Tuple!(uint, "key", int, "value")[] Did you import it? import std.algorithm;

Re: Forbidding implicit conversions from an enum type to an integer

2019-04-02 Thread Dennis via Digitalmars-d-learn
On Tuesday, 2 April 2019 at 09:37:26 UTC, Per Nordlöw wrote: Are there any plans on deprecating implicit conversions of enums to integers? Not that I know of. Given the precedence of this: https://github.com/dlang/DIPs/blob/master/DIPs/rejected/DIP1015.md I doubt enum/integer-types are going

Re: Forbidding implicit conversions from an enum type to an integer

2019-04-02 Thread Dennis via Digitalmars-d-learn
On Tuesday, 2 April 2019 at 08:38:28 UTC, Per Nordlöw wrote: Is there a way (compiler flag) to forbid implicit conversions from an enum type to integer types? You can make the enum type not an integer type. ``` struct Int{int i;} enum E: Int { first = Int(0), second = Int(1), } ```

Re: Block statements and memory management

2019-03-16 Thread Dennis via Digitalmars-d-learn
On Saturday, 16 March 2019 at 03:47:43 UTC, Murilo wrote: Does anyone know if when I create a variable inside a scope as in {int a = 10;} it disappears complete from the memory when the scope finishes? Or does it remain in some part of the memory? I am thinking of using scopes to make

Re: bug in doc?

2019-03-14 Thread Dennis via Digitalmars-d-learn
On Thursday, 14 March 2019 at 19:46:30 UTC, spir wrote: But the doc (the language ref for the matter) should definitely say what you just explained above, shouldn't they? Well arguably, the spec should detail the language semantics formally and not just be a description of the reference

Re: Applying a function each respective 2 elements of an array

2019-03-10 Thread Dennis via Digitalmars-d-learn
On Sunday, 10 March 2019 at 08:59:59 UTC, kerdemdemir wrote: Can I avoid for loops and solve my problem with std algorithms or ranges ? Try slide: https://dlang.org/phobos/std_range.html#slide And then use map.

Re: Aliasing a mixin (or alternative ways to profile a scope)

2019-03-09 Thread Dennis via Digitalmars-d-learn
On Friday, 8 March 2019 at 11:42:11 UTC, Simon wrote: Thanks, this works flawlessly. Out of interest: what is the "enum" doing there? I had the exact same behaviour in a function before, that I only called at compile-time, so why did it complain then? Can I somehow tell the compiler that a

Re: Why is SwitchError an error and how is it unsafe to continue after catching it?

2019-02-24 Thread Dennis via Digitalmars-d-learn
On Sunday, 24 February 2019 at 10:53:09 UTC, aliak wrote: But the following code is very recoverable and I don't see how it's unsafe to continue executing: There is no guarantee that a final switch throws an Error. From what I've heard of Walter [1] (though I can't find it in the spec), the

Re: How to convert `std.datetime.Duration` to seconds of floating point type?

2019-02-19 Thread Dennis via Digitalmars-d-learn
On Tuesday, 19 February 2019 at 14:34:09 UTC, drug wrote: Now I do it this way (https://run.dlang.io/is/8kVibT): ``` auto some_duration = dur!"msecs"(500); auto seconds = some_duration.total!"hnsecs" / 10_000_000.0; assert(seconds.approxEqual(0.5)); ``` is there better

Re: Casting int[] to ubyte[]: element wise cast or slice cast

2019-02-15 Thread Dennis via Digitalmars-d-learn
On Friday, 15 February 2019 at 17:18:28 UTC, H. S. Teoh wrote: Why? because that's the only case where you can reinterpret the .sizeof*.length bytes as an array of a different type. There is no conversion, the cast works as a reinterpretation. It's by design. But my problem is that it

Casting int[] to ubyte[]: element wise cast or slice cast

2019-02-15 Thread Dennis via Digitalmars-d-learn
I assumed that casting an int[] to a ubyte[] would keep all bytes and quadruple the length of the original array. But when the array is a literal, it keeps the same length but truncates every int element to a ubyte: ``` import std.stdio; void main() { // enum: enum litA =

Re: Handling big FP numbers

2019-02-10 Thread Dennis via Digitalmars-d-learn
On Sunday, 10 February 2019 at 20:25:02 UTC, Murilo wrote: It seems this is a feature of D I will have to get used to and accept the fact I can't always get the same number as in C What compilers and settings do you use? What you're actually comparing here are different implementations of the

Re: UTFException when reading a file

2019-01-11 Thread Dennis via Digitalmars-d-learn
On Friday, 11 January 2019 at 19:45:05 UTC, Head Scratcher wrote: How can I read the file and convert the string into proper UTF-8 in memory without an exception? You have multiple options: ``` import std.file: read; import std.encoding: transcode, Windows1252String; auto ansiStr =

Re: Some Fundamental Paradigm Questions

2018-12-21 Thread Dennis via Digitalmars-d-learn
The most fundamental problem that these features tackle is that code is costly, so making code-bases smaller and more reusable saves effort spent on maintaining large code-bases and rewriting code to suit a different situation. On Friday, 21 December 2018 at 12:39:48 UTC, Ron Tarrant wrote:

Re: Calling function explicitly from mixin template results in recursive call instead

2018-12-10 Thread Dennis via Digitalmars-d-learn
On Monday, 10 December 2018 at 21:16:23 UTC, aliak wrote: Does this fix your issue? struct S { mixin operators ops; S opBinary(string op, T)(T a) { alias opBinary = ops.opBinary; // explicitly alias opBinary in this scope return opBinary!op(a); } } It does,

Re: Calling function explicitly from mixin template results in recursive call instead

2018-12-10 Thread Dennis via Digitalmars-d-learn
On Sunday, 9 December 2018 at 18:36:50 UTC, Dennis wrote: Does anyone know how to get this working? I added this to the mixin template: ``` alias mixinOpBinary = opBinary; ``` And called mixinOpBinary instead in the forwarded function. I think that solved it. I think I'll just file an issue

Calling function explicitly from mixin template results in recursive call instead

2018-12-09 Thread Dennis via Digitalmars-d-learn
I'm using Adam's workaround from https://issues.dlang.org/show_bug.cgi?id=19365, but now I have endless recursion. Reduced code: ``` mixin template operators() { S opBinary(string op: "+")(S rhs) { return rhs; } // (A) auto opBinary(string op, T)(T rhs) if (false) {

Re: std.algorithm.canFind behavior difference between arrays and elements

2018-12-07 Thread Dennis via Digitalmars-d-learn
On Friday, 7 December 2018 at 18:51:27 UTC, Arun Chandrasekaran wrote: Why is there a difference in the behavior? Your first assert expression is looking for a string in a larger string, your second expression looks for hay which is not a string but a string[]. To flatten the array, use:

Re: Ambiguous virtual function

2018-12-06 Thread Dennis via Digitalmars-d-learn
On Thursday, 6 December 2018 at 07:37:12 UTC, John Chapman wrote: Is the compiler giving the non-mixed-in function special treatment? I think you're running into this bug: https://issues.dlang.org/show_bug.cgi?id=19365 I see that it is not limited to operator overloading, in general the

Re: Initialize static array without explicit length

2018-12-03 Thread Dennis via Digitalmars-d-learn
On Monday, 3 December 2018 at 10:00:31 UTC, Simen Kjærås wrote: However, it's easy to implement in a library: It even is in phobos: https://dlang.org/phobos/std_array.html#.staticArray ``` import std.array: staticArray; auto a = [0, 1, 2].staticArray; ```

Re: difficulties with const structs and alias this / template functions

2018-11-19 Thread Dennis via Digitalmars-d-learn
On Monday, 19 November 2018 at 13:34:50 UTC, Stanislav Blinov wrote: Because it's not mutation, it's initialization. Oh. That's an epiphany for me. When a ctor is `pure`, the compiler knows it doesn't mutate any state other than the object's, so it allows conversion to all three

Re: difficulties with const structs and alias this / template functions

2018-11-19 Thread Dennis via Digitalmars-d-learn
On Monday, 19 November 2018 at 02:39:32 UTC, Stanislav Blinov wrote: You're skimming the examples ;) I'm not saying your examples don't work, I'm trying to understand the minimum requirements. You said: "That's [constructors needing to be pure is] only for types with indirections

Re: difficulties with const structs and alias this / template functions

2018-11-18 Thread Dennis via Digitalmars-d-learn
On Monday, 19 November 2018 at 01:24:02 UTC, Stanislav Blinov wrote: Yup, that's because, like Rubn said, copying value types is trivial. Where it all comes to bite you is when you start having pointers, because you can't copy a const(T)* into a T*. I'm not using reference types, but still:

Re: difficulties with const structs and alias this / template functions

2018-11-18 Thread Dennis via Digitalmars-d-learn
On Monday, 19 November 2018 at 01:13:29 UTC, Stanislav Blinov wrote: You just dismissed that second to last sentence, did you? :) I don't know what you mean with it. It's not that I'm trying to be sneaky or lazy really trying to modify the const parameter when I should treat it properly. And

Re: difficulties with const structs and alias this / template functions

2018-11-18 Thread Dennis via Digitalmars-d-learn
On Sunday, 18 November 2018 at 22:30:52 UTC, Rubn wrote: Yah most people tend to avoid const for this reason. It only really works for basic types, if you have a "const int" you can convert it to an "int" by copy. But if you have a type like Vector!(const int) that won't work, you can't even

Re: difficulties with const structs and alias this / template functions

2018-11-18 Thread Dennis via Digitalmars-d-learn
On Sunday, 18 November 2018 at 18:17:54 UTC, Stanislav Blinov wrote: // implement separate methods for mutable/const/immutable Thanks. I should have tried that, but I assumed it wouldn't work since you can't overload on return-type only. However, the const / non-const makes it

difficulties with const structs and alias this / template functions

2018-11-18 Thread Dennis via Digitalmars-d-learn
I'm making a fixed point numeric type and want it to work correctly with const. First problem: ``` const q16 a = 6; a /= 2; // compiles! despite `a` being const. writeln(a); // still 6 a.toQ32 /= 2;// what's actually happening ``` My q16 type has an implicit conversion to q32

Re: Fields with the same name not causing a warning?

2018-11-16 Thread Dennis via Digitalmars-d-learn
On Friday, 16 November 2018 at 20:13:42 UTC, Vinay Sajip wrote: More complicated for the compiler writers, or users of mixins/generics? For users of generics. It's hard to come up with an actual example because I don't know why one would ever use this, but in this concocted scenario: ```

Re: Fields with the same name not causing a warning?

2018-11-16 Thread Dennis via Digitalmars-d-learn
On Friday, 16 November 2018 at 18:37:00 UTC, Vinay Sajip wrote: Design flaws in what? Design flaws in the language. Quoting Jonathan M Davis: "Honestly, in general, warnings are a terrible idea. Anything that's a warning in your code has to be fixed, because it's bad practice to leave

Re: Differences between group() and chunkBy()

2018-11-14 Thread Dennis via Digitalmars-d-learn
On Wednesday, 14 November 2018 at 12:28:38 UTC, Per Nordlöw wrote: Is it because of `group` has a default for the predicate whereas `chunkBy` hasn't. chunkBy splits the range into smaller ranges, group actually returns tuples of the item and the amount of occurences. Because in group the

Re: linker warnings and errors with bindbc-glfw

2018-11-09 Thread Dennis via Digitalmars-d-learn
On Friday, 9 November 2018 at 19:40:15 UTC, Mike Parker wrote: When you link statically with a library, you have to link with all of its dependencies, too. For GLFW, you'll need User32.lib, gdi32.lib, and OpenGL32.lib, off the top of my head. Aha. Now I wonder why LDC includes those

Re: linker warnings and errors with bindbc-glfw

2018-11-09 Thread Dennis via Digitalmars-d-learn
On Friday, 9 November 2018 at 19:21:30 UTC, kinke wrote: May be worth another try with the proper command line. Thank you! LDC + LD now works without warnings. On Friday, 9 November 2018 at 19:21:30 UTC, kinke wrote: Run LDC or DMD with `-v`, that gives you the linker command line at the end

Re: linker warnings and errors with bindbc-glfw

2018-11-09 Thread Dennis via Digitalmars-d-learn
On Friday, 9 November 2018 at 18:19:22 UTC, Dennis wrote: [...] I just noticed in the section about the static version: "This requires the GLFW development package be installed on your system at compile time." http://code.dlang.org/packages/bindbc-glfw I don't see where I can install the

linker warnings and errors with bindbc-glfw

2018-11-09 Thread Dennis via Digitalmars-d-learn
I'm trying the static bindings for glfw of bindbc on Windows, using the pre-compiled .lib files from the lib-vc2015 folder in the official download. (http://code.dlang.org/packages/bindbc-glfw) With LDC using the Microsoft MSCV linker, everything works. I can either add this: app.d: ```

Re: Using decodeFront with a generalised input range

2018-11-09 Thread Dennis via Digitalmars-d-learn
On Friday, 9 November 2018 at 10:45:49 UTC, Vinay Sajip wrote: As I see it, a ubyte 0x20 could be decoded to an ASCII char ' ', and likewise to wchar or dchar. It doesn't (to me) make sense to decode a char to a wchar or dchar. Anyway, you've shown me how decodeFront can be used, so great!

Re: Using decodeFront with a generalised input range

2018-11-09 Thread Dennis via Digitalmars-d-learn
On Friday, 9 November 2018 at 09:47:32 UTC, Vinay Sajip wrote: std.utf.decodeFront(Flag useReplacementDchar = No.useReplacementDchar, S)(ref S str) if (isInputRange!S && isSomeChar!(ElementType!S)) This is the overload you want, let's check if it matches: ref S str - your InputRange can be

Re: How do I install a library?

2018-11-08 Thread Dennis via Digitalmars-d-learn
On Thursday, 8 November 2018 at 23:43:38 UTC, Murilo wrote: It finally worked, but I can't just compile it normally, I have to use dub run, I wish it were something simple that I just download into the folder and then use an import statement and then compile it like any other program. I wish

Re: Putting dmd error through grep for dustmite

2018-11-05 Thread Dennis via Digitalmars-d-learn
On Monday, 5 November 2018 at 03:13:26 UTC, Vladimir Panteleev wrote: cmd.exe will interpret \` verbatim (i.e. as \`), so, try not quoting the ` characters (or just replace them with . if you want the command to work in both shells). Of course, the one thing I didn't try. Thanks!

Putting dmd error through grep for dustmite

2018-11-04 Thread Dennis via Digitalmars-d-learn
I am debugging a case where operator overloading seems to break when I define the opBinary templates in a mixin template. On my own simple test-case it worked fine, so I'm trying to reduce my current code with dustmite. The file tree is simply: myproject/ q16.d And the command I run is:

Re: Dealing with ranges where front and popFront do the same logic / eager ranges

2018-10-17 Thread Dennis via Digitalmars-d-learn
On Wednesday, 17 October 2018 at 00:12:13 UTC, H. S. Teoh wrote: I'm not sure what's the reasoning behind the saying that throwing exceptions in ctors is bad, but exceptions are exactly the kind of thing designed for handling this sort of situation. If the parser detects a problem early (i.e.,

Re: why is the default floating point value NAN ?

2018-10-17 Thread Dennis via Digitalmars-d-learn
On Wednesday, 17 October 2018 at 15:51:21 UTC, Codifies wrote: okay I should have carried on reading the blog, its so uninitialized values stick out when debugging... Indeed, the initial value is not supposed to be useful, it's there because dealing with garbage memory when forgetting to

Dealing with ranges where front and popFront do the same logic / eager ranges

2018-10-16 Thread Dennis via Digitalmars-d-learn
I've always been curious around the design choice of ranges to make front and popFront separate functions, instead of having popFront return the front. I suppose it is useful sometimes to be able to access front multiple times without having to save it temporarily (can't think of a specific

Re: Alligned gc allocation of struct

2018-10-05 Thread Dennis via Digitalmars-d-learn
On Friday, 5 October 2018 at 10:03:35 UTC, Kagamin wrote: GC allocations are 16 bytes aligned. Is that an implementation detail or well-defined behavior?

Re: Simple parallel foreach and summation/reduction

2018-09-21 Thread Dennis via Digitalmars-d-learn
On Friday, 21 September 2018 at 07:25:17 UTC, Chris Katko wrote: I get "Error: template instance `reduce!((a, b) => a + b)` cannot use local __lambda1 as parameter to non-global template reduce(functions...)" when trying to compile that using the online D editor with DMD and LDC. Any ideas?

Re: "immutable string" vs "const string*"

2018-09-09 Thread Dennis via Digitalmars-d-learn
On Sunday, 9 September 2018 at 08:41:37 UTC, Christian Mayer wrote: As of my current understanding "char" will create a new variable and copy the content of the original to the new variable. "char*" will just use the pointer. And "const char*" is good for when not modifying. But I also can

Re: anyway to debug nogc code with writeln?

2018-09-02 Thread Dennis via Digitalmars-d-learn
On Saturday, 1 September 2018 at 21:53:03 UTC, aliak wrote: Anyway around this? I don't know if your situation allows it, but you can mark f explicitly as always @nogc. If your design assumes that it's @nogc, it's a good idea to add the attribute anyway. You can also use the C printf

<    1   2   3   4   >