Re: Phobos Unittest

2021-09-04 Thread Dennis via Digitalmars-d-learn
On Saturday, 4 September 2021 at 09:42:46 UTC, Per Nordlöw wrote: Yes, but they are lexed and parsed, right? Right, but that's the case regardless of `version(StdUnittest)`.

Re: C to D convertor

2021-08-24 Thread Dennis via Digitalmars-d-learn
On Saturday, 21 August 2021 at 08:14:22 UTC, Виталий Фадеев wrote: Any more ? CPP2D https://github.com/lhamot/CPP2D

Re: Union member positions?

2021-08-17 Thread Dennis via Digitalmars-d-learn
On Tuesday, 17 August 2021 at 13:46:22 UTC, z wrote: Is it possible to set a "position" on a union member? You can use anonymous `struct` and `union` blocks. ```D union UnionExample{ uint EAX; struct { //upper union { ushort EAHX; struct {

Re: .tupleof for static array

2021-08-10 Thread Dennis via Digitalmars-d-learn
Thanks for this solution as well. On Tuesday, 10 August 2021 at 13:10:23 UTC, Paul Backus wrote: Would definitely be nice to have this in the language, though. Do you know more use cases for this?

Re: .tupleof for static array

2021-08-10 Thread Dennis via Digitalmars-d-learn
Thanks! I was considering turning the static array into an AliasSeq directly, but casting it to a struct and doing tupleof on that is pretty smart. On Tuesday, 10 August 2021 at 12:50:55 UTC, jfondren wrote: And I don't see very many static-array-generic functions in Phobos. Indeed, static a

.tupleof for static array

2021-08-10 Thread Dennis via Digitalmars-d-learn
```D struct Vec { float x, y, z; } void setPosition(float x, float y, float z) { } void main() { Vec posS = Vec(10, 20, 30); setPosition(posS.tupleof); // pass float[3] posA = [10, 20, 30]; setPosition(posA.tupleof); // Error: no property `tupleof` for type `float[3]` } `

Re: Tracy

2021-08-08 Thread Dennis via Digitalmars-d-learn
On Sunday, 8 August 2021 at 01:37:42 UTC, SealabJaster wrote: Could this be fixed? Or is this intentional? Of course it *could*, anyone can go to [the dlang wiki](https://wiki.dlang.org/LDC) and add a page for it. Johan Engelen is still working on [improving the feature](https://github.com/l

Re: Tracy

2021-08-07 Thread Dennis via Digitalmars-d-learn
On Friday, 6 August 2021 at 12:30:16 UTC, JG wrote: I guess this means that tracy has been integrated? If this is so is it documented anywhere how to use it? Stefan Koch's WIP tracy integration in DMD is completely separate from Johan Engelen's time tracing added to LDC in 1.25.0. Note that t

Re: Build time

2021-07-23 Thread Dennis via Digitalmars-d-learn
On Friday, 23 July 2021 at 18:53:06 UTC, JG wrote: Any suggestion on how to try and improve the build time. I am currently using dub. You can try profiling it with LDC 1.25 or later. Add this to dub.sdl: ``` dflags "--ftime-trace" platform="ldc" dflags "--ftime-trace-file=./my-trace.json" pl

Re: Creating immutable arrays in @safe code

2021-07-17 Thread Dennis via Digitalmars-d-learn
On Saturday, 17 July 2021 at 12:05:44 UTC, ag0aep6g wrote: Hm, as far as I understand, "strongly pure" doesn't require `immutable` parameters. `const` should be enough. The spec says: "A strongly pure function has no parameters with mutable indirections" [1]. I just took the description from

Re: Creating immutable arrays in @safe code

2021-07-17 Thread Dennis via Digitalmars-d-learn
On Saturday, 17 July 2021 at 05:44:24 UTC, ag0aep6g wrote: I tried doing that, but `-preview=dip1000` causes trouble. This fails: (...) I'm not sure what's going on. I'm not completely caught up, but from what I see, pure and immutable have a history of issues: [Issue 11503 - Type system br

Re: Creating immutable arrays in @safe code

2021-07-16 Thread Dennis via Digitalmars-d-learn
On Friday, 16 July 2021 at 20:45:11 UTC, H. S. Teoh wrote: Have you tried `pure`? The code in question is all `@safe pure nothrow`.

Re: Creating immutable arrays in @safe code

2021-07-16 Thread Dennis via Digitalmars-d-learn
On Friday, 16 July 2021 at 20:39:41 UTC, Ali Çehreli wrote: So to me, newly created data should be mutable for the most usability. It's clear that I stripped away too much context with the toy examples, so let me try to add some back. I don't like forcing the use of `immutable` in general, bu

Creating immutable arrays in @safe code

2021-07-16 Thread Dennis via Digitalmars-d-learn
I like passing around immutable data, but I don't like creating it. Here are some toy examples to illustrate: ```D immutable(int)[] positive(int[] input) @safe { return input.filter!(x => x > 0).array; } ``` Error: cannot implicitly convert expression `array(filter(input))` of type `int[]`

Re: Where is "open" in "core.sys.linux.unistd"?

2021-07-09 Thread Dennis via Digitalmars-d-learn
On Friday, 9 July 2021 at 15:11:38 UTC, Steven Schveighoffer wrote: But reading/writing, closing these file descriptors is always the same. For sockets you'd typically use `recv` and `send` instead or `read` and `write` because the former give extra options and the latter don't work on Window

Re: to compose or hack?

2021-07-09 Thread Dennis via Digitalmars-d-learn
On Wednesday, 7 July 2021 at 01:44:20 UTC, Steven Schveighoffer wrote: But it got me thinking, how often do people roll their own vs. trying to compose using existing Phobos nuggets? When there's not an obvious/simple way to do something by composing ranges, I tend to just give up and write pr

Re: assign to property 2 values

2021-07-09 Thread Dennis via Digitalmars-d-learn
On Friday, 9 July 2021 at 10:19:59 UTC, Виталий Фадеев wrote: It possible in current version 2.097 ? If you `import std.typecons` you can do: ```D element.border = tuple(1, solid).expand; ``` But it's not pretty. I suggest either calling the function regularly, or combing all settings in a si

Re: Can I make system calls directly from D?

2021-07-09 Thread Dennis via Digitalmars-d-learn
On Friday, 9 July 2021 at 08:08:57 UTC, rempas wrote: I just wonder if I'm able to do system calls directly from D or If I have to create bindings from "unistd.h" from C If with directly means 'without calling any C function' you can use inline assembly: ```D version(linux) void rt_sigreturn(

Re: UFCS doubt

2021-07-08 Thread Dennis via Digitalmars-d-learn
On Thursday, 8 July 2021 at 23:31:57 UTC, Antonio wrote: "It works as described in the manual, not as expected" (from MySQL haters club :-p) . Yeah, 50/285 people answering the question "What language features do you miss?" chose "UFCS for local symbols" in the [State of D survey (2018)](htt

Re: UFCS doubt

2021-07-08 Thread Dennis via Digitalmars-d-learn
On Thursday, 8 July 2021 at 22:24:26 UTC, Antonio wrote: I supossed that ```mfp(c,20)``` and ```c.mfp(20)``` should be equivalent because UFCS in second example, but it is not... why? UFCS does not work for nested functions. Functions declared in a local scope are not found when searching fo

Re: Trivial simple OpenGl working example

2021-07-08 Thread Dennis via Digitalmars-d-learn
On Thursday, 8 July 2021 at 14:20:16 UTC, Виталий Фадеев wrote: Has dub flag for disable "warnings are treated as errors" ? You have to edit the package file to include `buildRequirements "allowWarnings"`, see https://dub.pm/package-format-sdl.html#build-requirements

Re: Trivial simple OpenGl working example

2021-07-08 Thread Dennis via Digitalmars-d-learn
On Thursday, 8 July 2021 at 13:51:51 UTC, Виталий Фадеев wrote: I searching trivial simple D/OpenGL working in 2021 year example. https://github.com/dkorpel/glfw-d/tree/master/examples/triangle-gl Uses bindbc-opengl + glfw-d (my package), example uses OpenGL 3.3. Should works on Windows and L

Re: How to disable assigning a value to a property?

2021-07-06 Thread Dennis via Digitalmars-d-learn
On Tuesday, 6 July 2021 at 10:06:11 UTC, Jack Applegame wrote: How to disable `register.clock = 10;` but allow `register.clock(1) = 10;`? I want to get a compilation error on `register.clock = 10;` We're [still awaiting formal assessment on dip1038](https://forum.dlang.org/thread/sojvxakgruzf

Re: anonymous functions and scope(exit)

2021-07-03 Thread Dennis via Digitalmars-d-learn
On Saturday, 3 July 2021 at 17:20:47 UTC, Luis wrote: scope(exit) inside of a anonymous functions, it's never called. I think the compiler infers the function `nothrow` since you don't throw any `Exception`, only an `Error`. Errors represent unrecoverable bugs, after which the program is in a

Re: float price; if (price == float.nan) { // initialized } else { // uninitialized } ... valid ?

2021-06-30 Thread Dennis via Digitalmars-d-learn
On Wednesday, 30 June 2021 at 03:52:51 UTC, someone wrote: at least I can do nulls with strings since it a class :) A `string` is not a class but an array, an `immutable(char)[]`. For arrays, `null` is equal to an empty array `[]`. ```D void main() { string s0 = null; string s1 = [];

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 on

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

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 "sour

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

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)

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: For fun, and executable lame joke

2021-05-31 Thread Dennis via Digitalmars-d-learn
On Monday, 31 May 2021 at 03:44:15 UTC, btiffin wrote: Is there a way to make that less codey, more jokey, *but still compile and execute the hip hip array*? ```D import std; alias cheer = each!writeln; void main() { D(); } void D() { cheer = ["hip", "hip"].array; } ```

Re: Compiler Explorer Assembly Output for C, C++ and D (dlang)

2021-05-27 Thread Dennis via Digitalmars-d-learn
On Thursday, 27 May 2021 at 10:27:42 UTC, Tariq Siddiqui wrote: Thanks for your answer, -betterC works well with simple code but when using templates in code -betterC compilation failed. Templates are supported in -betterC, what's not supported can be found here: https://dlang.org/spec/better

Re: Compiler Explorer Assembly Output for C, C++ and D (dlang)

2021-05-27 Thread Dennis via Digitalmars-d-learn
On Thursday, 27 May 2021 at 08:47:50 UTC, Tariq Siddiqui wrote: - What are these additional lines? D generates extra symbols per module for things like module constructors, unittests and class introspection (I think). - How can I remove these lines from being generated? Pass the `-bette

Re: ugly and/or useless features in the language.

2021-05-23 Thread Dennis via Digitalmars-d-learn
On Sunday, 23 May 2021 at 14:13:36 UTC, Alain De Vos wrote: This one compiles without any problem. You annotated main `@trusted`, which means you want the compiler to assume it to be `@safe` without checking it. Mark it `@safe` and it reports: Error: address of variable `a` assigned to `q`

Re: struct destructor

2021-05-15 Thread Dennis via Digitalmars-d-learn
On Saturday, 15 May 2021 at 17:55:17 UTC, Alain De Vos wrote: Feature request, a function old which does the opposite of new, allowing deterministic,real-time behavior and memory conservation. You can use [object.destroy](https://dlang.org/phobos/object.html#.destroy) to destruct, and [GC.f

Re: Scope of import

2021-05-15 Thread Dennis via Digitalmars-d-learn
On Saturday, 15 May 2021 at 11:38:22 UTC, Adam D. Ruppe wrote: * rdmd runs the program too, dmd -i just compiles. You run the program separately. You can do `dmd -i -run main.d`

Re: bindbc.sfml , sfVideoMode , Error: undefined identifier

2021-05-08 Thread Dennis via Digitalmars-d-learn
On Saturday, 8 May 2021 at 09:05:18 UTC, Alain De Vos wrote: I must doing something wrong ? Did you define the `SFML_Graphics` version like in the README of bindbc-sfml?

Re: Measure cpu time

2021-05-07 Thread Dennis via Digitalmars-d-learn
On Friday, 7 May 2021 at 08:52:13 UTC, Dennis wrote: If you want to use it on Windows as well, this is a code snippet I wrote for that: For completeness, the imports it uses: ```D version(Windows) { import core.sys.windows.windows; import core.sys.windows.psapi: PROCESS_MEMORY_COUNTERS

Re: Measure cpu time

2021-05-07 Thread Dennis via Digitalmars-d-learn
On Friday, 7 May 2021 at 08:25:43 UTC, Andre Pany wrote: Is there some equivalent function in Phobos to get the cpu time on linux? I don't think so, but you can use `core.sys.posix.sys.resource: rusage`. If you want to use it on Windows as well, this is a code snippet I wrote for that: ```

Re: How to check for combinations of versions

2021-05-05 Thread Dennis via Digitalmars-d-learn
On Wednesday, 5 May 2021 at 15:03:16 UTC, Blatnik wrote: Is there any way to check for multiple conditions in a `version` statement? No, and that's by design to discourage complex version logic. The recommended approach is: ```D version (Version_A) version = Cool_Feature_Supported; version (Ve

Re: ioctl to set mixer volume

2021-04-16 Thread Dennis via Digitalmars-d-learn
On Friday, 16 April 2021 at 17:50:13 UTC, Alain De Vos wrote: The following very simple low level C-function simply sets the mixer volume. How to convert this simple function to dlang ? ``` void mixer_setlevel_stereo(int mixfd,int dev,int left,int right) { left+=256*right; #int_ioctl(int fd, uns

Re: Endianness - How to test code for portability

2021-03-12 Thread Dennis via Digitalmars-d-learn
On Friday, 12 March 2021 at 05:53:40 UTC, Preetpal wrote: This is not an important issue to me but I was just curious to see if anyone actually tests for portability issues related to endianness by compiling their D Lang code for a big endian architecture and actually running it on that system.

Re: Two functions with different args. Taking address of the one

2021-03-11 Thread Dennis via Digitalmars-d-learn
On Thursday, 11 March 2021 at 12:56:34 UTC, Виталий Фадеев wrote: What right way to call function directly with selecting one of two ? If they are not nested functions, you can also do: ``` // Separate names void processKey (ref MouseKeyEvent event) {...} void processMove(ref MouseMoveEvent eve

Re: Introspection of exceptions that a function can throw

2021-02-24 Thread Dennis via Digitalmars-d-learn
On Wednesday, 24 February 2021 at 19:38:53 UTC, Mark wrote: Is there a way to obtain a list, at compile-time, of all the exception types that a function might throw (directly or through a call to another function)? No, since this is not known at compile-time. See: https://forum.dlang.org/pos

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 equal

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 tha

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 could

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 s

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 fun

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 https://dlang.org/blog/2018/06/11/dasbetterc-converting-make

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 suggest

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 _D3std6format__T10printFloatTfTaZQrFNaNfNkAafSQBsQBr__T10FormatSpecTaZQ

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; ush

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 w

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 t

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 wh

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() { assert("Received".

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 t

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: https://github.com/dlang/dm

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 li

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 aut

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 en

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"; wr

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 ma

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] https://code.dlang.org/package

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 o

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(&mut arg), and I certainly find it helpful.) C# also does it, and uses exactly the same key

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 disappointing

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; voi

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 struct

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 => x[]).joine

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 *co

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 s

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 arra

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 cr

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: https://issues.dlang.org/show

<    1   2   3   4   >