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

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

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

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

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

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

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

  1   2   >