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 Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 8 September 2024 at 22:01:10 UTC, WraithGlade wrote: Basically, I want there to be a way to print both an expression and its value but to only have to write the expression once (which also aids refactoring). Such a feature is extremely useful for faster print-based debugging. [...]

Re: Mixin Templates and Operators

2022-04-06 Thread Adam D Ruppe via Digitalmars-d-learn
On Wednesday, 6 April 2022 at 10:36:04 UTC, francesco.andreetto wrote: Am I doing something wrong or it is impossible to use mixin templates like that? mixin templates can't bring in operator overloads. The spec doesn't really say this I think, but that's the way it has been for a long time.

Re: Mixin Templates and Operators

2022-04-06 Thread Adam D Ruppe via Digitalmars-d-learn
On Wednesday, 6 April 2022 at 17:33:28 UTC, Steven Schveighoffer wrote: As I mentioned elsewhere, it does work. But the situation I think must be that it's only one mixin template. Probably also you can't have any overloads in the type itself. ooh yeah there's multiple here so the name

Re: Looking for a workaround

2022-04-06 Thread Adam D Ruppe via Digitalmars-d-learn
On Wednesday, 6 April 2022 at 18:10:32 UTC, Guillaume Piolat wrote: Any idea how to workaround that? Works fine if you just use the language instead of the buggy phobos wrappers: --- struct MyUDA { } class A { @MyUDA int a; } class B : A { @M

Re: arsd-minigui - couple of questions

2022-04-11 Thread Adam D Ruppe via Digitalmars-d-learn
On Monday, 11 April 2022 at 12:40:29 UTC, sai wrote: One more request, is it possible for you to do to ImageBox what you did to Button to show the transparent images (png)? Because Imagebox is showing black color for transparent pixels. oh yeah this one is different because the imagebox custom

Re: CTFE and BetterC compatibility

2022-04-27 Thread Adam D Ruppe via Digitalmars-d-learn
On Wednesday, 27 April 2022 at 14:21:15 UTC, Claude wrote: The operation requiring the D-runtime is appending the array, but it should **only** be done at compile-time. In that case, you want to prove to the compiler it is only called at compile time by encapsulating the function inside a temp

Re: Library for image editing and text insertion

2022-04-27 Thread Adam D Ruppe via Digitalmars-d-learn
On Wednesday, 27 April 2022 at 14:40:59 UTC, Alexander Zhirov wrote: Gorgeous! LDC has compressed my code at times! How small did it get? And with my libs if you import the other ones like `arsd.png` or `arsd.jpeg` directly instead of `arsd.image` that MIGHT help trim it down by removing sup

Re: Library for image editing and text insertion

2022-04-27 Thread Adam D Ruppe via Digitalmars-d-learn
On Wednesday, 27 April 2022 at 17:07:54 UTC, matheus wrote: I know about Adam Ruppe's work, I already used his terminal.d, but I think that unfortunately most people don't and I think it should be announced more in these parts. tbh sometimes i just don't feel like answering messages. even thi

Re: How do I get the screen resolution?

2022-04-28 Thread Adam D Ruppe via Digitalmars-d-learn
On Thursday, 28 April 2022 at 11:22:15 UTC, Alexander Zhirov wrote: Are there any methods to get the screen resolution? Call DisplayWidth/DisplayHeight on the X connection... my simpledisplay.d provides bindings (though not a high level helper function since both X and Windows calls are trivi

Re: CTFE and BetterC compatibility

2022-04-28 Thread Adam D Ruppe via Digitalmars-d-learn
On Thursday, 28 April 2022 at 12:36:56 UTC, Dennis wrote: In this case, it was actually a trailing whitespace in the changelog entry making the test suite fail, but the PR author Stefan's own `assert(__ctfe);` approach was better anyway...

Re: What's a good way to disassemble Phobos?

2022-04-30 Thread Adam D Ruppe via Digitalmars-d-learn
On Saturday, 30 April 2022 at 18:18:02 UTC, Dukc wrote: I'm looking for something where I could search for the call to the DRuntime functions in question, from an already combined .o or .a. What do you suggest? I'm on Linux. objdump -d works on .o files

Re: How to get compatible symbol names and runtime typeid names for templated classes?

2022-05-03 Thread Adam D Ruppe via Digitalmars-d-learn
On Tuesday, 3 May 2022 at 09:42:45 UTC, cc wrote: something I can pass to `Object.factory`. Object.factory is useless and will hopefully be removed someday. Instead, make your own factory registration function. Put a static constructor in the class which appends a factory delegate to an arra

Re: How to get compatible symbol names and runtime typeid names for templated classes?

2022-05-03 Thread Adam D Ruppe via Digitalmars-d-learn
On Tuesday, 3 May 2022 at 13:25:14 UTC, Arafel wrote: I'd like to do a runtime registration system myself, using a "template this" static constructor. A simple version supporting only default constructors would be: Yeah, you can't template this a static constructor, but you can just use a sta

Re: How to get compatible symbol names and runtime typeid names for templated classes?

2022-05-03 Thread Adam D Ruppe via Digitalmars-d-learn
On Tuesday, 3 May 2022 at 14:38:53 UTC, Arafel wrote: Actually, it would be cool to do it through an interface, although I don't think an interface's static constructors are invoked by the implementing classes... it would be cool, though. yeah interfaces can't have constructors. I'd try it my

Re: How to get compatible symbol names and runtime typeid names for templated classes?

2022-05-03 Thread Adam D Ruppe via Digitalmars-d-learn
On Tuesday, 3 May 2022 at 16:38:23 UTC, cc wrote: This is really interesting syntax, I'm surprised that works! Can read a little more on my blog about it: http://dpldocs.info/this-week-in-d/Blog.Posted_2019_06_10.html#tip-of-the-week pretty cool little pattern.

Re: Google Code Jam 2022

2022-05-06 Thread Adam D Ruppe via Digitalmars-d-learn
On Friday, 6 May 2022 at 04:26:13 UTC, Siarhei Siamashka wrote: So it may seem that D should be a very good choice for programming competitions, but there's still no success. Programming competitions are a 100% waste of time. I'm too busy doing real work.

Re: What are (were) the most difficult parts of D?

2022-05-11 Thread Adam D Ruppe via Digitalmars-d-learn
On Thursday, 12 May 2022 at 01:06:02 UTC, Christopher Katko wrote: completely different semantics for a class vs a struct. Is it a reference? Is it a value? Look up the entire declaration and have the entire Dlang manual open to find out. As far as I remember, no automatic RAII support, even t

Re: What are (were) the most difficult parts of D?

2022-05-12 Thread Adam D Ruppe via Digitalmars-d-learn
On Thursday, 12 May 2022 at 14:42:43 UTC, Anonymouse wrote: That said, one thing I cannot seem to firmly wrap my head around is `is` expressions. `is` does so many things. It is simpler than it looks, I wrote about it in my book and in a post here: https://forum.dlang.org/post/xklcgjaqggihvh

Re: What are (were) the most difficult parts of D?

2022-05-12 Thread Adam D Ruppe via Digitalmars-d-learn
On Thursday, 12 May 2022 at 15:18:34 UTC, jmh530 wrote: What's the difference between a Type and Type Identifier? The is expression roughly follows variable declaration style. You write int a; to declare a new symbol named `a` of type `int`. Similarly, static if(is(T a)) declares a new sy

Re: What are (were) the most difficult parts of D?

2022-05-13 Thread Adam D Ruppe via Digitalmars-d-learn
On Friday, 13 May 2022 at 18:23:58 UTC, H. S. Teoh wrote: On Thu, May 12, 2022 at 11:45:47PM +, Guillaume Piolat via It's a problem because it goes from solving "no accidental race condition" and you get "people forget to add shared or __gshared and their shared library silently fail" situa

Re: D WebAssembly working differently than C++, Zig

2022-05-16 Thread Adam D Ruppe via Digitalmars-d-learn
I would suspect it is something to do with your memset... even if it needs to take the int (wtf but ldc is weird) you might want to reinterpret cast it to float to avoid any extra conversions.

Re: D WebAssembly working differently than C++, Zig

2022-05-17 Thread Adam D Ruppe via Digitalmars-d-learn
On Monday, 16 May 2022 at 18:17:03 UTC, Allen Garvey wrote: Thanks so much, that fixed the problem! You have no idea have long I have spent trying to debug this! Oh I should have checked my impl, where I did all this already! https://github.com/adamdruppe/webassembly/blob/master/arsd-webassemb

Re: D WebAssembly working differently than C++, Zig

2022-05-17 Thread Adam D Ruppe via Digitalmars-d-learn
On Tuesday, 17 May 2022 at 11:43:45 UTC, Siarhei Siamashka wrote: Looks like you forgot to increment the pointer and need "*d++ = cast(ubyte) c;" there. hahaha yup. And filling the buffer one byte at a time is likely slow. prolly but meh, that's where the intrinsics are nice.

Re: Why are structs and classes so different?

2022-05-17 Thread Adam D Ruppe via Digitalmars-d-learn
On Tuesday, 17 May 2022 at 14:40:48 UTC, Kevin Bailey wrote: Foo foo; is undefined behavior waiting to happen, that I can't detect at a glance. It is actually perfectly well defined - for the class, it will be null, and this will kill the program if you use it. You might not like that defi

Re: Error: undefined symbol: _WinMain@16 When try compile no console

2022-05-19 Thread Adam D Ruppe via Digitalmars-d-learn
On Thursday, 19 May 2022 at 19:29:25 UTC, Marcone wrote: Using -L/SUBSYSTEM:windows user32.lib you using a main() function right? Please note when compiling on Win64, you need to explicitly list -Lgdi32.lib -Luser32.lib on the build command. If you want the Windows subsystem too, use -L/subs

Re: Error: undefined symbol: _WinMain@16 When try compile no console

2022-05-19 Thread Adam D Ruppe via Digitalmars-d-learn
On Thursday, 19 May 2022 at 20:20:49 UTC, Marcone wrote: I am using a main() function. I am compiling on Windows x86 32 bits. I am using DMD 2.100.0 This error is only in version 2.100.0 of DMD. Are you using the `-L/entry:mainCRTStartup` or the `L/entry:wmainCRTStartup` ?

Re: UI Library

2022-05-20 Thread Adam D Ruppe via Digitalmars-d-learn
On Friday, 20 May 2022 at 03:47:14 UTC, harakim wrote: Thank you. I will definitely give that a try. My minigui uses the normal Windows controls so it works well there. On linux it uses a custom thing of my own design so your mileage may vary. The docs don't have a lot of examples but hopef

Re: template? mixin? template mixins? for modifying a struct setup

2022-05-20 Thread Adam D Ruppe via Digitalmars-d-learn
On Friday, 20 May 2022 at 14:54:31 UTC, Christopher Katko wrote: If the declarations are at module scope, `static` has no effect, and CTFE will be used for initialization. It won't use CTFE? Why is there a local module requirement? "module scope" just means at the top level in a module. so n

Re: Sleep in a cycle

2022-05-20 Thread Adam D Ruppe via Digitalmars-d-learn
On Friday, 20 May 2022 at 14:59:07 UTC, Alexander Zhirov wrote: I have a loop spinning, I want to pause in it in order to repeat the next iteration. An error is displayed during compilation. The error has nothing to do with the sleep source/app.d(32,5): Warning: statement is not reachable Er

Re: Install DCD language server on Raspberrry PI4 (aarch64) requires rdmd , command not found.

2022-05-21 Thread Adam D Ruppe via Digitalmars-d-learn
On Saturday, 21 May 2022 at 22:44:55 UTC, Alain De Vos wrote: Can I compile rdmd from source ? Yes, rdmd is a trivial program. https://github.com/dlang/tools/blob/master/rdmd.d

Re: Allocate a string via the GC

2022-05-23 Thread Adam D Ruppe via Digitalmars-d-learn
On Monday, 23 May 2022 at 09:38:07 UTC, JG wrote: Hi, Is there any more standard way to achieve something to the effect of: ```d import std.experimental.allocator; string* name = theAllocator.make!string; ``` Why do you want that? Easiest way I know of is to just wrap it in a struct,

Re: Allocate a string via the GC

2022-05-23 Thread Adam D Ruppe via Digitalmars-d-learn
On Monday, 23 May 2022 at 12:20:11 UTC, JG wrote: I am writing an interpreter and I needed access to a string via a pointer of type void* I ended up wrapping it in a struct since I needed another value anyway. Seems odd that one can't do it in a less unusual way. OK yeah, that's the main use c

Re: How are delegate attributes in fn signature inferred?

2022-05-23 Thread Adam D Ruppe via Digitalmars-d-learn
On Monday, 23 May 2022 at 13:44:53 UTC, wjoe wrote: i.construct((ulong i) {return cast(int)(i+i);}).print; You can actually make this work with `construct!(int[])` rather than plain `construct`. This is a (really annoying) deficiency in dmd's implementation. (that sdc solved btw proving it

Re: Cannot check function address

2022-05-24 Thread Adam D Ruppe via Digitalmars-d-learn
On Tuesday, 24 May 2022 at 22:10:21 UTC, frame wrote: To also anwser to Adam: no, this symbol is unique. The first line of the error says: ``` Error: function `a.fun(string param)` is not callable using argument types `()`. ``` There's a big difference between a function and a function poi

Re: gdc 12.1: undefined references when linking separately compiled files

2022-05-28 Thread Adam D Ruppe via Digitalmars-d-learn
On Saturday, 28 May 2022 at 13:12:46 UTC, kdevel wrote: gdc -o ppinsta ppinsta.o esah.o evaluate.o jsr.o jsw.o parser.o ptvr.o stack.o testdatagenerator.o You might need to add -lgphobos or -lgphobos2 or whatever it is called too explicitly.

Re: gdc 12.1: undefined references when linking separately compiled files

2022-05-28 Thread Adam D Ruppe via Digitalmars-d-learn
On Saturday, 28 May 2022 at 14:16:51 UTC, kdevel wrote: $ gdc -o ppinsta ppinsta.d parser.d Compiling together is faster anyway this is prolly what you want most the time. But I know what's going on now, it is the template emission thing, the compiler thinks, since it is from std, it was al

Re: Basic SQLite Application

2022-06-01 Thread Adam D Ruppe via Digitalmars-d-learn
On Wednesday, 1 June 2022 at 03:46:38 UTC, harakim wrote: I started trying to get it to compile in another directory structure but since I've switched to dub It should work the way you have it, just with dub you can also the dub version instead of copying the files: https://code.dlang.org/pac

Re: Basic SQLite Application

2022-06-01 Thread Adam D Ruppe via Digitalmars-d-learn
On Wednesday, 1 June 2022 at 15:40:43 UTC, harakim wrote: It's been a long time since I did any C development, and I have never done any on windows, but I thought I could statically link to the .lib at compile time and then I wouldn't need a dll. You sometimes can, it depends on how the librar

Re: Dynamic Arrays Capacity

2022-06-03 Thread Adam D Ruppe via Digitalmars-d-learn
On Friday, 3 June 2022 at 12:49:07 UTC, bauss wrote: I believe it's only true in unicode for utf-32 since all characters do fit in the 4 byte space they have Depends how you define "character".

Re: Comparing Exceptions and Errors

2022-06-05 Thread Adam D Ruppe via Digitalmars-d-learn
On Sunday, 5 June 2022 at 10:38:44 UTC, Ola Fosheim Grøstad wrote: That is a workaround that makes other languages more attractive. It is what a lot of real world things do since it provides additional layers of protection while still being pretty easy to use. *Correctness **is** probabilis

Re: How to map machine instctions in memory and execute them? (Aka, how to create a loader)

2022-06-06 Thread Adam D Ruppe via Digitalmars-d-learn
On Monday, 6 June 2022 at 15:13:45 UTC, rempas wrote: void* code = mmap(null, cast(ulong)500, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANON, -1, 0); On a lot of systems, it can't be executable and writable at the same time, it is a security measure. see https://en.wikipedia.or

Re: 'each' can take static arrays

2022-06-10 Thread Adam D Ruppe via Digitalmars-d-learn
On Friday, 10 June 2022 at 16:59:04 UTC, Ali Çehreli wrote: Why the inconsistency? Phobos has dozens of random special cases throughout. I'd prefer if these were all removed, but right now there's just some functions that special case to allow it and others that don't. Apparently each is on

Re: UI Library

2022-06-11 Thread Adam D Ruppe via Digitalmars-d-learn
On Saturday, 11 June 2022 at 01:20:17 UTC, harakim wrote: The issue I'm having is that I don't understand how to assign bounds in the nested widget. I'm sure there's a very clean solution. I basically want a paintContent method but with the bounds dynamically assigned by the parent. Well the

Re: UI Library

2022-06-11 Thread Adam D Ruppe via Digitalmars-d-learn
On Saturday, 11 June 2022 at 21:44:17 UTC, harakim wrote: I tried the solution I suggested and it did not work because the child would occlude the parent (which is in the comments now that I see it.) yeah minigui's model is to tile the widgets; they aren't supposed to overlap (except their pa

Re: Creating DLL

2022-06-16 Thread Adam D Ruppe via Digitalmars-d-learn
On Thursday, 16 June 2022 at 13:57:48 UTC, Sergeant wrote: export int my(int a, int b) the name here is going to be mangled, so like "_D5mydll2myiiZi" or something like that. You might want to add `extern(C)` to it so it keeps the simple name "my", that might help.

Re: Creating DLL

2022-06-16 Thread Adam D Ruppe via Digitalmars-d-learn
On Thursday, 16 June 2022 at 16:07:41 UTC, Sergeant wrote: May I ask one more question: why a code like this would work in D-application but not in D-DLL? (also I notice some other D functions don't work in DLL): Probably because the runtime not initialized properly. Export an Initialize() an

Re: Creating DLL

2022-06-16 Thread Adam D Ruppe via Digitalmars-d-learn
On Thursday, 16 June 2022 at 16:19:22 UTC, Ali Çehreli wrote: pragma (crt_constructor) You have to be pretty careful about this since it might not run in the order you expect. If there's two things in the program with a equal-priority crt constructor, they are run in arbitrary order. In a sh

Re: Creating DLL

2022-06-16 Thread Adam D Ruppe via Digitalmars-d-learn
On Thursday, 16 June 2022 at 16:37:34 UTC, Ali Çehreli wrote: Agreed but that excludes using the D runtime in 'static this' (and shared) blocks, right? It is runtime.initialize that calls those `static this` blocks. If my explicit call to Initialize is in a 'shared static this' This is back

Re: multidim array with enum

2022-06-18 Thread Adam D Ruppe via Digitalmars-d-learn
On Saturday, 18 June 2022 at 17:19:24 UTC, Chris Katko wrote: I'm having difficulty figuring out exactly what signature D is expecting. BITMAP*[2][DIR] bmps; I'm actually not sure if that [DIR] is an associative array or DIR's base type or a static array of DIR's size. I *think* it is an a

Re: can you initialize a array of POD structs?

2022-06-18 Thread Adam D Ruppe via Digitalmars-d-learn
On Saturday, 18 June 2022 at 17:37:44 UTC, Chris Katko wrote: D struct pair { float x, y;} pair p[] = [[0, 0], [255, 255], [25,-25]]; //nope An array of pair is `pair[]`, keep the brackets with the type. Then a struct literal is either: pair(0, 0) // using constructor syntax or in

Re: destroy and @safe

2022-06-21 Thread Adam D Ruppe via Digitalmars-d-learn
On Tuesday, 21 June 2022 at 15:13:36 UTC, Paul Backus wrote: `destroy` should be `@safe` as long as the destructor it's calling is `@safe`. For classes, the current dmd+druntime implementation makes it impossible to determine statically if the destructor is safe or not. Structs I'm not sure

Re: dlang bug - accessing module variable from method segfaults only when using module reference directly

2022-07-01 Thread Adam D Ruppe via Digitalmars-d-learn
On Friday, 1 July 2022 at 12:57:01 UTC, Chris Katko wrote: Cannot access memory at address 0x10 Looks like an ordinary null pointer. How did you create the variable?

Re: How to check if something can be null

2022-07-01 Thread Adam D Ruppe via Digitalmars-d-learn
On Friday, 1 July 2022 at 13:48:25 UTC, Antonio wrote: I has been using this pattern each time something needs special treatment when it can be null: i'd prolly check `static if(is(typeof(null) : T))` which means if the null literal implicitly converts to type T. there's also the bludgeon __

Re: How to call a function from a dll created with d ?

2022-07-01 Thread Adam D Ruppe via Digitalmars-d-learn
On Friday, 1 July 2022 at 22:32:24 UTC, Vinod K Chandran wrote: So using a `def` file is a must I think. no it is not. you just need to mark things export and make sure names match (including module name)

Re: How to obtain Variant underlying type?

2022-07-09 Thread Adam D Ruppe via Digitalmars-d-learn
On Saturday, 9 July 2022 at 14:36:44 UTC, anonymouse wrote: auto vb = v.base; // what should I put here to achieve the following: typeof(vb); // int[][] Impossible; Variant's type is only known at runtime, and this would require compile time knowledge.

Re: How can I convert a file encode by CP936 to a file with UTF-8 encoding

2022-07-13 Thread Adam D Ruppe via Digitalmars-d-learn
On Wednesday, 13 July 2022 at 11:47:56 UTC, rocex wrote: How can I convert a file encode by CP936 to a file with UTF-8 encoding My lib doesn't have it included but the basic idea is to take this table: https://www.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP936.TXT and do the conve

Re: File.write introduces \r regardless of presence

2022-07-16 Thread Adam D Ruppe via Digitalmars-d-learn
On Saturday, 16 July 2022 at 19:54:08 UTC, HuskyNator wrote: File("test.txt", "w").write(a); The default here is write in text mode, change the "w" to "wb" and it won't molest your line endings any more.

Re: mixin template bug with opBinary?

2022-07-22 Thread Adam D Ruppe via Digitalmars-d-learn
On Friday, 22 July 2022 at 12:33:37 UTC, Anthony Quizon wrote: Is this a bug or am I doing something wrong? I think this is a bug. The compiler must not take well to this pattern, maybe the assoc array template argument, but idk. It looks like the first type used gets cached and reused even i

Re: Using "%s" with inputting numberic values

2022-07-24 Thread Adam D Ruppe via Digitalmars-d-learn
On Sunday, 24 July 2022 at 23:12:46 UTC, pascal111 wrote: In the next code, we used "%s" format with receiving an integer value, while from C experience, we know that we use "%d" or "%i" formats, so what "%s" stands for here, I guess it's for receiving string data type? The D things in std.st

Re: "string" data type with readln

2022-07-25 Thread Adam D Ruppe via Digitalmars-d-learn
On Monday, 25 July 2022 at 19:55:40 UTC, pascal111 wrote: I tried to type small program, and tried to use "string" data type with "readln", but the compiler refused it, and I had to use "char[]". the overload you used modifies the array you give it try string s = readln();

Re: BASIC "sgn" function equivalent

2022-07-28 Thread Adam D Ruppe via Digitalmars-d-learn
On Thursday, 28 July 2022 at 12:02:54 UTC, pascal111 wrote: I'm making an equivalent of "sgn" function of BASIC language, and I used "(T)" in its definition, but the function can receive wrong data by passing string data to it, how we can solve it? There's no need to do the complication of a

Re: Write binary data as a file

2022-08-02 Thread Adam D Ruppe via Digitalmars-d-learn
On Tuesday, 2 August 2022 at 11:10:27 UTC, Alexander Zhirov wrote: As a result, I get only a set of text data. my database layer is doing to!string(that_ubyte) which is wrong. gonna see about pushing a fix

Re: How to find all modules in a package?

2022-08-03 Thread Adam D Ruppe via Digitalmars-d-learn
On Wednesday, 3 August 2022 at 03:36:55 UTC, Domain wrote: I want to find out all public functions in all modules in a package. Can I do that at compile time? No, D packages are not closed; anyone can add new modules to them at any time.

Re: curses/ncurses liberary in D

2022-08-04 Thread Adam D Ruppe via Digitalmars-d-learn
On Thursday, 4 August 2022 at 21:15:39 UTC, pascal111 wrote: https://github.com/adamdruppe/arsd/blob/master/terminal.d How can I use this terminal module? Is there a document for it? http://arsd-official.dpldocs.info/arsd.terminal.html

Re: curses/ncurses liberary in D

2022-08-05 Thread Adam D Ruppe via Digitalmars-d-learn
On Friday, 5 August 2022 at 04:14:22 UTC, H. S. Teoh wrote: including cursorX, cursorY Worth noting these are not initialized in linear mode, only in fullscreen/cellular. I might change that soon, it is on my todo list. (Granted, though, the main page could be expanded to include examples

Re: curses/ncurses liberary in D

2022-08-05 Thread Adam D Ruppe via Digitalmars-d-learn
On Friday, 5 August 2022 at 18:20:36 UTC, pascal111 wrote: But I'll need help to understand some functions like how we can use "readf" equivalent, I don't see it. http://arsd-official.dpldocs.info/arsd.terminal.html#get-line get a line then strip it and convert to whatever numbers you want et

Re: My programs issues

2022-08-10 Thread Adam D Ruppe via Digitalmars-d-learn
On Wednesday, 10 August 2022 at 12:36:42 UTC, pascal111 wrote: 1) I used "exit()" from "core.stdc.stdlib;" module, but someone can say this isn't the D way to exit the program. It is better to simply return a value from main instead. 2) I used "goto", I heard from someone before that using "go

Re: How to use exceptions

2022-08-11 Thread Adam D Ruppe via Digitalmars-d-learn
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 the lack of information disturbing, but I

Re: How to use exceptions

2022-08-11 Thread Adam D Ruppe via Digitalmars-d-learn
On Thursday, 11 August 2022 at 23:50:58 UTC, H. S. Teoh wrote: I think the OP's idea is somewhat different: adding contextual information to a propagating exception that the throwing code may not have access to. Yeah, but you can use the mechanism again: you'd catch the one then throw a new o

Re: How to use exceptions

2022-08-11 Thread Adam D Ruppe via Digitalmars-d-learn
On Friday, 12 August 2022 at 00:40:48 UTC, H. S. Teoh wrote: Hmm! That gets me thinking. Maybe something like this? aye. and scopes share dtors which means we can do it in the lib today: --- struct AdditionalInfo { static string[] info; this(string info) { A

Re: Recommendation for parallelism with nested for loops?

2022-08-18 Thread Adam D Ruppe via Digitalmars-d-learn
On Friday, 19 August 2022 at 01:49:43 UTC, Shriramana Sharma wrote: Also, what is the best way to do parallelism in such a situation? If the inner loops are about the same size for each pass of the outer loop, you can just simply parallel on the outer loop and get the same benefit. Even if

Re: Best practice for dub registry package and module names

2022-09-04 Thread Adam D Ruppe via Digitalmars-d-learn
On Sunday, 4 September 2022 at 01:52:11 UTC, Ali Çehreli wrote: Should the package be the author's name: acehreli.a, acehreli.b, and acehreli.c? This is what I'd suggest. You want something that nobody else is likely to step on throughout the entirety of the D ecosystem. It doesn't have to li

Re: Best practice for dub registry package and module names

2022-09-04 Thread Adam D Ruppe via Digitalmars-d-learn
On Sunday, 4 September 2022 at 03:50:56 UTC, Ali Çehreli wrote: For example, there is fixedsizearray, which does not belong to any package: Yeah, this is bad design since two separate people might reuse the name and then end users - even if it comes through a couple layers of dependencies the

Re: Is there a way to

2022-09-10 Thread Adam D Ruppe via Digitalmars-d-learn
On Saturday, 10 September 2022 at 23:37:30 UTC, Kyle Ingraham wrote: How can I write a type that is strict for the first two parameters but tolerant of any other parameter following those? That's not a type per se, but you can assign wrapper at the assignment thing. Like your_delegate = (a,

Re: Is there a way to

2022-09-10 Thread Adam D Ruppe via Digitalmars-d-learn
On Sunday, 11 September 2022 at 00:32:18 UTC, Kyle Ingraham wrote: I can't use default parameters because I want to be able to call the delegate with arguments extracted from a URL path at runtime Some kind of wrapper might not only be your best option, it might be your only option. Your de

Re: Is it valid in D to write an opSlice overload that takes no arguments?

2022-09-11 Thread Adam D Ruppe via Digitalmars-d-learn
On Sunday, 11 September 2022 at 09:47:34 UTC, solidstate1991 wrote: Here's this code: This should be allowed, but also the way you're supposed to write it now is a no-argument opIndex.

Re: Is this a new bug ?

2022-09-24 Thread Adam D Ruppe via Digitalmars-d-learn
On Saturday, 24 September 2022 at 06:13:55 UTC, test123 wrote: If so please report it for me to bugs platform. This isn't a bug, the effect of keyword: things stop at the matching }. (static if and version don't introduce a namespace scope, but they still follow this rule for the { colon: .

Re: Detect uninitialized class var access

2022-09-24 Thread Adam D Ruppe via Digitalmars-d-learn
On Saturday, 24 September 2022 at 13:17:19 UTC, rassoc wrote: just crashes with `Error: program killed by signal 11` on linux and nothing else. gdb --args ./your_program and then it will tell you all the details you want to know about when this happens. strangly sometimes adding the -O opti

Re: Template function alias that leaves out the last type parameter

2022-09-27 Thread Adam D Ruppe via Digitalmars-d-learn
On Tuesday, 27 September 2022 at 22:39:52 UTC, torhu wrote: How would I achieve something like this, do I have to turn the aliases into functions? You can write it out long-form with two steps like this: --- template _messageBox(string title, int style) { void _messageBox(T...)(T args)

Re: Way to pass params to a function passed to a fiber?

2022-10-03 Thread Adam D Ruppe via Digitalmars-d-learn
On Monday, 3 October 2022 at 08:10:43 UTC, Bienlein wrote: Hello, I'm looking for a way to pass parameters to a function called by a fiber. Starting a fiber works like this: You can also make a subclass of fiber that stores them with the object.

Re: DateTime resetting

2022-10-11 Thread Adam D Ruppe via Digitalmars-d-learn
On Tuesday, 11 October 2022 at 22:09:34 UTC, Joel wrote: I've been working on a diary program (ChronoLog). but lately my date and time variable keeps resetting. I've spent hours trying to fix it. I'm wondering if there's a known issue. An ordinary DateTime variable? Those are pretty simple and

Re: DateTime resetting

2022-10-11 Thread Adam D Ruppe via Digitalmars-d-learn
I'm just eyeballing the code, is it the g_dateTimeCursor you're concerned about? That's the only one I really see there. A few things that might explain it: 1) as a global variable, it is thread local. I don't see any use of threads in here, but if you do, each one has a separate copy and oth

Re: Can someone tell me what the compiler thought I was trying to do?

2022-10-18 Thread Adam D Ruppe via Digitalmars-d-learn
On Wednesday, 19 October 2022 at 00:57:31 UTC, H. S. Teoh wrote: Has it really been implemented? I tested the latest git master, the following code doesn't compile: it only applies to types, not to functions.

Re: Can someone tell me what the compiler thought I was trying to do?

2022-10-18 Thread Adam D Ruppe via Digitalmars-d-learn
On Wednesday, 19 October 2022 at 01:34:54 UTC, mw wrote: Is there any (design) doc about this? scroll up, click the link from this very thread. https://github.com/dlang/DIPs/blob/master/DIPs/accepted/DIP1038.md#design-goals-and-possible-alternatives

Re: Is "auto t=T();" not the same as "T t;"?

2022-10-25 Thread Adam D Ruppe via Digitalmars-d-learn
On Tuesday, 25 October 2022 at 13:51:30 UTC, Andrey Zherikov wrote: A[] a = [A.init]; This is a problem - this is referring to a static array instance, shared across all copies of B. You almost certainly don't want this. That B.a[0] is the *same object* across different default-constru

Re: Importing modules under DUB on Windows

2022-10-28 Thread Adam D Ruppe via Digitalmars-d-learn
On Wednesday, 26 October 2022 at 16:20:01 UTC, DLearner wrote: Wanted to use a function stored in a module outside the main source. easiest thing to do with dub is to add it as a sourcePath or a sourceFile. Well, actually, easiest is to just copy the module right into your default src folder,

Re: Importing modules under DUB on Windows

2022-10-28 Thread Adam D Ruppe via Digitalmars-d-learn
On Friday, 28 October 2022 at 15:15:04 UTC, DLearner wrote: Took suggestion, dub run then produced: `Linking... lld-link: error: subsystem must be defined Error: linker exited with status 1` That means the linker didn't see a `main` function. Make sure you have a `void main() {}` somewhere (an

Re: overloading main

2022-10-30 Thread Adam D Ruppe via Digitalmars-d-learn
On Sunday, 30 October 2022 at 16:09:54 UTC, NonNull wrote: I am linking to a C project with some C already automatically translated into D including the C main function `int main(int argc, char** argv){/* ... */}` which I wanted to call from a D main function in a new module. did you put exte

Re: Make IN Dlang

2022-11-01 Thread Adam D Ruppe via Digitalmars-d-learn
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

Re: What's the correct way of creating an instance of class in D?

2022-11-03 Thread Adam D Ruppe via Digitalmars-d-learn
On Thursday, 3 November 2022 at 15:40:02 UTC, H. S. Teoh wrote: D does not have the equivalent of C++'s allocating a class instance on the stack. In D, all class instances are allocated on the heap and class variables are references to them. well there is scope Object o = new Object; which

Re: Hipreme's #4 Tip of the day - Don't use package.d

2022-11-04 Thread Adam D Ruppe via Digitalmars-d-learn
On Friday, 4 November 2022 at 14:11:55 UTC, bauss wrote: Having used D for like a decade at this point, I've never experienced any issues with it. Lucky you, lots of other people have. Broken phobos updates, impossible to transition to it without code breakages (which is the only reason it ex

Re: Hipreme's #4 Tip of the day - Don't use package.d

2022-11-04 Thread Adam D Ruppe via Digitalmars-d-learn
On Friday, 4 November 2022 at 19:10:33 UTC, jmh530 wrote: If you don't plan to use private(package_name), then I don't know what the point of it is. This works fine without the package.d anyway.

Re: Hipreme's #4 Tip of the day - Don't use package.d

2022-11-04 Thread Adam D Ruppe via Digitalmars-d-learn
On Friday, 4 November 2022 at 19:34:58 UTC, jmh530 wrote: Oh really, then what's the point of package.d? It was originally added because Phobos had `std.algorithm` and `std.datetime` and some people wanted to break them up into pieces, but not break user code that still said `import std.algo

Re: Hipreme's #4 Tip of the day - Don't use package.d

2022-11-04 Thread Adam D Ruppe via Digitalmars-d-learn
On Friday, 4 November 2022 at 19:40:09 UTC, H. S. Teoh wrote: So that you can import abc.def separately from abc.def.ghi and abc.def.jkl. This isn't that hard; in the old days you'd have `pkg.foo` then `import pkg.all` instead of `import pkg;`. The specific thing that led to the package.d thi

Re: My new programming book ...

2022-11-06 Thread Adam D Ruppe via Digitalmars-d-learn
On Monday, 7 November 2022 at 00:55:33 UTC, zjh wrote: Is there a second edition? After all, it has been many years. No, but not that much has changed and you can always post here with questions.

Re: Passing a string by reference

2022-11-08 Thread Adam D Ruppe via Digitalmars-d-learn
On Tuesday, 8 November 2022 at 12:30:50 UTC, Alexander Zhirov wrote: Do I understand correctly that in order for me to pass a string when creating an object, I must pass it by value? You should almost never use `ref string`. Just use plain `string`. In fact, ref in general in D is a lot more r

Re: My new programming book ...

2022-11-08 Thread Adam D Ruppe via Digitalmars-d-learn
On Monday, 7 November 2022 at 04:54:05 UTC, ikelaiah wrote: I'm aware of the publication date. However, I find the content still highly relevant to many day-to-day tasks (my use case). Yeah, I tried to focus more on the ideas behind it than the specifics of a library. My thought is if you unde

Re: My new programming book ...

2022-11-08 Thread Adam D Ruppe via Digitalmars-d-learn
On Monday, 7 November 2022 at 06:10:46 UTC, zjh wrote: How is your `minigui`? Please write an `introduction` when you have time. It is on my list but minigui is a pretty simple class collection of basic widgets. It works pretty well now. I don't have too many intro examples yet though. My blo

Re: Using glibc headers with ImportC

2022-11-12 Thread Adam D Ruppe via Digitalmars-d-learn
On Saturday, 12 November 2022 at 13:46:27 UTC, qua wrote: This is supposed to work, right? No, it isn't. And it probably never will. importC looks for a .c file in the current directory. It is that .c file's responsibility to #include whatever .h files you want.

Re: Using glibc headers with ImportC

2022-11-12 Thread Adam D Ruppe via Digitalmars-d-learn
On Saturday, 12 November 2022 at 14:39:14 UTC, qua wrote: Do I have to do anything else? I've read that importc doesn't have a preprocessor and I assume it is related to that, however "ImportC can automatically run the C preprocessor associated with the Associated C Compiler". I still don't t

  1   2   3   4   5   6   7   8   9   10   >