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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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 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: 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: 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 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

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: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: 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: 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

Re: Some impressions/notes from a new D programmer

2020-02-12 Thread Dennis via Digitalmars-d-learn
Thanks for your perspective. Just a few things are unclear to me: On Wednesday, 12 February 2020 at 10:39:06 UTC, mark wrote: I don't find the presentation of the member properties and methods very easy to read Can you elaborate a bit on this? The lack of set and B-tree types is

Re: dscanner and ref parameters

2020-02-23 Thread Dennis via Digitalmars-d-learn
On Sunday, 23 February 2020 at 09:03:56 UTC, mark wrote: Then this would not only help dscanner, but also make it clear to programmers that the argument could be modified. (This is done in Rust with f( arg), and I certainly find it helpful.) C# also does it, and uses exactly the same

Re: converting to/from char[]/string

2020-03-05 Thread Dennis via Digitalmars-d-learn
On Thursday, 5 March 2020 at 11:31:43 UTC, mark wrote: I've now got Martin Porter's own Java version, so I'll have a go at porting that to D myself. I don't think that's necessary, the errors seem easy to fix. src/porterstemmer.d(197,13): Error: cannot implicitly convert expression s.length

Re: list of all defined items in a D file

2020-01-24 Thread Dennis via Digitalmars-d-learn
On Thursday, 23 January 2020 at 17:10:29 UTC, berni44 wrote: I'd like to get a list of all items (public, package, private) that are defined in a D file. Is there a simple way, to get them? You can pass the -X flag to dmd, which makes it generate a .json file describing the compiled file.

Cannot take slice of scope static array in @safe code

