Re: How to make project with main application and cli application in the same folder?

2024-04-21 Thread Monkyyy via Digitalmars-d-learn
On Sunday, 21 April 2024 at 08:44:38 UTC, alex wrote: Hi guys. Trying to play with vibe-d and want to create separate web app, and cli app which can add admin users. When I just keep both files app.d and cli.d in source folder, I get an error that I can't have more then 1 main function. [...]

Re: How to generate a random number from system clock as seed

2024-06-08 Thread monkyyy via Digitalmars-d-learn
On Saturday, 8 June 2024 at 13:19:30 UTC, Eric P626 wrote: I managed to create a random number generator using the following code: ~~~ auto rng = Random(42); // uniform(0,10,rng); ~~~ Now I want to seed the generator using system time. I looked at Date & time functions/classes and systime

Re: How to generate a random number from system clock as seed

2024-06-08 Thread monkyyy via Digitalmars-d-learn
On Saturday, 8 June 2024 at 20:53:02 UTC, Nick Treleaven wrote: On Saturday, 8 June 2024 at 16:09:04 UTC, monkyyy wrote: rng is an optional parameter, `uniform(0,100).writeln;` alone works; the docs not telling you that is really bad They do tell you: urng (optional) random number generator

Re: How to generate a random number from system clock as seed

2024-06-09 Thread monkyyy via Digitalmars-d-learn
On Sunday, 9 June 2024 at 07:11:22 UTC, Eric P626 wrote: On Saturday, 8 June 2024 at 21:04:16 UTC, monkyyy wrote: generate is a very rare function and do novices understand lamdas? Yes I know lamdas, but try not to use them. I am not very picky about the exact source of time, I just want a d

Re: How to use D without the GC ?

2024-06-11 Thread monkyyy via Digitalmars-d-learn
On Tuesday, 11 June 2024 at 17:15:07 UTC, Vinod K Chandran wrote: On Tuesday, 11 June 2024 at 16:54:44 UTC, Steven Schveighoffer wrote: I would instead ask the reason for wanting to write D code without the GC. -Steve Hi Steve, Two reasons. 1. I am writting a dll to use in Python. So I am

Re: How to use D without the GC ?

2024-06-12 Thread monkyyy via Digitalmars-d-learn
On Wednesday, 12 June 2024 at 16:50:04 UTC, Vinod K Chandran wrote: On Wednesday, 12 June 2024 at 01:35:26 UTC, monkyyy wrote: rather then worring about the gc, just have 95% of data on the stack How's that even possible ? AFAIK, we need heap allocated memory in order to make GUI lib as a D

Re: Call an external program from CTFE

2024-06-23 Thread monkyyy via Digitalmars-d-learn
On Sunday, 23 June 2024 at 16:33:54 UTC, realhet wrote: Hi, Is there a way to call an external program from CTFE? Use case: Inside a module I want to put some GLSL code. I also want to generate that GLSL code using CTFE. And when it's done, it would be nice if I was able to save that GLSL cod

Re: Why does this mixin fail to compile?

2024-07-01 Thread monkyyy via Digitalmars-d-learn
On Monday, 1 July 2024 at 13:00:55 UTC, ryuukk_ wrote: i don't want string concatenation This limitation is very intentional, add it to the pile like file io in ctfe of stuff that the core devs think "you shouldnt even want that" for "safety"

Re: Being reading a lot about betterC, but still have some questions

2024-07-09 Thread monkyyy via Digitalmars-d-learn
On Tuesday, 9 July 2024 at 07:54:12 UTC, kiboshimo wrote: I'm going to try a project with raylib and WASM. use mine https://github.com/crazymonkyyy/raylib-2024/blob/master/docs/examplecode.md - betterC can be compiled to WASM, but some of phobos can't, so basically same worries as above. I'm

Re: Being reading a lot about betterC, but still have some questions

2024-07-09 Thread monkyyy via Digitalmars-d-learn
On Tuesday, 9 July 2024 at 20:03:15 UTC, kiboshimo wrote: On Tuesday, 9 July 2024 at 14:42:01 UTC, monkyyy wrote: On Tuesday, 9 July 2024 at 07:54:12 UTC, kiboshimo wrote: - betterC can be compiled to WASM, but some of phobos can't, so basically same worries as above. I'm afraid to lose some e

Re: Error: circular reference to variable cause by order (bugs?)

2024-07-18 Thread monkyyy via Digitalmars-d-learn
On Thursday, 18 July 2024 at 12:25:37 UTC, Dakota wrote: I am trying to translate some c code into d, get this error: ```d struct A { void* sub; } struct B { void* subs; } __gshared { const A[1] a0 = [ { &b1_ptr }, ]; const A[2] a1 = [

Re: How to find the right function in the Phobos library?

2024-08-16 Thread monkyyy via Digitalmars-d-learn
On Saturday, 17 August 2024 at 05:28:37 UTC, Bruce wrote: This seems to work but now I'm concerned. Why was it so hard to find? What is the best way to search for a function in the Phobos library? It's the correct name for the wrong function If you use it on unicode strings or filters it's ju

Re: How to find the right function in the Phobos library?

2024-08-16 Thread monkyyy via Digitalmars-d-learn
On Saturday, 17 August 2024 at 06:11:58 UTC, Bruce wrote: On Saturday, 17 August 2024 at 05:42:42 UTC, monkyyy wrote: On Saturday, 17 August 2024 at 05:28:37 UTC, Bruce wrote: It's the correct name for the wrong function Are you saying this is wrong? auto i = arr.countUntil("ha"); yes ```d

