Re: SumType extraction

2024-07-06 Thread Christian Köstlin via Digitalmars-d-learn
On Thursday, 27 June 2024 at 18:51:19 UTC, Josh Holtrop wrote: Questions: 4. Any other general improvements to my solution? I know it's kind of an unpopular choice these days but one could go with inheritance and polymorphism or instanceof tests. something along the lines of ```d import std.

Help with DynamicArray of Emsi Containers

2022-04-30 Thread Christian Köstlin via Digitalmars-d-learn
I am struggling with initializing an Emsi Containers DynamicArray in a nice way. Some background information of my usecase: I experimenting in porting some old 3d engine code of mine from c++ to dlang. In the engine I want to exactly control when resources are freed and not rely on the garbage

Re: Help with DynamicArray of Emsi Containers

2022-05-01 Thread Christian Köstlin via Digitalmars-d-learn
On 2022-05-01 09:12, vit wrote: DynamicArray has disabled postblit (is not copyable). Package autoptr is deprecated (internaly redirected to btl:atuoptr), all functionality is moved to package [BTL](https://code.dlang.org/packages/btl) (subpackage btl:autoptr). This library contains subpacka

Tracing/Profiling D Applications

2022-05-25 Thread Christian Köstlin via Digitalmars-d-learn
I experimented with application level tracing/profiling of d applications similar to what is described in https://dlang.org/blog/2020/03/13/tracing-d-applications/ as the "writef-based approach". Only difference is, that I am emitting json (https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUm

Re: Tracing/Profiling D Applications

2022-05-26 Thread Christian Köstlin via Digitalmars-d-learn
On 2022-05-26 01:05, frame wrote: On Wednesday, 25 May 2022 at 21:35:07 UTC, Christian Köstlin wrote: Is there also a way to get the "real" threadid? I'm using that functions inside threads: core.sys.windows.winbase.GetCurrentThreadId on Windows core.sys.posix.pthread.pthread_self on Unix (im

Re: Tracing/Profiling D Applications

2022-05-26 Thread Christian Köstlin via Digitalmars-d-learn
On 2022-05-25 23:56, Ali Çehreli wrote: On 5/25/22 14:35, Christian Köstlin wrote: > 1. I went for a singleton for storing tracing/logging information that > needs to be initialized manually. Is __gshared the right way to do that? I think this is where thread-local storage comes in handy. As

Re: Tracing/Profiling D Applications

2022-05-27 Thread Christian Köstlin via Digitalmars-d-learn
On 2022-05-26 22:19, Ali Çehreli wrote: On 5/26/22 12:54, Christian Köstlin wrote: > I want to be able to dump > tracings even while the program is still running. Then I would have to > collect the tls data of all still running threads. I am not sure without testing but I am under the impres

Re: Tracing/Profiling D Applications

2022-05-29 Thread Christian Köstlin via Digitalmars-d-learn
On 2022-05-29 20:52, Ali Çehreli wrote: On 5/27/22 06:55, Christian Köstlin wrote: > I wonder how I can synchronize the "dumping" and the > collection of the threads. Would be cool to have an efficient lockless > implementation of appender ... That turned out to be nontrivial. The following

Re: Tracing/Profiling D Applications

2022-05-29 Thread Christian Köstlin via Digitalmars-d-learn
On 2022-05-29 20:52, Ali Çehreli wrote: On 5/27/22 06:55, Christian Köstlin wrote: > I wonder how I can synchronize the "dumping" and the > collection of the threads. Would be cool to have an efficient lockless > implementation of appender ... That turned out to be nontrivial. The following

Re: Execute the Shell command and continue executing the algorithm

2022-05-31 Thread Christian Köstlin via Digitalmars-d-learn
On 2022-05-30 15:25, Ali Çehreli wrote: On 5/30/22 04:18, Alexander Zhirov wrote: > I want to run a command in the background The closest is spawnShell: import std.stdio; import std.process; import core.thread; void main() {   auto pid = spawnShell(`(sleep 1 & echo SLEEP >> log)`);   T

Re: Tracing/Profiling D Applications

2022-05-31 Thread Christian Köstlin via Digitalmars-d-learn
On 2022-05-29 23:08, Ali Çehreli wrote: On 5/29/22 13:47, Christian Köstlin wrote: > Our discussion with using TLS for the > collectors proposed to not need any lock on the add method for > collector, because its thread local and with that thread safe? It would be great that way but then the

Re: Tracing/Profiling D Applications

2022-05-31 Thread Christian Köstlin via Digitalmars-d-learn
On 2022-05-29 23:00, Ali Çehreli wrote: On 5/29/22 13:53, Christian Köstlin wrote: > According to > https://www.schveiguy.com/blog/2022/05/comparing-exceptions-and-errors-in-d/ > its bad to catch Errors ... Correct in the sense that the program should not continue after catching Error.

Re: Templatized delegates

2022-05-31 Thread Christian Köstlin via Digitalmars-d-learn
On 2022-05-31 23:15, Andrey Zherikov wrote: I have tightly coupled code which I'd like to decouple but I'm a bit stuck. For simplicity, I reduced the amount of code to something simple to understand. So I have a struct `S` that has templated member function that does something. On the other sid

Whats the proper way to write a Range next function

2022-06-15 Thread Christian Köstlin via Digitalmars-d-learn
the naive version would look like ```d auto next(Range)(Range r) { r.popFront; return r.front; } ``` But looking at a mature library e.g. https://github.com/submada/btl/blob/9cc599fd8495215d346ccd62d6e9f1f7ac140937/source/btl/vector/package.d#L229 is looks like there should be tons of

Re: Whats the proper way to write a Range next function

2022-06-15 Thread Christian Köstlin via Digitalmars-d-learn
On 2022-06-15 19:36, JG wrote: On Wednesday, 15 June 2022 at 17:30:31 UTC, JG wrote: On Wednesday, 15 June 2022 at 13:52:24 UTC, Christian Köstlin wrote: the naive version would look like ```d auto next(Range)(Range r) {     r.popFront;     return r.front; } ``` But looking at a mature librar

Re: Fetching licensing info for all dependencies of a DUB project

2022-06-27 Thread Christian Köstlin via Digitalmars-d-learn
On 2020-05-12 15:23, Paul Backus wrote: On Tuesday, 12 May 2020 at 13:08:01 UTC, Joseph Rushton Wakeling wrote: On Tuesday, 12 May 2020 at 12:59:14 UTC, Paul Backus wrote: You should be able to get this information from the JSON output of `dub describe`. Cool, thanks.  Much appreciated :-) H

Re: Fetching licensing info for all dependencies of a DUB project

2022-06-29 Thread Christian Köstlin via Digitalmars-d-learn
On 2022-06-28 14:34, Guillaume Piolat wrote: On Monday, 27 June 2022 at 21:36:31 UTC, Christian Köstlin wrote: I played around with the idea and came up with a small dub package, that is not (yet) uploaded to the dub registry. Source is available at https://github.com/gizmomogwai/packageinfo,

How to work with coverage data

2022-07-31 Thread Christian Köstlin via Digitalmars-d-learn
Hi dlang lovers, I recently wanted to improve how I work with coverage data (locally). For that I came up with a small program, that can be either called after a `dub test --coverage` or that can be automatically executed after the unittest with `postRunCommands "$DUB run lst2errormessages"` i

Re: Combining JSON arrays into a single JSON array -- better way than this?

2022-08-01 Thread Christian Köstlin via Digitalmars-d-learn
On 2022-08-01 06:24, ikelaiah wrote: Hi, I've written a cli tool to merge JSON files (containing JSON array) in the current folder as a single JSON file. My algorithm: 1. Create a string to store the output JSON array as a string, 2. read each file 3. read each object in JSON array from inpu

How to use exceptions

2022-08-11 Thread Christian Köstlin via Digitalmars-d-learn
Dear d-lang experts, lets say in general I am quite happy with exceptions. Recently though I stumbled upon two problems with them: 1. Its quite simple to loose valuable information 2. Its hard to present the exception messages to end users of your program Let me elaborate on those: Lets take

Re: How to use exceptions

2022-08-11 Thread Christian Köstlin via Digitalmars-d-learn
On 12.08.22 01:06, Adam D Ruppe wrote: You might find my recent blog post interesting too: http://dpldocs.info/this-week-in-d/Blog.Posted_2022_08_01.html#exception-template-concept and a draft of some more concepts: http://arsd-official.dpldocs.info/source/arsd.exception.d.html I also find th

Re: How to use exceptions

2022-08-12 Thread Christian Köstlin via Digitalmars-d-learn
On 12.08.22 01:50, H. S. Teoh wrote: ... > The OP's idea of wrapping throwing code with a function that tacks on extra information is a good idea. Perhaps the use of strings isn't ideal, but in principle I like his idea of exceptions acquiring higher-level information as it propagates up the c

Run dub build with all generated files in /tmp

2022-08-12 Thread Christian Köstlin via Digitalmars-d-learn
Sometimes I do not only rely on git to transport dub projects from computer to computer, but also on Dropbox or Syncthing or similar tools. For that it would be great if it would be possible to do all dub commands (e.g. build) in a way, that they are not touching the current working directory. For

Re: How to use exceptions

2022-08-12 Thread Christian Köstlin via Digitalmars-d-learn
On 12.08.22 23:05, Christian Köstlin wrote: On 12.08.22 01:50, H. S. Teoh wrote: ... > The OP's idea of wrapping throwing code with a function that tacks on extra information is a good idea.  Perhaps the use of strings isn't ideal, but in principle I like his idea of exceptions acquiring high

Re: How to use exceptions

2022-08-13 Thread Christian Köstlin via Digitalmars-d-learn
On 13.08.22 15:00, kdevel wrote: On Friday, 12 August 2022 at 21:41:25 UTC, Christian Köstlin wrote: which would enable something like ```d     return  s     .readText     .parseJSON     .contextWithException((UTFException e) {     return new Exception("Cannot process UTF-8

Re: How to use exceptions

2022-08-13 Thread Christian Köstlin via Digitalmars-d-learn
On 13.08.22 17:00, kdevel wrote: "Exception enrichment" would be my wording which is supported by google [1]. There is also the notion of "exception context" [2] and "contexted exception" [3]. Thats really a good word! Especially it describes better what the java guys are doing by adding inform

Re: Recommendation for parallelism with nested for loops?

2022-08-20 Thread Christian Köstlin via Digitalmars-d-learn
On 19.08.22 03:49, Shriramana Sharma wrote: Hello. I want to parallelize a computation which has two for loops, one nested within another. All inner-loop-param+outer-loop-param combinations can be computed independent of one another. As I suspected, [https://forum.dlang.org/post/xysyidbkjdinc

Re: Recommendation for parallelism with nested for loops?

2022-08-20 Thread Christian Köstlin via Digitalmars-d-learn
On 20.08.22 12:28, Christian Köstlin wrote: On 19.08.22 03:49, Shriramana Sharma wrote: Hello. I want to parallelize a computation which has two for loops, one nested within another. All inner-loop-param+outer-loop-param combinations can be computed independent of one another. As I suspected,

How do you work with lst files?

2022-08-24 Thread Christian Köstlin via Digitalmars-d-learn
I want to ask around how you from the dlang community work with .lst coverage files? For me those files are really one of the best formats as they are (really, in contrast to some xml things) human readable and someone added them to codecov. My setup at the moment consists of a small tool that

Re: How check if destructor has been called?

2022-09-13 Thread Christian Köstlin via Digitalmars-d-learn
On 13.09.22 19:13, Ben Jones wrote: On Tuesday, 13 September 2022 at 14:06:42 UTC, Injeckt wrote: Hi, I'm trying to check if destructor has been called, but when I'm deleting class object I didn't get any calls from destructor. myclass.d     ~this() {     this.log("\nDestructor\n");  

Re: dub lint

2022-09-15 Thread Christian Köstlin via Digitalmars-d-learn
On 16.09.22 00:14, Ali Çehreli wrote: On 9/15/22 15:04, Ali Çehreli wrote: > Is there a way to silence specific 'dub lint' warnings? Answering myself, I don't think it's possible but luckily my catching an Error was in unittests only so I can do either of the following to skip unittest code

Re: dub lint

2022-09-15 Thread Christian Köstlin via Digitalmars-d-learn
On 16.09.22 01:14, Christian Köstlin wrote: On 16.09.22 00:14, Ali Çehreli wrote: On 9/15/22 15:04, Ali Çehreli wrote:  > Is there a way to silence specific 'dub lint' warnings? Answering myself, I don't think it's possible but luckily my catching an Error was in unittests only so I can do ei

Re: dub lint

2022-09-16 Thread Christian Köstlin via Digitalmars-d-learn
On 16.09.22 02:23, rikki cattermole wrote: https://github.com/dlang/dub/issues/2483 Also the double --config option is already in a bugreport (quite old), but not fixed as far as i can see: https://github.com/dlang/dub/issues/1940 Kind regards, Christian

Re: Setting import paths - project (dub) and also rdmd or dmd

2022-09-19 Thread Christian Köstlin via Digitalmars-d-learn
On 19.09.22 16:24, David wrote: Hi, New to D (and enjoying the learning..) I've probably missed something obvious but I'm slightly confused with the best way to achieve a simple build. I like to keep my reusable modules in a directory outside of the project directory so I can use them on an

Anaphoric "macros"

2022-09-24 Thread Christian Köstlin via Digitalmars-d-learn
Hi, I just stumbled upon anaphoric macros (https://en.wikipedia.org/wiki/Anaphoric_macro) in elisp. Seems that the dlang feature e.g. `map!"a*2"` is something similar to that, although I never read about it phrased like that before. Kind regards, Christian

Is there a way to mark a dub package as linux only?

2022-09-26 Thread Christian Köstlin via Digitalmars-d-learn
Or posix only? Or not windows? Kind regards, Christian

Re: Is there a way to mark a dub package as linux only?

2022-09-27 Thread Christian Köstlin via Digitalmars-d-learn
On 27.09.22 13:07, Ahmet Sait wrote: On Monday, 26 September 2022 at 20:57:06 UTC, Christian Köstlin wrote: Or posix only? Or not windows? Kind regards, Christian Not necessarily a dub solution but you can do something like this: ```d version(Posix) { } else     static assert(0, "Unsupported

Re: rotate left an array

2022-10-04 Thread Christian Köstlin via Digitalmars-d-learn
If you are ok with using things from std.range you could use something like this: ```d import std.range : cycle, drop, take; import std.stdio : writeln; int main(string[] args) { auto r = [1, 2, 3, 4, 5, 6, 7, 8]; writeln(r.cycle.drop(3).take(r.length)); return 0; } ``` Kind regar

Make IN Dlang

2022-11-01 Thread Christian Köstlin via Digitalmars-d-learn
Dear dlang-folk, one of the tools I always return to is rake (https://ruby.github.io/rake/). For those that do not know it, its a little like make in the sense that you describe your build as a graph of tasks with dependencies between them, but in contrast to make the definition is written in

Re: Make IN Dlang

2022-11-02 Thread Christian Köstlin via Digitalmars-d-learn
On 02.11.22 00:51, Adam D Ruppe wrote: I don't have specific answers to your questions but your goal sounds similar to Atila's reggae project so it might be good for you to take a look at: https://code.dlang.org/packages/reggae Hi Adam, thanks for the pointer. I forgot about reggae ;-) From

Re: Make IN Dlang

2022-11-02 Thread Christian Köstlin via Digitalmars-d-learn
On 02.11.22 03:25, Tejas wrote: On Tuesday, 1 November 2022 at 23:40:22 UTC, Christian Köstlin wrote: Dear dlang-folk, one of the tools I always return to is rake (https://ruby.github.io/rake/). For those that do not know it, its a little like make in the sense that you describe your build a

Re: Make IN Dlang

2022-11-02 Thread Christian Köstlin via Digitalmars-d-learn
On 02.11.22 04:07, rikki cattermole wrote: Something to consider: dub can be used as a library. You can add your own logic in main to allow using your build specification to generate a dub file (either in memory or in file system). Nice ... I will perhaps give that a try! Kind regards, Chris

Re: Make IN Dlang

2022-11-02 Thread Christian Köstlin via Digitalmars-d-learn
On 02.11.22 20:16, H. S. Teoh wrote: On Wed, Nov 02, 2022 at 03:08:36PM +, JN via Digitalmars-d-learn wrote: On Tuesday, 1 November 2022 at 23:40:22 UTC, Christian Köstlin wrote: sh("touch %s".format(t.name)); One of the problems of many Make-like tools is that they offe

Re: Make IN Dlang

2022-11-02 Thread Christian Köstlin via Digitalmars-d-learn
On 02.11.22 17:24, Kagamin wrote: Another idea is to separate the script and interpreter then compile them together. ``` --- interp.d --- import script; import ...more stuff ...boilerplate code int main() {   interpret(script.All);   return 0; } --- script.d --- #! ? module script; import min

Re: Makefiles and dub

2022-11-05 Thread Christian Köstlin via Digitalmars-d-learn
On 05.11.22 12:38, rikki cattermole wrote: We have a few build formats that dub can generate for you automatically: ``` visuald - VisualD project files sublimetext - SublimeText project file cmake - CMake build scripts build - Builds the package directly ``` Unfortunately none of them are make,

Is it just me, or does vibe.d's api doc look strange?

2022-12-02 Thread Christian Köstlin via Digitalmars-d-learn
Please see this screenshot: https://imgur.com/Ez9TcqD of my browser (firefox or chrome) of https://vibed.org/api/vibe.web.auth/ Kind regards, Christian

Gotcha with photos' documentation

2022-12-08 Thread Christian Köstlin via Digitalmars-d-learn
Recently I stumbled upon a small issue in dlang's docs. I wanted to look up uniq in std.algorithm. Started from https://dlang.org/phobos/std_algorithm.html and clicked uniq, no problem, all good. But my code did not work. After some debugging I saw, that for some inputs uniq just did not work. I

Re: Gotcha with photos' documentation

2022-12-09 Thread Christian Köstlin via Digitalmars-d-learn
On 09.12.22 02:27, H. S. Teoh wrote: On Thu, Dec 08, 2022 at 05:21:52PM -0800, H. S. Teoh via Digitalmars-d-learn wrote: [...] I'll see if I can reword this to be more explicit. [...] https://github.com/dlang/phobos/pull/8646 T Thanks a lot ... that was fast. Is there also an implementat

Re: Gotcha with photos' documentation

2022-12-09 Thread Christian Köstlin via Digitalmars-d-learn
On 09.12.22 19:55, H. S. Teoh wrote: On Fri, Dec 09, 2022 at 12:51:27PM +0100, Christian Köstlin via Digitalmars-d-learn wrote: On 09.12.22 02:27, H. S. Teoh wrote: [...] https://github.com/dlang/phobos/pull/8646 [...] Thanks a lot ... that was fast. It only took a minute to fix. :-D

Advent of Code 2022

2022-12-10 Thread Christian Köstlin via Digitalmars-d-learn
Is anybody participating with dlang in the advent of code 22? It would be interesting to discuss dlang specific things from the puzzles. Kind regards, Christian

Re: Coding Challenges - Dlang or Generic

2023-01-10 Thread Christian Köstlin via Digitalmars-d-learn
On 10.01.23 01:17, Paul wrote: There is also https://exercism.org/tracks/d with some tasks for dlang. Kind regards, Christian

Re: Coding Challenges - Dlang or Generic

2023-01-12 Thread Christian Köstlin via Digitalmars-d-learn
On 10.01.23 23:22, monkyyy wrote: On Tuesday, 10 January 2023 at 19:10:09 UTC, Christian Köstlin wrote: On 10.01.23 01:17, Paul wrote: There is also https://exercism.org/tracks/d with some tasks for dlang. Kind regards, Christian Its all converted code; worthless I was not aware, that the qu

Re: Coding Challenges - Dlang or Generic

2023-01-12 Thread Christian Köstlin via Digitalmars-d-learn
On 10.01.23 23:30, Paul wrote: On Tuesday, 10 January 2023 at 01:31:28 UTC, Ali Çehreli wrote: On 1/9/23 16:17, Paul wrote: > coding challenges Perhaps the following two?   https://rosettacode.org/   https://adventofcode.com/ Ali Excellent.  Thanks. For this years advent-of-code Steven S

Re: Need some technical help an object oriented wrapper I am creating for bindbc.sfml

2023-01-23 Thread Christian Köstlin via Digitalmars-d-learn
On 24.01.23 04:59, thebluepandabear wrote: Regards, thebluepandabear Btw I understand this question is extremely complex, don't want to pressure anyone to help me because of that... but any sort of assistance or leads would be greatly... greatly apprecaited... I do not know anything about sfm

Re: Simplest way to convert an array into a set

2023-02-13 Thread Christian Köstlin via Digitalmars-d-learn
On 13.02.23 19:04, Matt wrote: Obviously, there is no "set" object in D, but I was wondering what the quickest way to remove duplicates from an array would be. I was convinced I'd seen a "unique" method somewhere, but I've looked through the documentation for std.array, std.algorithm AND std.ra

How to work with phobos github projects

2023-03-10 Thread Christian Köstlin via Digitalmars-d-learn
Recently I was looking in contributing to dlang/phobos and found the github subprojects for phobos (https://github.com/dlang/phobos/projects?type=classic) which include a project to improve the public examples for phobos (https://github.com/dlang/phobos/projects/1). I looked at one of the card

How do you work with unittest libraries in dub packages?

2023-04-04 Thread Christian Köstlin via Digitalmars-d-learn
Recently Dmytro Katyukha brought up an issue in one of my dub packages that is supposed to be used as a library. He even went the whole way and came up with a simple reduced example: https://gitlab.com/gizmomogwai/colored/-/merge_requests/3#note_1341026928. The problem here is, that my dub pack

Re: serve-d and emacs

2023-04-20 Thread Christian Köstlin via Digitalmars-d-learn
I tried to reproduce my old eglot experiment, and for me serve-d was not even compiling with the newest dmd. Which versions are you using? Kind regards, Christian

Re: Mixin and compile-time functions for code generation

2023-06-30 Thread Christian Köstlin via Digitalmars-d-learn
On 24.06.23 18:31, Cecil Ward wrote: I have a function that can be run at compile-time and which will be able to output code to be injected into the D source code stream. Can I get mixin whatever to do this for me? Mixin with a function that runs at compile-time and creates the required source

Re: Giant template - changing types everywhere

2023-07-14 Thread Christian Köstlin via Digitalmars-d-learn
On 14.07.23 16:15, Steven Schveighoffer wrote: On 7/14/23 1:51 AM, Cecil Ward wrote: On Friday, 14 July 2023 at 05:09:58 UTC, Cecil Ward wrote: On Friday, 14 July 2023 at 05:05:27 UTC, Cecil Ward wrote: On Friday, 14 July 2023 at 05:03:31 UTC, Cecil Ward wrote: The way I can see it going is

Re: Giant template - changing types everywhere

2023-07-14 Thread Christian Köstlin via Digitalmars-d-learn
On 14.07.23 18:51, Steven Schveighoffer wrote: On 7/14/23 12:40 PM, Christian Köstlin wrote: Would Eponymous Templates (https://dlang.org/spec/template.html#implicit_template_properties) work with the wrapping template? Only if all the functions are named the same as the template. With ep

Re: parallel threads stalls until all thread batches are finished.

2023-08-28 Thread Christian Köstlin via Digitalmars-d-learn
On 26.08.23 05:39, j...@bloow.edu wrote: On Friday, 25 August 2023 at 21:31:37 UTC, Ali Çehreli wrote: On 8/25/23 14:27, j...@bloow.edu wrote: > "A work unit is a set of consecutive elements of range to be processed > by a worker thread between communication with any other thread. The > number

Re: parallel threads stalls until all thread batches are finished.

2023-08-29 Thread Christian Köstlin via Digitalmars-d-learn
On 29.08.23 00:37, j...@bloow.edu wrote: Well, I have 32 cores so that would spawn 64-1 threads with hyper threading so not really a solution as it is too many simultaneous downs IMO. "These properties get and set the number of worker threads in the TaskPool instance returned by taskPool. Th

Re: pipeProcess output to hash string

2023-09-11 Thread Christian Köstlin via Digitalmars-d-learn
On 09.09.23 17:44, Vino wrote: Hi All,   Request your help on how to convert the output of std.process.pipeProcess to hash string ``` auto test(in Redirect redirect=Redirect.stdout | Redirect.stderr) {     import std.process;     import std.digest.crc;     import std.stdio: writeln;   

Re: Json Help

2023-09-12 Thread Christian Köstlin via Digitalmars-d-learn
On 10.09.23 13:06, Vino wrote: Hi All,   Request your help on the below code,I am trying to convert the below string to json and it always throws the error, if the below can be accomplished with any other json package even that is fine, I tired only the std.json package. Test Program: Work

Re: change object class

2023-09-22 Thread Christian Köstlin via Digitalmars-d-learn
On 17.09.23 17:05, Vitaliy Fadeev wrote: Hi! I want to change a method ```Draw``` on a custom object when the ```MouseIn``` event occurs. This is known as "Change State" of the object: ```Init``` -> ```Hovered```. I want to change the state of an object by changing its class, like this: ```d

Re: change object class

2023-09-22 Thread Christian Köstlin via Digitalmars-d-learn
On 23.09.23 05:25, Vitaliy Fadeev wrote: On Friday, 22 September 2023 at 19:50:17 UTC, Christian Köstlin wrote: On 17.09.23 17:05, Vitaliy Fadeev wrote: Hi! You could model it oop style like this: https://run.dlang.io/is/MJb5Fk This solution might not be to your taste, as it involves interfac

Re: change object class

2023-09-23 Thread Christian Köstlin via Digitalmars-d-learn
On 23.09.23 05:11, Vitaliy Fadeev wrote: On Friday, 22 September 2023 at 19:50:17 UTC, Christian Köstlin wrote: another option could be to model your own VTable in a struct like this: https://run.dlang.io/is/3LTjP5 Kind regards, Christian Thank, Christian ! True nice tasty solution with ```VT

Re: Vibe.d download function, how to get callback when done or error?

2023-09-23 Thread Christian Köstlin via Digitalmars-d-learn
On 23.09.23 14:07, j...@bloow.edu wrote: I'm using download(url, filename) to download files in vibe.d. The issue is that I do not know when the download is finished or errors. There is a callback for the streaming side but not for the file download. A small test program shows, that if the fu

Re: Vibe.d download function, how to get callback when done or error?

2023-09-24 Thread Christian Köstlin via Digitalmars-d-learn
On 24.09.23 12:01, j...@bloow.edu wrote: On Saturday, 23 September 2023 at 20:20:31 UTC, Christian Köstlin wrote: On 23.09.23 14:07, j...@bloow.edu wrote: I'm using download(url, filename) to download files in vibe.d. The issue is that I do not know when the download is finished or errors. Th

Re: Vibe.d download function, how to get callback when done or error?

2023-09-24 Thread Christian Köstlin via Digitalmars-d-learn
On 24.09.23 12:01, j...@bloow.edu wrote: On Saturday, 23 September 2023 at 20:20:31 UTC, Christian Köstlin wrote: On 23.09.23 14:07, j...@bloow.edu wrote: I'm using download(url, filename) to download files in vibe.d. The issue is that I do not know when the download is finished or errors. Th

Re: Removing an element from a DList

2023-10-18 Thread Christian Köstlin via Digitalmars-d-learn
On Tuesday, 17 October 2023 at 17:27:19 UTC, Joakim G. wrote: For some reason I cannot remove an element from a DList. I tried several range approaches but to no avail. I'm a noob. In the end I did this: ``` private void removeFromWaitingQueue(uint jid) { auto arr = waitingQueue[].array;

Re: Weird bug in std.logger? Possible memory corruption

2023-11-01 Thread Christian Köstlin via Digitalmars-d-learn
On Wednesday, 1 November 2023 at 14:15:55 UTC, matheus wrote: On Tuesday, 31 October 2023 at 21:19:34 UTC, Arafel wrote: ... Assigning the value to a variable works as expected: ```d import std.logger : info; void main() { auto s = foo(); info(s); } auto foo() { info("In foo");

Re: How do I install a package globally?

2023-11-10 Thread Christian Köstlin via Digitalmars-d-learn
On Saturday, 11 November 2023 at 01:50:54 UTC, Trevor wrote: I'm just getting in to D , coming from a C and Python background. I've had a play with DUB and adding packages to my project, but it seems like there should be a way to install packages so they can be used in any D program I compile w

Re: How do I install a package globally?

2023-11-13 Thread Christian Köstlin via Digitalmars-d-learn
On Saturday, 11 November 2023 at 23:28:18 UTC, Trevor wrote: On Saturday, 11 November 2023 at 07:12:21 UTC, Christian Köstlin wrote: On Saturday, 11 November 2023 at 01:50:54 UTC, Trevor wrote: I'm just getting in to D , coming from a C and Python background. I've had a play with DUB and adding

Behaves different on my osx and linux machines

2023-12-21 Thread Christian Köstlin via Digitalmars-d-learn
I have this somehow reduced program that behaves differently on osx and linux. ```d void stdioMain() { import std.stdio : readln, writeln; import std.concurrency : spawnLinked, receive, receiveTimeout, LinkTerminated; import std.variant : Variant; import std.string : strip;

Re: Behaves different on my osx and linux machines

2023-12-22 Thread Christian Köstlin via Digitalmars-d-learn
On Friday, 22 December 2023 at 15:02:42 UTC, Kagamin wrote: Add more debugging? ``` bool done = false; while (!done) { writeln(1); auto result = ["echo", "Hello World"].execute; if (result.status != 0) { writeln(2); throw new

Re: Behaves different on my osx and linux machines

2023-12-27 Thread Christian Köstlin via Digitalmars-d-learn
On Wednesday, 27 December 2023 at 14:03:06 UTC, Kagamin wrote: Maybe you're not supposed to print text while reading? In parallel I have contacted schveiguy on discord and he found the culprid. But we do not have a solution yet. It probably will result in a bugreport at https://issues.dlang.o

Re: Non-blocking keyboard input

2023-12-27 Thread Christian Köstlin via Digitalmars-d-learn
On Wednesday, 27 December 2023 at 05:07:04 UTC, Joe wrote: ??? Surely there there is a one liner library solution for this? I have a program that spawns a thread for debugging information and uses the keyboard input which allows me to display the informati

Re: Non-blocking keyboard input

2023-12-27 Thread Christian Köstlin via Digitalmars-d-learn
On Wednesday, 27 December 2023 at 14:41:05 UTC, Christian Köstlin wrote: One option (not tested) should be to close stdin so that readln then returns null or something on eof. Shutting down threads is always tricky. It would be great if there would be one or two (perhaps one synchronous, one

How to implement filterMap

2023-12-29 Thread Christian Köstlin via Digitalmars-d-learn
Is there a way to implement filterMap (meaning do mapping of a range, but if something happens during the map, leave this element out of the resulting range). I have two solutions (one is with evaluating the mapping function several times), and one tries to store the result for the next front c

Re: How to implement filterMap

2023-12-30 Thread Christian Köstlin via Digitalmars-d-learn
On Saturday, 30 December 2023 at 01:22:31 UTC, Siarhei Siamashka wrote: On Friday, 29 December 2023 at 23:10:47 UTC, Christian Köstlin wrote: Is there a way to implement filterMap (meaning do mapping of a range, but if something happens during the map, leave this element out of the resulting ra

Re: How to implement filterMap

2023-12-30 Thread Christian Köstlin via Digitalmars-d-learn
On Saturday, 30 December 2023 at 18:08:55 UTC, Alexandru Ermicioi wrote: On Friday, 29 December 2023 at 23:10:47 UTC, Christian Köstlin wrote: Is there a way to implement filterMap (meaning do mapping of a range, but if something happens during the map, leave this element out of the resulting r

Re: Synchronisation help

2024-01-02 Thread Christian Köstlin via Digitalmars-d-learn
On Tuesday, 2 January 2024 at 10:41:55 UTC, Anonymouse wrote: On Monday, 1 January 2024 at 19:49:28 UTC, Jonathan M Davis wrote: [...] Thank you. Yes, `Foo` is a class for the purposes of inheritance -- I left that out of the example. So a completely valid solution is to write a struct wrap

Re: Partial function application (Currying)

2024-01-20 Thread Christian Köstlin via Digitalmars-d-learn
Would https://dlang.org/library/std/functional/curry.html help you? kind regards, Christian

Vibe.d and shared data synchronization

2020-04-07 Thread Christian Köstlin via Digitalmars-d-learn
Hi, I wrote a very small vibe.d based URL-shortener. It has an in memory database that is in theory shared across request threads. At the moment I do not distribute over the vibe.d threadpool (https://vibed.org/features#multi-threading), but I would like to. What would be the best way to shar

Re: dynamic array .length vs .reserve - what's the difference?

2020-08-02 Thread Christian Köstlin via Digitalmars-d-learn
On 31.07.20 06:28, Ali Çehreli wrote: On 7/30/20 4:42 PM, wjoe wrote: > So .capacity can't be assigned a value like length to reserve the RAM ? Yes, a read-only property... >> auto a = b; >> b = b[0 .. $-1]; >> b ~= someT; >> >> If that last line is done in-place, then it overwrites a[$-

DMD support for Apples new silicon

2021-01-10 Thread Christian Köstlin via Digitalmars-d-learn
Hi all, are there any plans on supporting Apples new ARM silicon with DMD or would this be something for ldc? Kind regards, Christian

Re: DMD support for Apples new silicon

2021-01-10 Thread Christian Köstlin via Digitalmars-d-learn
On 10.01.21 15:50, Guillaume Piolat wrote: On Sunday, 10 January 2021 at 14:22:25 UTC, Christian Köstlin wrote: Hi all, are there any plans on supporting Apples new ARM silicon with DMD or would this be something for ldc? Kind regards, Christian Hello Christian, LDC since 1.24+ support cr

Re: DMD support for Apples new silicon

2021-01-11 Thread Christian Köstlin via Digitalmars-d-learn
On 10.01.21 17:29, Guillaume Piolat wrote: On Sunday, 10 January 2021 at 16:03:53 UTC, Christian Köstlin wrote: Good news! I was hoping for support in ldc, but dmds super fast compile times would be very welcome. I guess it's more work to put an ARM backend there. Kind regards, Christian

Re: Anything in D to avoid check for null everywhere?

2021-01-14 Thread Christian Köstlin via Digitalmars-d-learn
On 12.01.21 22:37, Jack wrote: I was looking for a way to avoid null checks everywhere. I was checking the Null object pattern, or use something like enforce pattern, or even if I could make a new operator and implement something like C#'s .? operator, that Java was going to have one but they r

serve-d and emacs

2021-04-26 Thread Christian Köstlin via Digitalmars-d-learn
Does anybody use serve-d with emacs (lsp-mode or eglot)? I would love to see the configuration! Kind regards, Christian

Re: serve-d and emacs

2021-04-28 Thread Christian Köstlin via Digitalmars-d-learn
On 26.04.21 21:13, WebFreak001 wrote: On Monday, 26 April 2021 at 18:45:08 UTC, Christian Köstlin wrote: Does anybody use serve-d with emacs (lsp-mode or eglot)? I would love to see the configuration! Kind regards, Christian if you configure it yourself, feel free to share the configuration a

Re: serve-d and emacs

2021-04-30 Thread Christian Köstlin via Digitalmars-d-learn
On 26.04.21 21:13, WebFreak001 wrote: On Monday, 26 April 2021 at 18:45:08 UTC, Christian Köstlin wrote: Does anybody use serve-d with emacs (lsp-mode or eglot)? I would love to see the configuration! Kind regards, Christian if you configure it yourself, feel free to share the configuration a

Re: How to use dub with our own package

2021-05-12 Thread Christian Köstlin via Digitalmars-d-learn
On 2021-05-12 15:37, Vinod K Chandran wrote: Hi all, I am creating a hobby project related with win api gui functions. i would like to work with dub. But How do I use dub in my project. 1. All my gui library modules are located in a folder named "winglib". 2. And that folder also conatains a d

Re: How to use dub with our own package

2021-05-12 Thread Christian Köstlin via Digitalmars-d-learn
On 2021-05-12 21:22, Vinod K Chandran wrote: On Wednesday, 12 May 2021 at 18:26:39 UTC, Christian Köstlin wrote: Are you really interested in doing winglib as a separate dub package? If not you could just do a `dub init yourappname` which gives you the basic skeleton. something like: . ├── d

Re: how do I implement opSlice for retro range?

2021-05-14 Thread Christian Köstlin via Digitalmars-d-learn
On 2021-05-14 05:49, Jack wrote: How can I implement ranges in the retro range? I'd like to do this without allocate a new array with .array from std.array, can I do that? use like this: ```d     auto arr = [1, 2, 3, 4, 5];     auto a = new A!int(arr);     auto b = a.retro[0 .. 2]; // 4, 5

How to work around the infamous dual-context when using delegates together with std.parallelism

2021-05-27 Thread Christian Köstlin via Digitalmars-d-learn
I have this small program here test.d: ``` import std; string doSomething(string[] servers, string user) { return user ~ servers[0]; } void main() { auto servers = ["s1", "s2", "s3"]; auto users = ["u1", "u2", "u3"]; writeln(map!(user => servers.doSomething(user))(users)); wri

Re: How to work around the infamous dual-context when using delegates together with std.parallelism

2021-05-27 Thread Christian Köstlin via Digitalmars-d-learn
Thanks for the proposed solution. It also works in my slightly bigger program (although I do not like to make servers more global). I tried also the following (which unfortunately also does not work as intended): ```D import std; string doSomething(string[] servers, string user) { return

Re: How to work around the infamous dual-context when using delegates together with std.parallelism

2021-05-27 Thread Christian Köstlin via Digitalmars-d-learn
On 2021-05-27 13:11, sighoya wrote: On Thursday, 27 May 2021 at 09:58:40 UTC, Christian Köstlin wrote: I have this small program here test.d: ``` import std; string doSomething(string[] servers, string user) {     return user ~ servers[0]; } void main() {     auto servers = ["s1", "s2", "s3"];

  1   2   >