2020-02-02 Thread Dennis via Digitalmars-d-learn
Compiling the following with -dip1000 gives an error. ``` void main() @safe { string[1] a0; scope int[1] a1; scope string[1] a2; scope string[] b0 = a0[]; // Fine scope int[] b1 = a1[]; // Fine scope string[] b2 = a2[]; // Error: cannot take address of scope local a2 }

Re: Cannot take slice of scope static array in @safe code

2020-02-02 Thread Dennis via Digitalmars-d-learn
Thanks for your response. On Sunday, 2 February 2020 at 15:20:39 UTC, ag0aep6g wrote: Now it's important to realize that `scope` only applies to the top-level of the type. This is where my confusion was. I knew scope wasn't transitive, so I thought that `scope string[1]` meant the static

Re: Cannot take slice of scope static array in @safe code

2020-02-02 Thread Dennis via Digitalmars-d-learn
On Sunday, 2 February 2020 at 18:18:28 UTC, Steven Schveighoffer wrote: scope should have been a type constructor. I feel the same way, I find const/immutable much easier to reason about than scope in its current state. Do you think scope as a storage class is fundamentally broken, or is it

Re: const pointers C vs. D

2020-02-04 Thread Dennis via Digitalmars-d-learn
On Tuesday, 4 February 2020 at 10:06:03 UTC, Johann Lermer wrote: In C, this would not be valid. So the question for me now is: is const char* in D different from C? Yes, const char* in D reads as const(char*), so it is a char* that cannot be modified. This is similar to the C code: char

Flatten a range of static arrays

2020-02-07 Thread Dennis via Digitalmars-d-learn
If I have an input range with element type `int[3]`, how do I easily turn it into a range of `int` so I can map it? If it were an int[3][] I could simply cast it to an int[] before mapping, but I don't want to eagerly turn it into an array. I thought of doing this: ``` range.map!(x =>

Re: Flatten a range of static arrays

2020-02-07 Thread Dennis via Digitalmars-d-learn
On Friday, 7 February 2020 at 20:55:14 UTC, nullptr wrote: Depending on how your range is structured, it might be possible to just mark front as returning by ref to make this work. That's a good one. I can't make front() return by ref, but I can make front a member variable of the range

Re: Flatten a range of static arrays

2020-02-07 Thread Dennis via Digitalmars-d-learn
On Friday, 7 February 2020 at 20:31:47 UTC, Steven Schveighoffer wrote: The only solution I can provide is to wrap the static array into a range (maybe something like this exists in Phobos?): Thanks. I was hoping something like that existed in Phobos, but I can't find anything.

Re: Flatten a range of static arrays

2020-02-07 Thread Dennis via Digitalmars-d-learn
On Friday, 7 February 2020 at 21:40:36 UTC, Steven Schveighoffer wrote: S.popFront is not @safe, and S is not a template. So no inferrence. Oops, minimized a bit too much. Corrected test case: ``` import std; struct S { @safe: int[3] front = [10, 20, 30]; bool empty = false;

Re: Conditional Attributes

2020-02-20 Thread Dennis via Digitalmars-d-learn
On Tuesday, 18 February 2020 at 17:11:55 UTC, Marcel wrote: Say I have a struct where every member function can either be static or not depending on a template parameter. Is there a simple way to do this? The best I can think of is: ``` mixin template maybeStatic() { void foo() {

Re: Speeding up compilation of template-heavy code

2020-02-22 Thread Dennis via Digitalmars-d-learn
On Saturday, 22 February 2020 at 11:26:19 UTC, Per Nordlöw wrote: Is there a dmd flag that shows the code after template instantiations has been performed? The -vcg-ast flag does that.

Re: State of MIPS

2020-02-19 Thread Dennis via Digitalmars-d-learn
On Wednesday, 19 February 2020 at 07:09:02 UTC, April wrote: What's the current state of MIPS compiling for bare metal? Especially the R4300i processor. I've had some success with running D code on Nintendo 64 emulators, which emulate a R4300i processor. I'm compiling with: ldc2 -march=mips

Re: Win32 Api: How create a Color Dialog?

2020-01-09 Thread Dennis via Digitalmars-d-learn
On Thursday, 9 January 2020 at 13:04:33 UTC, Marcone wrote: I am creating a GUI using winsamp.d as model. See the window here: https://i.ibb.co/ZJ4v2KD/Sem-t-tulo.png I want to ask a user for choose a color when click Configuration/Color, and then change backgroud color of GUI. But how can I

Re: @safe std.file.read

2020-01-06 Thread Dennis via Digitalmars-d-learn
I would say it should return a ubyte[]. On Monday, 6 January 2020 at 10:07:37 UTC, WebFreak001 wrote: Or should void[] actually be castable to ubyte[] in @safe code? Definitely not with the current semantics, since a void[] can alias pointers in @safe code. See:

Re: Cool name for Dub packages?

2020-03-07 Thread Dennis via Digitalmars-d-learn
On Saturday, 7 March 2020 at 10:49:24 UTC, Paolo Invernizzi wrote: Frankly, I simply hate all that shuffle around names ... I remember someone noting how unusual it is for D to have a name for its standard library, "Phobos".

Re: To get memory from another process.

2020-04-09 Thread Dennis via Digitalmars-d-learn
On Thursday, 9 April 2020 at 17:23:19 UTC, Quantium wrote: Ok. For training example, we're using Windows 10 Por. We can use WinAPI. Are there any D libs to use WinAPI? I have used the Windows API to read/write into a different process before. Here is some example code in case it's useful: (I

Re: To get memory from another process.

2020-04-09 Thread Dennis via Digitalmars-d-learn
On Thursday, 9 April 2020 at 19:27:16 UTC, Quantium wrote: I see this code imports drivers and does it depend on processor architecture? Would it work only on 64-bit or 32-bit or some special architechtures? kernel32.dll and psapi.dll should be present on any normal Windows 10 installation.

Re: Does anyone have gdb pretty printers for buildin types like associative arrays?

2020-03-15 Thread Dennis via Digitalmars-d-learn
On Sunday, 15 March 2020 at 16:42:52 UTC, Panke wrote: Should this just work and by box is not correctly configured or do I need some pretty printers? If so, has someone already made them? Take a look at: https://forum.dlang.org/post/ztyhmmxalpiysgjkv...@forum.dlang.org

Re: Integer without restrictions

2020-03-15 Thread Dennis via Digitalmars-d-learn
On Sunday, 15 March 2020 at 19:07:05 UTC, ... wrote: And if I need to create very large value, how to use GMP library (It isn't described in that post)? You can use C bindings [1], look up examples in C and do the same in D, or use a high-level wrapper [2]. [1]

Re: Whats wrong with binery heap or i am not understand something?

2020-04-02 Thread Dennis via Digitalmars-d-learn
On Thursday, 2 April 2020 at 12:59:06 UTC, AlexM wrote: Please explain me whats wrong with binery heap?!!! This has nothing to do with binaryheap and all to do with writeln. writeln recognizes b and h as ranges, and prints them by iterating over each element, which advances the range to the

Re: Whats wrong with binery heap or i am not understand something?

2020-04-02 Thread Dennis via Digitalmars-d-learn
On Thursday, 2 April 2020 at 13:23:29 UTC, Dennis wrote: writeln recognizes b and h as ranges, and prints them by iterating over each element, Correction: this only applies to `h`, the array slice `b` will not be mutated by writeln.

Re: How to code Z-Function of string?

2020-03-26 Thread Dennis via Digitalmars-d-learn
On Thursday, 26 March 2020 at 19:34:08 UTC, Quantium wrote: 1. How can I make string ONLY char[] (Not immutable) You can use .dup to make a mutable copy of an array. ``` char[] a = "abc".dup; ``` 2. How can I work with some of chars in the stirng, is, for example: string s="abc";

Re: Is there a way to benchmark/profile portably?

2020-05-07 Thread Dennis via Digitalmars-d-learn
On Thursday, 7 May 2020 at 10:21:07 UTC, Dukc wrote: Is there some way to measure the performance of a function so that the results will be same in different computers (all x86, but otherwise different processors)? I'm thinking of making a test suite that could find performance regressions

Re: DScanner warns class is undocumented, how to resolve it ?

2020-05-14 Thread Dennis via Digitalmars-d-learn
On Thursday, 14 May 2020 at 06:08:17 UTC, Vinod K Chandran wrote: On Thursday, 14 May 2020 at 06:05:00 UTC, Vinod K Chandran wrote: Hi all, I wrote a class and in VS Code, DScanner says that the class is undocumented. How can i document a class ? Never mind, i found the answer myself. Just

Re: Can You Expand Arrays into an Argument List?

2020-05-15 Thread Dennis via Digitalmars-d-learn
On Friday, 15 May 2020 at 19:19:59 UTC, H. S. Teoh wrote: Here's how to do it: int add(int[] args...) { ... // access `args` here as an array } Beware that that language feature, typesafe variadic functions, might become deprecated:

Re: Best way to learn 2d games with D?

2020-03-17 Thread Dennis via Digitalmars-d-learn
On Sunday, 15 March 2020 at 17:58:58 UTC, Steven Schveighoffer wrote: I want to try and learn how to write 2d games. I'd prefer to do it with D. I haven't seen anyone mention Dgame yet: https://github.com/Dgame/Dgame It's not maintained anymore since last November [1], but is seems pretty

Re: Best way to learn 2d games with D?

2020-03-17 Thread Dennis via Digitalmars-d-learn
On Tuesday, 17 March 2020 at 22:47:43 UTC, Sebastiaan Koppe wrote: Dont trust that marketing, there is actually decent scripting in gamemaker, which you'll need if you get creative. Second that. GameMaker is how I got into programming at age 12, and look where I ended up ;)

Re: return val if

2020-03-22 Thread Dennis via Digitalmars-d-learn
On Sunday, 22 March 2020 at 18:48:32 UTC, Abby wrote: Is there a way to create a template that would do the same is glib g_return_val_if_fail() (https://developer.gnome.org/glib/stable/glib-Warnings-and-Assertions.html#g-return-val-if-fail) I'm not famililar with glib, but the description:

Re: Best way to confine project to 64 bit builds only?

2020-10-17 Thread Dennis via Digitalmars-d-learn
On Saturday, 17 October 2020 at 14:50:47 UTC, NonNull wrote: I have inherited an open source C project that assumes that the size of a long and the size of a pointer are the same, and I have translated it into very similar D just like

Re: What's the best way to find out which exceptions may be thrown ?

2020-05-27 Thread Dennis via Digitalmars-d-learn
On Wednesday, 27 May 2020 at 09:56:07 UTC, wjoe wrote: The problem with catch(Exception) is that it's run time whereas I'd like to know compile time which exception may possibly be thrown. Note that this is impossible in general due to the nature of classes. A function could at runtime find

Re: How to parse enum from a string ?

2020-05-27 Thread Dennis via Digitalmars-d-learn
On Wednesday, 27 May 2020 at 17:33:33 UTC, Vinod K Chandran wrote: I am saving this enum values as string in database. So, when i retrieve them from the database, how can i parse the string into TestEnum ? Use `to` from `std.conv`. ``` import std.conv: to; void main() {

Re: Neater "not version (...)" ?

2020-09-16 Thread Dennis via Digitalmars-d-learn
On Wednesday, 16 September 2020 at 19:04:24 UTC, Vladimirs Nordholm wrote: Ah, I guess it boils down to this then. Doesn't really make it "neater", but thank you for the tip! IMO, just keep it as `version(Windows) {} else { ... }` if you HAVE to instead of one of the workarounds people

Re: alias restriction??!

2020-07-18 Thread Dennis via Digitalmars-d-learn
On Saturday, 18 July 2020 at 18:46:16 UTC, Carl Sturtivant wrote: Is there any way to avoid the duplication of the entries in the anonymous union, aside from using a mixin template? I think this would be fixed if https://github.com/dlang/dmd/pull/11273 gets merged.

Re: How does one run a linux system command from a D main() fcn ?

2020-08-04 Thread Dennis via Digitalmars-d-learn
On Tuesday, 4 August 2020 at 19:52:47 UTC, Andy Balba wrote: i.e. D equivalent to C++ command system("MyExe") Apart from std.process, you can also call the C function in D after importing core.stdc.stdlib: https://dlang.org/library/core/stdc/stdlib/system.html

Re: dlib 0.19.1 seems to be failing linking with ldc2

2020-07-31 Thread Dennis via Digitalmars-d-learn
On Friday, 31 July 2020 at 14:17:14 UTC, jeff thompson wrote: dlib.lib(dlib.audio.io.wav.obj) : error LNK2019: unresolved external symbol _D4core8internal7switch___T14__switch_errorZQrFNaNbNiNfAyamZv referenced in function

Re: Print only part of a stack trace

2020-07-01 Thread Dennis via Digitalmars-d-learn
On Wednesday, 1 July 2020 at 18:44:10 UTC, Stanislav Blinov wrote: void assertNoOpenGLErrors(string file = __FILE__, int line = __LINE__, string func = __PRETTY_FUNCTION__) { if (glGetError() != GL_NO_ERROR) { print(file, ":", line, ":", func, ": blah"); exit(); } } :)

Re: Print only part of a stack trace

2020-07-01 Thread Dennis via Digitalmars-d-learn
On Wednesday, 1 July 2020 at 18:54:55 UTC, Dennis wrote: It sort of works, but it seems it does not start at the right stack frame, the top item is this: ??:? void rt.dmain2._d_run_main2(char[][], ulong, extern (C) int function(char[][])*).runAll().__lambda1() [0x55c19a09c1fa] So dmd skips

Re: Print only part of a stack trace

2020-07-01 Thread Dennis via Digitalmars-d-learn
On Wednesday, 1 July 2020 at 18:05:09 UTC, Jacob Carlborg wrote: [1] https://dlang.org/phobos/core_runtime.html#.Runtime.traceHandler Thanks, but I don't want to re-implement the default trace handler, I want to use it on a specific location and capture its output. I'll be more specific in

Re: Print only part of a stack trace

2020-07-01 Thread Dennis via Digitalmars-d-learn
On Wednesday, 1 July 2020 at 19:33:08 UTC, JN wrote: Bit off-topic, but if you can use them, debug contexts offer much better OpenGL error-checking experience. https://www.khronos.org/opengl/wiki/Debug_Output . Instead of checking glGetError() after each call, you can setup a C callback that

Print only part of a stack trace

2020-07-01 Thread Dennis via Digitalmars-d-learn
On assertion failure, the default error handler prints a stack trace that looks like this [library functions] [application functions] [druntime start-up functions] I'm only interested in application functions, the rest is noise. I could easily filter unwanted lines out if I had the stack trace

Re: How to work Get & Set text in clipboard in Windows ?

2020-06-20 Thread Dennis via Digitalmars-d-learn
On Saturday, 20 June 2020 at 13:32:22 UTC, Vinod K Chandran wrote: I would like to know how to get & set text in clipboard. I am using windows machine. This is an example of setting the clipboard using the Windows API in D: ``` /// Returns: true on success bool setClipboard(string str) {

Re: Templates and SIMD - examining types

2020-07-22 Thread Dennis via Digitalmars-d-learn
On Wednesday, 22 July 2020 at 21:58:16 UTC, Cecil Ward wrote: I need to then work out what is the size of the internal units within the 128-bit value, size in bytes,1 or 2, at compile time. You can use the .sizeof property on the type. ``` import core.simd; void main() { ubyte16 a;

Re: Ways to parse D code.

2020-11-25 Thread Dennis via Digitalmars-d-learn
On Wednesday, 25 November 2020 at 16:27:41 UTC, Jan Hönig wrote: What is the "easiest" way to parse D code? (...) libdparse seems to do it as well with `parseModule` function. https://github.com/dlang-community/libdparse/blob/master/src/dparse/parser.d I recommend libdparse. dmd has to do it

Re: Using multiple mixin templates to implement operator overloading

2020-12-12 Thread Dennis via Digitalmars-d-learn
On Saturday, 12 December 2020 at 18:14:31 UTC, Paul Backus wrote: IMO this is one of the stupider design decisions in D, but it's unlikely it will ever be fixed. The easiest workaround is to use string mixins instead, which work the way you'd expect them to. If issue 19365 got fixed, it

Re: is type checking in D undecidable?

2020-10-22 Thread Dennis via Digitalmars-d-learn
On Thursday, 22 October 2020 at 17:25:44 UTC, Bruce Carneal wrote: Is type checking in D undecidable? Per the wiki on dependent types it sure looks like it is. It is indeed undecidable. Imagine you had a decider for it. Because CTFE is clearly turing-complete, you can express that in a D

Re: Source code folder naming convention?

2020-11-04 Thread Dennis via Digitalmars-d-learn
On Wednesday, 4 November 2020 at 11:15:33 UTC, Vladimirs Nordholm wrote: Is there a "best practice" of what the source folder should be called? `dub init` creates a folder named `source`, so I would stick with that.

Re: How can I check to see if template type is an array?

2021-01-19 Thread Dennis via Digitalmars-d-learn
On Tuesday, 19 January 2021 at 22:26:52 UTC, Tim wrote: I need to be able to check in a template whether the type given is an array type so that I can do some different logic. How can I do this? `if(is(T == E[], E))` or `isDynamicArray!T` is you `import std.traits;`

Re: Open question: what code pattern you use usually for null safety problem

2021-01-14 Thread Dennis via Digitalmars-d-learn
On Thursday, 14 January 2021 at 18:24:44 UTC, ddcovery wrote: If it's not a bother, I'd like to know how you usually approach it Usually I don't deal with null because my functions get primitive types, slices, or structs. `ref` parameters can be used to replace pointers that may not be null.

Re: Is there a way to work with processes in Windows without extern(c)?

2021-01-13 Thread Dennis via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 14:04:52 UTC, dog2002 wrote: I could use extern(c) and Process Walking (Process32First, Process32Next), but maybe there is a way to get the list by means of D? I don't think this is part of the standard library. Here's a piece of code I wrote a while ago if

Re: Why am I getting a dividing by zero error message

2021-01-28 Thread Dennis via Digitalmars-d-learn
On Thursday, 28 January 2021 at 18:37:37 UTC, Ruby The Roobster wrote: object.Error@(0): Integer Divide by Zero Why is this happening? Does anybody know? data[0] = (new egg(0,0,"a")); Here you set data[0].y to 0 tempb = data[x].y; In the first iteration, this equals data[0].y which

Re: What is this undefined reference with -betterC about?

2021-06-16 Thread Dennis via Digitalmars-d-learn
On Wednesday, 16 June 2021 at 16:27:13 UTC, Dennis wrote: It has to be a linker error, dmd cannot know at the time of compiling project A how project B is going to be compiled and vice versa. Well I suppose you could use a specific dub configuration, maybe giving 'hostname' a targetType

Re: What is this undefined reference with -betterC about?

2021-06-16 Thread Dennis via Digitalmars-d-learn
On Wednesday, 16 June 2021 at 14:38:10 UTC, jfondren wrote: What do I change to 1. a script like this that uses hostname 2. the hostname module so that both can be built with -betterC when and only when the script is using -betterC? That's currently the situation: you can only build when both

Re: Flaoting point operations : unexpected results

2021-06-10 Thread Dennis via Digitalmars-d-learn
On Thursday, 10 June 2021 at 19:37:36 UTC, seany wrote: However, i sometimes see, that the results are _radically_ different. Are you using uninitialized memory or multi-threading?

Re: semi-final switch?

2021-06-17 Thread Dennis via Digitalmars-d-learn
On Thursday, 17 June 2021 at 21:41:28 UTC, Steven Schveighoffer wrote: Any ideas on better ways to handle this? I've had such a situation before too where I want to switch over enums I read from an ELF file which can't be assumed to be correct, but I also don't want to forget one. For a

Re: BetterC, int to string?

2021-06-18 Thread Dennis via Digitalmars-d-learn
On Friday, 18 June 2021 at 09:05:38 UTC, Mike Brown wrote: im doing this in a compile time function as well. If it's a compile time string you can use mixin()

Re: How to I get pointer to an Array and cast to a void * and back ?

2021-06-24 Thread Dennis via Digitalmars-d-learn
On Thursday, 24 June 2021 at 14:06:11 UTC, seany wrote: void f() { a[] * rd; // DO SOME WORK HERE this.dataSet = & rd_flattened; rd = cast (a [] *) dataSet; write("length of rd is : "); writeln((*rd).length); // <--- this works.. // do some work

Re: How to translate this C macro to D mixin/template mixin?

2021-06-15 Thread Dennis via Digitalmars-d-learn
On Tuesday, 15 June 2021 at 12:18:26 UTC, VitaliiY wrote: It's simple with STARTDATA as mixin, but STOREBITS and ADDBITS use variables defined in STARTDATA scope, so I can't understand how to do mixin template with it. If the code duplication isn't too bad, consider just expanding the C

Re: difficulty with rectangular arrays

2021-06-11 Thread Dennis via Digitalmars-d-learn
On Friday, 11 June 2021 at 08:30:29 UTC, Moth wrote: what's going on? It's a bug: [Issue 19178 - Static initialization of 2d static arrays in structs produces garbage or doesn't compile sometimes](https://issues.dlang.org/show_bug.cgi?id=19178)

<    1   2   3   4   >