Re: need help to use Emscripten with LDC to build wasm projects

2024-08-22 Thread monkyyy via Digitalmars-d-learn
On Thursday, 22 August 2024 at 07:28:00 UTC, Dakota wrote: Is there a way to link ldc objects with Emscripten to build wasm binary ? yes; you'll have to untangle my build system https://github.com/crazymonkyyy/raylib-2024 It will always suck tho

Re: need help to use Emscripten with LDC to build wasm projects

2024-08-23 Thread monkyyy via Digitalmars-d-learn
On Friday, 23 August 2024 at 05:50:43 UTC, Dakota wrote: any suggestions how to fix this? ```sh /ldc/bin/../import/core/stdc/stdio.d(31): Error: module ``` I dont use the std with wasm, everything imports everything else and there are just broken symbols deep in "core" that wont be fixed

Re: How do I compile D code for WASM? Any alternative runtime recommendations?

2024-08-28 Thread monkyyy via Digitalmars-d-learn
On Wednesday, 28 August 2024 at 19:08:58 UTC, Sergey wrote: In Discord we are collecting all links about different topics. We already have D & Wasm topic with most of the relevant links. airnt all the wasm projects by people not on the discord?

Re: Adding a partial specialization of std.conv.to for Typedef!string

2024-09-01 Thread monkyyy via Digitalmars-d-learn
On Sunday, 1 September 2024 at 11:01:13 UTC, kdevel wrote: In order to make this work ```d import std.typecons; alias vstring = Typedef!string; void main () { import std.stdio; import std.conv; auto v = 3.to!vstring; // ain't work out of the box writeln (v); auto w = 3.to!stri

Re: std.random.uniform failing

2024-09-03 Thread monkyyy via Digitalmars-d-learn
On Tuesday, 3 September 2024 at 11:57:42 UTC, remontoir wrote: Not really sure what is happening here. This works is "None" is removed, but displays a silly answer or fails with "range is smaller than amount of items to pop" otherwise. I guess it is related to enum being also integers ? ```d

Re: Is it possible to use templates to implement something like the `@show` macro from the Julia programming langauge in D?

2024-09-08 Thread monkyyy via Digitalmars-d-learn
On Sunday, 8 September 2024 at 22:01:10 UTC, WraithGlade wrote: I want to just be able to write this: ``` show!(1 + 2) ``` ```d void show(string s)(){ auto res=mixin(s); writeln(s,"==",res); } show!"1+2"; ```

Re: Is it possible to use templates to implement something like the `@show` macro from the Julia programming langauge in D?

2024-09-08 Thread monkyyy via Digitalmars-d-learn
On Monday, 9 September 2024 at 00:34:03 UTC, Paul Backus wrote: The only way is that a challenge? void main() { import std.stdio; mixin(show!"1 + 2"); // 1 + 2 == 3 const int x = 1 + 2; mixin(show!"x"); // x == 3 } ``` idk why you calling it a macro, im pretty sure d isnt

Re: Is it possible to use templates to implement something like the `@show` macro from the Julia programming langauge in D?

2024-09-09 Thread monkyyy via Digitalmars-d-learn
On Monday, 9 September 2024 at 17:39:46 UTC, WraithGlade wrote: import std; auto parse(char[] s)=>s[9..$-2]; void show(T,string file= __FILE__,int line=__LINE__)(T t){ writeln(File(file).byLine.drop(line-1).front.parse," == ",t); } void main(){ int i=3; show(i++ + ++i * i); sho

Re: Is it possible to use templates to implement something like the `@show` macro from the Julia programming langauge in D?

2024-09-09 Thread monkyyy via Digitalmars-d-learn
On Monday, 9 September 2024 at 19:29:01 UTC, Salih Dincer wrote: My only concern is why i == 5 in the line below when i == 28? i isn't being modified by a `*=`. its only the two ++

Re: Is it possible to use templates to implement something like the `@show` macro from the Julia programming langauge in D?

2024-09-09 Thread monkyyy via Digitalmars-d-learn
On Monday, 9 September 2024 at 20:52:09 UTC, WraithGlade wrote: This is not that surprising considering it uses hardcoded numbers and doesn't look right. I made it on dlang.io which does space tabs, if its not ovisous to a beginner, parse is ~~lazy~~ not correct, it need to do find substrin

Re: Is it possible to use templates to implement something like the `@show` macro from the Julia programming langauge in D?

2024-09-11 Thread monkyyy via Digitalmars-d-learn
On Wednesday, 11 September 2024 at 22:06:54 UTC, WB wrote: I feel there is too much already in D and standard library, and things are added to quickly and eagerly, and years later we end up in a mess that cannot be solved (because of compatibility). this isnt autodecoding, cant be, your oping

Re: nested function overloading

2022-06-21 Thread monkyyy via Digitalmars-d-learn
On Monday, 20 June 2022 at 13:20:51 UTC, Steven Schveighoffer wrote: And you can also use an inner struct to define overloaded functions. I believe templates make a better bandaid ```d void main(){ template bar(){ void bar_(int){} void bar_(float){}

Re: How to use templates in a separate library?

2022-06-23 Thread monkyyy via Digitalmars-d-learn
On Thursday, 23 June 2022 at 08:12:32 UTC, CrazyMan wrote: linking make sure you use the -i flag when compiling

Re: Coding Challenges - Dlang or Generic

2023-01-10 Thread monkyyy via Digitalmars-d-learn
On Tuesday, 10 January 2023 at 00:17:18 UTC, Paul wrote: I know. Someone's going to say why don't YOU do it:) https://github.com/crazymonkyyy/dingbats I could use contributors

Re: Coding Challenges - Dlang or Generic

2023-01-10 Thread monkyyy via Digitalmars-d-learn
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

better video rendering in d

2023-03-21 Thread monkyyy via Digitalmars-d-learn
My current method of making videos of using raylib to generate screenshots, throwing those screenshots into a folder and calling a magic ffmpeg command is ... slow. Does anyone have a demo or a project that does something smarter (or willing to do the busy work of finding the right combo of d

Re: better video rendering in d

2023-03-21 Thread monkyyy via Digitalmars-d-learn
On Tuesday, 21 March 2023 at 17:18:15 UTC, H. S. Teoh wrote: On Tue, Mar 21, 2023 at 04:57:49PM +, monkyyy via Digitalmars-d-learn wrote: My current method of making videos of using raylib to generate screenshots, throwing those screenshots into a folder and calling a magic ffmpeg command

Re: Removing an element from a DList

2023-10-17 Thread monkyyy 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;

Patterns for overload set recursion disambiguated by named arguments

2023-12-12 Thread monkyyy via Digitalmars-d-learn
raylib has a collection of well-organized but verbose functions https://www.raylib.com/cheatsheet/cheatsheet.html looking at draw colors are named `color` or if part of a gradient `color1` and `color2` `posx` and `centerx` are a bit more confusing but it should be fine etc. So I want to make

surviving wasm

2023-12-13 Thread monkyyy via Digitalmars-d-learn
so long term planning on wasm raylib; I want compatibility with the good parts of the std, the std is causal about using libc while ldc-wasm half-baked implication is missing a bunch of basically worthless symbols but given the std is 1 million lines of code it will be a perennial problem that

Re: surviving wasm

2023-12-13 Thread monkyyy via Digitalmars-d-learn
On Wednesday, 13 December 2023 at 21:15:47 UTC, Julian Fondren wrote: 6. statically build against musl and include it in the wasm binary. Since phobos is slow to change, its libc dependencies will also be slow to change, and you can work on reducing how much musl goes into the binary. Musl's

Re: Less verbose or at least "higher level" 2D game engines for Dlang.

2023-12-29 Thread monkyyy via Digitalmars-d-learn
On Saturday, 30 December 2023 at 00:47:04 UTC, Agent P. wrote: Hello everyone, I'm looking for a 2D game engine for Dlang that offers flexibility but has a high-level interface, preferably less verbose. Although I've explored options on GitHub and in general, I haven't found something that ex

Re: The One Billion Row Challenge

2024-01-13 Thread monkyyy via Digitalmars-d-learn
On Thursday, 11 January 2024 at 11:21:39 UTC, Sergey wrote: On Thursday, 11 January 2024 at 08:57:43 UTC, Christian Köstlin wrote: Did someone already try to do this in dlang? I guess it will be very hard to beat the java solutions running with graalvm! https://news.ycombinator.com/item?id=38

Re: Delegates and values captured inside loops

2024-01-20 Thread monkyyy via Digitalmars-d-learn
On Saturday, 20 January 2024 at 15:59:59 UTC, Anonymouse wrote: I remember reading this was an issue and now I ran into it myself. ```d import std.stdio; void main() { auto names = [ "foo", "bar", "baz" ]; void delegate()[] dgs; foreach (name; names) { dgs ~= () => wri

Re: length's type.

2024-01-28 Thread monkyyy via Digitalmars-d-learn
On Sunday, 28 January 2024 at 16:16:34 UTC, Olivier Pisano wrote: On Sunday, 28 January 2024 at 08:55:54 UTC, zjh wrote: On Sunday, 28 January 2024 at 06:34:13 UTC, Siarhei Siamashka wrote: The explicit conversion `.length.to!int` has an extra benefit I rarely use numbers over one million.

Re: length's type.

2024-01-28 Thread monkyyy via Digitalmars-d-learn
On Thursday, 18 January 2024 at 02:55:37 UTC, zjh wrote: Can you change the type of 'length' from 'ulong' to 'int', so I haven't to convert it every time! The devs are obviously very very wrong here I underflow indexs all the time But this is a pretty dead fight, I'd aim for a smart index ty

Re: Error when using `import`.

2024-03-01 Thread monkyyy via Digitalmars-d-learn
On Friday, 1 March 2024 at 05:07:24 UTC, Liam McGillivray wrote: I don't know how best to organize the code. So far I have been oo ideas for a 2nd opinion: https://github.com/crazymonkyyy/raylib-2024/blob/master/docs/examplecode.md Theres not a good learning resource but "data oirented desig

Re: How to make a struct containing an associative array to deeply copy (for repeated usage in foreach) ?

2024-03-14 Thread monkyyy via Digitalmars-d-learn
On Wednesday, 13 March 2024 at 22:16:52 UTC, rkompass wrote: I want to make a custom dictionary that I may iterate through with foreach. Several times. What I observe so far is that my dict as a simple forward range is exhausted after the first foreach and I have to deeply copy it beforehand.

Re: How to make a struct containing an associative array to deeply copy (for repeated usage in foreach) ?

2024-03-14 Thread Monkyyy via Digitalmars-d-learn
On Thursday, 14 March 2024 at 16:32:10 UTC, rkompass wrote: On Thursday, 14 March 2024 at 16:12:00 UTC, rkompass wrote: Hello @monkyyy again, your solution is much more elegant:-) No need to do a deep copy. I was thinking about a way to achieve that but had no clue. I will study opSlice now. Y

Re: varargs when they're not all the same type?

2024-03-14 Thread monkyyy via Digitalmars-d-learn
On Thursday, 14 March 2024 at 17:57:21 UTC, Andy Valencia wrote: Can somebody give me a starting point for understanding varadic functions? I know that we can declare them int[] args... and pick through whatever the caller provided. But if the caller wants to pass two int's and a _string_

Re: How to make a struct containing an associative array to deeply copy (for repeated usage in foreach) ?

2024-03-15 Thread monkyyy via Digitalmars-d-learn
On Friday, 15 March 2024 at 09:03:25 UTC, rkompass wrote: @Monkyyy: I adopted your solution, it is perfect. I only have one problem left: The foreach loop with associative arrays has two cases: `foreach(key, val; arr)` and `foreach(x; arr)`. In the second case only the values are iterated. Wit

Re: How to make a struct containing an associative array to deeply copy (for repeated usage in foreach) ?

2024-03-16 Thread monkyyy via Digitalmars-d-learn
On Friday, 15 March 2024 at 20:36:56 UTC, rkompass wrote: I start to see that D is heavily influenced by C++ (STL), not just C. This is not bad It is just bad; ranges are not pairs of 2 pointers, stepov was comprising with c++ or if he thinks c++ iterators are objectively good(not good fo

Re: Optimization when using a 2-dimensional array of objects

2024-03-22 Thread monkyyy via Digitalmars-d-learn
On Friday, 22 March 2024 at 02:19:07 UTC, Liam McGillivray wrote: In the [game I am currently making](https://github.com/LiamM32/Open_Emblem/blob/master/oe-raylib/source/app.d), I have a `Map` class (actually a combination of an interface & class template, but I'll call it a "class" for simplicit

Re: How can I tell D that function args are @nogc etc.

2024-04-13 Thread Monkyyy via Digitalmars-d-learn
On Friday, 12 April 2024 at 03:57:40 UTC, John Dougan wrote: Not every day you get to blame a compiler bug. D is uniquely: hacky, expressive and buggy. Having more metaprograming then c++ without the raw man power comes at a cost, in d you should distrust the spec and instead see what the

Re: need help to find a way to replace c macro

2024-10-15 Thread monkyyy via Digitalmars-d-learn
On Tuesday, 15 October 2024 at 12:05:16 UTC, Dakota wrote: ```c typedef union JSCFunctionType { JSCFunction *generic; JSValue (*generic_magic)(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv, int magic); JSCFunction *constructor; JSValue (*constructor_magic)(

Re: How to evaluate a JSON file at compile time and create a struct out of it?

2024-10-04 Thread monkyyy via Digitalmars-d-learn
On Friday, 4 October 2024 at 08:45:49 UTC, holyzantaclara wrote: Is there a way to achieve this? dub concerns ctfe risky whats this fud about? Will try to generate a .d file that would contain a static D object instead and then compile this .d file. While ctfe json is bad, you should st

Re: Splitting a project into different executable files

2024-10-12 Thread Monkyyy via Digitalmars-d-learn
On Saturday, 12 October 2024 at 01:09:56 UTC, Alexander Zhirov wrote: Is it possible to organize a project that will consist of several main files. I want to write several simple programs in one project, but for them to be divided into different files. So that it would be possible to choose dur

Re: Proper way to raise awareness of a bug

2024-10-29 Thread monkyyy via Digitalmars-d-learn
On Tuesday, 29 October 2024 at 16:59:48 UTC, Chris Piker wrote: Hi D There is a bug listed in the Bugzilla tracking tool that affected me the other day, [15526](https://issues.dlang.org/show_bug.cgi?id=15526). It's not a big problem, just an unexpected issue and seems easy to fix... by some

Re: Unexpected result with -betterC

2024-11-03 Thread monkyyy via Digitalmars-d-learn
On Sunday, 3 November 2024 at 19:00:33 UTC, DLearner wrote: The two fragments below compiled and ran as expected using dmd -betterC under Windows. ``` string Scrn = "OPO NAM='DspVar1' POS='1,1' VAR=('IntVar1','I');E"; printf("\nWR_Createtest entered.\n"); OpStructFstPtr = WR_Crea

Re: NGINX Unit and vibe.d Integration Performance

2024-11-04 Thread monkyyy via Digitalmars-d-learn
On Monday, 4 November 2024 at 18:05:25 UTC, Salih Dincer wrote: I'm glad to hear that. In the world of software, there is actually no problem that cannot be solved; except for the halting problem :) ? Id argue theres entire families of problems that are unsolvable; the halting problem may

Re: Unexpected result with -betterC

2024-11-03 Thread monkyyy via Digitalmars-d-learn
On Sunday, 3 November 2024 at 20:04:19 UTC, DLearner wrote: Surely the line: ``` string Scrn = "OPO NAM='DspVar1' POS='1,1' VAR=('IntVar1','I');E"; ``` creates, by the definition of 'string', a dynamic array? I believe thats stored in the binary

Re: std.algorithm.countUntil and alias

2024-10-23 Thread monkyyy via Digitalmars-d-learn
On Wednesday, 23 October 2024 at 17:18:47 UTC, Anton Pastukhov wrote: On Wednesday, 23 October 2024 at 14:50:44 UTC, Paul Backus wrote: On Wednesday, 23 October 2024 at 12:46:24 UTC, Paul Backus wrote: You can't use an `alias` to refer to a member variable like this. When you write al

Re: Why doesn't `opAssign` work for my templated struct?

2024-11-08 Thread monkyyy via Digitalmars-d-learn
On Friday, 8 November 2024 at 21:55:53 UTC, Liam McGillivray wrote: if(isNumeric!T) ``` Error: cannot implicitly convert expression `40.0F` of type `float` to `Milligrams` ``` I dont believe phoboes type detection templates are well designed; given some sort of type pattern matching issue yo

Re: Avoid subtracting form .length

2024-11-08 Thread monkyyy via Digitalmars-d-learn
On Friday, 8 November 2024 at 23:27:40 UTC, Dom DiSc wrote: I _very_ often use this pattern: ``` fun(ref int[] a) { assert(a.length && a.length<=100); int[100] b; b[0 .. a.length-1] = a[]; b[a.length .. 100] = 5; } ``` I consider this perfectly safe, but DScanner gives warnings for

Re: Integer precision of function return types

2024-09-26 Thread monkyyy via Digitalmars-d-learn
On Thursday, 26 September 2024 at 06:53:12 UTC, Per Nordlöw wrote: Should a function like ```d uint parseHex(in char ch) pure nothrow @safe @nogc { switch (ch) { case '0': .. case '9': return ch - '0'; case 'a': .. case 'f': return 10 + ch

Split by top level comma

2024-09-24 Thread monkyyy via Digitalmars-d-learn
I *strongly* believe the answer is not reasonable using phoboes tools; but Im going to leave it as an open question before I get started on something from scratch. Given well compliant phoboes-style ranges and a `ref string or retro!string` that starts with '(',')','[',']','{','}', modify tha

Re: Integer precision of function return types

2024-09-26 Thread monkyyy via Digitalmars-d-learn
On Friday, 27 September 2024 at 04:23:32 UTC, thinkunix wrote: What about using 'auto' as the return type? I tried it and it seemed to work OK. Wondering if there are any good reasons to use auto, or bad reasons why not to use auto here? You have started a style debate that will last a week,

Re: need help to work around float union non-zero init

2024-09-20 Thread monkyyy via Digitalmars-d-learn
On Friday, 20 September 2024 at 09:38:54 UTC, Dakota wrote: I need my struct defined as `isZeroInit`, so can I can import them as `di` file. (this also reduce build size) But I find this problem with float inside union: ```d struct test_t { union { int i32; float f32;

Re: Templates considered impressive

2024-10-01 Thread monkyyy via Digitalmars-d-learn
On Tuesday, 1 October 2024 at 05:44:16 UTC, H. S. Teoh wrote: why spend the time and effort when you could have just done: ``` import std.conv; theres a bunch of relivent tradeoffs and phoboes doesnt make a good set of them

Re: Would this function benefit from functional programming?

2024-11-20 Thread monkyyy via Digitalmars-d-learn
On Thursday, 21 November 2024 at 00:34:50 UTC, WhatMeWorry` wrote: I use this pattern very frequently throughout my code ``` void displayHex() { foreach(r; 0..rows) { foreach(c; 0..columns) { writeln("..."); foreach(p; 0..6) {

Re: File-like option where the "file contents" comes from a string?

2024-11-27 Thread monkyyy via Digitalmars-d-learn
On Wednesday, 27 November 2024 at 14:37:03 UTC, Andy Valencia wrote: With my OO programming goggles on, I can't help but notice that if Phobos had made File a class--or an interface-- oo doesn't own polymorphism you could do 99% of the value with ```d struct dummyfile{ auto byLineCopy()=>//s

Re: How can I have those "template instance recursive expansion" errors under control?

2024-12-01 Thread monkyyy via Digitalmars-d-learn
On Sunday, 1 December 2024 at 20:29:30 UTC, realhet wrote: Update: This not works! You have more code in that one file then I try to have in a *project*, so idk but if your still looking at the file, may as well say my thing But how can a standard template like CommonType or isNumeric go

Re: Partial application on Nth argument

2024-12-04 Thread monkyyy via Digitalmars-d-learn
On Wednesday, 4 December 2024 at 08:50:21 UTC, axricard wrote: Hello I believe std.functional.partial can only apply to the first argument. Is there an equivalent for the Nth argument ? Something like : ``` D int fun(int a, int b) { return a - b; } // create a function with the argument n°1

Re: Partial application on Nth argument

2024-12-05 Thread monkyyy via Digitalmars-d-learn
On Thursday, 5 December 2024 at 21:14:32 UTC, Salih Dincer wrote: static if unnecessary, check mine

Re: How to collect "some" items of a range in an array?

2025-01-06 Thread monkyyy via Digitalmars-d-learn
On Monday, 6 January 2025 at 19:30:27 UTC, Renato wrote: Is there any Phobos function that collects "some" items of a range into an array/slice? It's kind of embarrassing that I've been trying to find this for hours now without success :(. I think I know how to write this myself (though writin

Re: Kotlin Meta and CT programming vs D

2025-01-03 Thread monkyyy via Digitalmars-d-learn
On Friday, 3 January 2025 at 04:28:36 UTC, Jo Blow wrote: 30 years ago most entry level programmers were terrible. Because of evolution current entry level programmers are typically the equivalent of a seasoned programmer 30 years ago. Many kids now days are programming when most kids back th

Re: Simplify some C-style code

2024-12-29 Thread monkyyy via Digitalmars-d-learn
On Sunday, 29 December 2024 at 15:15:28 UTC, Andy Valencia wrote: On Saturday, 28 December 2024 at 23:23:02 UTC, monkyyy wrote: The spec would need to drastically improve before my opinion changes; Im also uninterested practicing withholding my opinions. There are many many ancient bugs, that

Re: Simplify some C-style code

2024-12-28 Thread monkyyy via Digitalmars-d-learn
On Friday, 27 December 2024 at 11:31:05 UTC, Nick Treleaven wrote: On Wednesday, 25 December 2024 at 21:34:00 UTC, monkyyy wrote: The spec is full of lies and slander, noun: lie; plural noun: lies an intentionally false statement. Can you please stop saying that the spec is intentionally

Re: help with prime pairs code

2025-02-02 Thread monkyyy via Digitalmars-d-learn
On Monday, 3 February 2025 at 04:15:09 UTC, Jabari Zakiya wrote: I translated this Ruby code: To this D code. It works, seems fast, can it be done shorter, faster, more idiomatic? translated code isnt going to be idiomatic ever; just state what you want done

when should ranges be static

2025-02-06 Thread monkyyy via Digitalmars-d-learn
I have template hell code; eventually 5 nested range calls have dual context-y issues and maybe compiler bugs; adding static makes those errors go away, adding static to everything makes new bugs. Wack-a-mole when the compiler gets confused about context is not a long term solution and for al

Re: unittest behaviour

2024-12-15 Thread monkyyy via Digitalmars-d-learn
On Sunday, 15 December 2024 at 08:45:22 UTC, DLearner wrote: I appreciate this behaviour matches the docs (so not a bug), but is it desirable? yes, the alternative would be that unittests attempt to undo themselves, and that would make bugs horrible horrible bugs or executable clear global

Re: How to do conditional scope(exit) ?

2024-12-18 Thread monkyyy via Digitalmars-d-learn
On Wednesday, 18 December 2024 at 22:16:45 UTC, John Dougan wrote: Is there a way to tell it that I want to use an enclosing scope or make it ignore the scope on the `if`? Cheers, -- John I dont think its anywhere near that smart, ive never seen a single usecase of scope(exit) do anything

Re: unittest behaviour

2024-12-17 Thread monkyyy via Digitalmars-d-learn
On Tuesday, 17 December 2024 at 21:31:13 UTC, DLearner wrote: On Tuesday, 17 December 2024 at 19:56:32 UTC, H. S. Teoh wrote: [...] That means the compiler will have to rerun your program once per unittest. That means your OS has to create a new process per unittest. If you have a lot of uni

Re: unittest behaviour

2024-12-17 Thread monkyyy via Digitalmars-d-learn
On Tuesday, 17 December 2024 at 19:16:55 UTC, DLearner wrote: On Sunday, 15 December 2024 at 20:30:21 UTC, monkyyy wrote: On Sunday, 15 December 2024 at 08:45:22 UTC, DLearner wrote: I appreciate this behaviour matches the docs (so not a bug), but is it desirable? yes, the alternative would

Re: D Tutorial

2024-12-20 Thread monkyyy via Digitalmars-d-learn
On Friday, 20 December 2024 at 16:10:05 UTC, Duke wrote: Just installed D. Need to work through an online tutorial for the language. Recommendations please. TIA .. https://github.com/crazymonkyyy/dingbats

Re: Virtual opBinary in interface

2024-12-19 Thread monkyyy via Digitalmars-d-learn
On Thursday, 19 December 2024 at 18:49:28 UTC, sfp wrote: perhaps `.d` files need to be added on the command line, or use `-i` to compile imports always try -i in response to any linker error

Re: Using a tuple as a function parameter

2024-11-22 Thread monkyyy via Digitalmars-d-learn
On Friday, 22 November 2024 at 17:24:08 UTC, Inkrementator wrote: Tuple access seems to be internally coded as a template (with unusual syntax) Its been a while since Ive tolerated std.tuple, is there any unusual syntax?

Re: Using a tuple as a function parameter

2024-11-22 Thread monkyyy via Digitalmars-d-learn
On Friday, 22 November 2024 at 16:36:43 UTC, Andrew wrote: I'm getting started using D for some small personal projects and one thing I wanted to do was use a helper function for a tuple. I declared the function like this: string getOrZeroth(Tuple!(string, string, string) tup, int i) pure

Navigating tradeoffs in bidirectional filter design

2025-01-09 Thread monkyyy via Digitalmars-d-learn
a unidirectional range filter can be implimented as simply as: ```d auto find(alias F,R)(R r){ while( ! r.empty && ! F(r.front)){ r.popFront; } return r; } unittest{ counter(5).find!(a=>a==3).summery; } auto findnext(alias F,R)(R r){ r.popFr

Re: Navigating tradeoffs in bidirectional filter design

2025-01-09 Thread monkyyy via Digitalmars-d-learn
On Friday, 10 January 2025 at 02:47:24 UTC, Salih Dincer wrote: On Thursday, 9 January 2025 at 21:56:59 UTC, monkyyy wrote: Im aware phoboes takes more complexity to implement filter and there should be *some* extra complexity to make a bidirectional filter, but when I ussally look into pho

Re: identify literals

2025-01-24 Thread monkyyy via Digitalmars-d-learn
On Friday, 24 January 2025 at 10:50:15 UTC, Dom DiSc wrote: Is it possible in D to find out if the parameter given to a function is a literal or a compile time constant? Of course, if it has _only_ parameters known at compile time, the function will be executed during CTFE, so I can check for

Re: Counting at compile-time

2025-01-26 Thread monkyyy via Digitalmars-d-learn
On Sunday, 26 January 2025 at 15:42:44 UTC, DLearner wrote: Suppose we have ``` enum Count = 0; static if () ... enum Count = Count + 1; // is disallowed else static if () ... enum Count = Count + 1; // is disallowed else ``` and the objective is to determine (at compile time) th

Re: Documentation re -betterC compatibility with standard library functions

2025-01-28 Thread monkyyy via Digitalmars-d-learn
On Tuesday, 28 January 2025 at 13:01:56 UTC, DLearner wrote: Is there a definitive list somewhere of standard library functions that work with -betterC? basicly none; phoboes causally imports itself and selective imports must parse the whole import still If you make a custom runtime or start

Re: std.conv:to that does not throw?

2025-01-29 Thread monkyyy via Digitalmars-d-learn
On Thursday, 30 January 2025 at 01:38:07 UTC, Kyle Ingraham wrote: Does D have a 'try' `std.conv:to` that does not throw if it fails? Something like: ```D string input = "9"; int output; auto parsed = input.tryTo!int(output); ``` `std.conv:to` is super flexible and does exactly what I need. Ho

Re: std.conv:to that does not throw?

2025-01-29 Thread monkyyy via Digitalmars-d-learn
On Thursday, 30 January 2025 at 03:01:43 UTC, Kyle Ingraham wrote: On Thursday, 30 January 2025 at 02:52:49 UTC, monkyyy wrote: its on my todo list for opend but isnt realisticly happening any time soon, I can suggest some patterns for setting up a cleaner `to` overloadset if you want to pick i

whats the best way to write short ciruitable reductions?

2025-01-13 Thread monkyyy via Digitalmars-d-learn
```d void issorted(R)(R r){ foreach(a,b;r.slide(2)){ if(a>b){return false;} } return true; } ``` the first pair of elements to be unsorted make issorted false; but my current `reduce` uses `last` which eagerly goes to the end of the list --- I can imagine 3 possible solutions(all ugl

Re: join() in CTFE very low performance

2025-01-04 Thread monkyyy via Digitalmars-d-learn
On Saturday, 4 January 2025 at 19:54:19 UTC, realhet wrote: It looks like they discover their parameter signatures every time from zero. Maybe those 'lazy wrappers' you mentioned can be inside text()? While it usually would be correct to assume Im being informal, in this case I wasn't; for

Re: Immutable (Rosetta code and learning D)

2025-01-04 Thread monkyyy via Digitalmars-d-learn
On Saturday, 4 January 2025 at 22:42:47 UTC, Andy Valencia wrote: On Saturday, 27 March 2021 at 20:44:12 UTC, Brad wrote: I was looking through lots of sample code on Rosetta Code. D has a lot of solutions out there. I'm following up to this older post, and I'm sure this is old news to many.

Re: join() in CTFE very low performance

2025-01-04 Thread monkyyy via Digitalmars-d-learn
On Saturday, 4 January 2025 at 13:56:47 UTC, realhet wrote: Hello, I have an array of array of strings, a 2D table encapsulated in a struct: The first few rows look like this. ```d enum TBL_niceExpressionTemplates = (表([ [q{/+Note: Name+/},q{/+Note: Example+/},q{/+Note: Pattern+/},q{/+Note:

Re: Simplify some C-style code

2024-12-25 Thread monkyyy via Digitalmars-d-learn
On Wednesday, 25 December 2024 at 07:49:28 UTC, sfp wrote: I have some code like this: ``` enum DomainType { Ball, Box, CsgDiff } struct Domain(int Dim) { DomainType type; union { Ball!Dim ball; Box!Dim box; CsgDiff!Dim csgDiff; } this(Ball!Dim ball) { this.type =

Re: How to iterate string enum values?

2024-12-24 Thread monkyyy via Digitalmars-d-learn
On Tuesday, 24 December 2024 at 12:07:56 UTC, Anton Pastukhov wrote: On Monday, 23 December 2024 at 23:46:33 UTC, Jim Balter wrote: I had the exact same issue yesterday. Allow me to quote ChatGPT: Thanks. That sounds plausible but I got burned by ChatGPT more than once, so I still would like

Re: Simplify some C-style code

2024-12-25 Thread monkyyy via Digitalmars-d-learn
On Wednesday, 25 December 2024 at 18:25:57 UTC, sfp wrote: What is a template map? I'd be interested in seeing this pattern and whether it's worth it to try to salvage std.sumtype. ```d import std; struct Ball(int i){} struct Box(int i){} struct CsgDiff(int i){} alias dimlist(int dim)=Alias

Re: Simplify some C-style code

2024-12-25 Thread monkyyy via Digitalmars-d-learn
On Wednesday, 25 December 2024 at 16:41:05 UTC, sfp wrote: On Wednesday, 25 December 2024 at 07:57:04 UTC, monkyyy wrote: static foreach, traits and mixin I was looking into this but I think I need some help getting off the ground... This doesn't compile: ``` enum Test { mixin("A, B, C") }

Re: Simplify some C-style code

2024-12-25 Thread monkyyy via Digitalmars-d-learn
On Wednesday, 25 December 2024 at 17:20:01 UTC, user1234 wrote: What you can do however is to use https://dlang.org/phobos/std_sumtype.html. instead of a the manually defined tagged union. If he's struggling to define a enum with a mixin I assume he's very new and to get this code to work wit

Re: Simplify some C-style code

2024-12-25 Thread monkyyy via Digitalmars-d-learn
On Wednesday, 25 December 2024 at 21:23:00 UTC, Jim Balter wrote: I suggest reading the spec rather than just trying random things. I suggest trying random things instead of reading the spec. The spec is full of lies and slander, and when your in template hell, defensively syntax test to find

Re: Why I can't modify a const(char[])[N]?

2024-12-29 Thread monkyyy via Digitalmars-d-learn
On Sunday, 29 December 2024 at 21:58:40 UTC, Renato Athaydes wrote: I expected this to be accepted by the compiler: ``` void foo(const(char[]) c) { const(char[])[2] d; d[0] = c; } ``` ```d void foo(const(char)[] c){ const(char)[][2] d; d[0] = c; } ``` *AND* ```d void foo(const(char[

Re: Template declaration of std.typecons.isTuple in -X JSON file.

2025-01-15 Thread monkyyy via Digitalmars-d-learn
On Wednesday, 15 January 2025 at 12:01:21 UTC, realhet wrote: Hello, I'm working on understanding and automating the contents of an X Json file generated by LDC2. I'm testing it by processing the whole Phobos lib. The weirdest thing that I've found is this: X Json: ``` ``` With my program, I

  1   2   >