Re: Adapting foreign iterators to D ranges

2024-04-22 Thread Steven Schveighoffer via Digitalmars-d-learn
On Monday, 22 April 2024 at 11:36:43 UTC, Chloé wrote: The first implementation has the advantage is being simpler and empty being const, but has the downside that next is called even if the range ends up not being used. Is either approach used consistently across the D ecosystem? I always

Re: Statically compiled binary with C interop crashes.

2024-04-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On Thursday, 18 April 2024 at 11:05:07 UTC, yabobay wrote: On Wednesday, 17 April 2024 at 15:24:07 UTC, Ferhat Kurtulmuş wrote: On Wednesday, 17 April 2024 at 11:03:22 UTC, yabobay wrote: I'm using [dray](https://code.dlang.org/packages/dray) in my project with dub, here's the relevant parts

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On Sunday, 14 April 2024 at 22:36:18 UTC, Liam McGillivray wrote: On Friday, 12 April 2024 at 15:24:38 UTC, Steven Schveighoffer wrote: ```d void InitWindow(int width, int height, ref string title) { InitWindow(width, height, cast(const(char)*)title); } ``` This is invalid, a string may

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On Friday, 12 April 2024 at 00:04:48 UTC, Liam McGillivray wrote: Here's what I wanted to do. In the library I'm working on, there are various declarations for functions defined in an external C library following the line `extern (C) @nogc nothrow:`. Here are some examples of such

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

2024-04-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On Friday, 12 April 2024 at 03:57:40 UTC, John Dougan wrote: What is the procedure for bug reporting? I'm looking at the issues tracker and have no clue how to drive the search to see if this is already there. https://issues.dlang.org While entering the bug title, it does a fuzzy search

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

2024-04-11 Thread Steven Schveighoffer via Digitalmars-d-learn
On Thursday, 11 April 2024 at 03:17:36 UTC, John Dougan wrote: Interesting. Thank you to both of you. On Wednesday, 10 April 2024 at 17:38:21 UTC, Steven Schveighoffer wrote: On Wednesday, 10 April 2024 at 11:34:06 UTC, Richard (Rikki) Andrew Cattermole wrote: Place your attributes on the

Re: mmap file performance

2024-04-11 Thread Steven Schveighoffer via Digitalmars-d-learn
On Thursday, 11 April 2024 at 00:24:44 UTC, Andy Valencia wrote: I wrote a "count newlines" based on mapped files. It used about twice the CPU of the version which just read 1 meg at a time. I thought something was amiss (needless slice indirection or something), so I wrote the code in C.

Re: "Error: `TypeInfo` cannot be used with -betterC" on a CTFE function

2024-04-10 Thread Steven Schveighoffer via Digitalmars-d-learn
On Tuesday, 9 April 2024 at 23:50:36 UTC, Richard (Rikki) Andrew Cattermole wrote: On 10/04/2024 11:21 AM, Liam McGillivray wrote: On Sunday, 7 April 2024 at 08:59:55 UTC, Richard (Rikki) Andrew Cattermole wrote: Unfortunately runtime and CTFE are the same target in the compiler. So that

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

2024-04-10 Thread Steven Schveighoffer via Digitalmars-d-learn
On Wednesday, 10 April 2024 at 11:34:06 UTC, Richard (Rikki) Andrew Cattermole wrote: Place your attributes on the right hand side of the function, not the left side. Use the left side for attributes/type qualifiers that go on the return type. Just a word of warning, this explanation

Re: Boneheaded question regarding compilation...

2024-04-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On Monday, 1 April 2024 at 21:23:50 UTC, WhatMeWorry wrote: Huge fan of Mike Shah's YouTube videos regarding D and his latest for D conference: https://mshah.io/conf/24/DConf%20%20Online%202024%20_%20The%20Case%20for%20Graphics%20Programming%20in%20Dlang.pdf So I installed github desktop

Re: Limits of implicit conversion of class arrays

2024-03-27 Thread Steven Schveighoffer via Digitalmars-d-learn
On Monday, 25 March 2024 at 07:16:35 UTC, Per Nordlöw wrote: On Saturday, 23 March 2024 at 11:04:04 UTC, Dmitry Olshansky wrote: The first and second is unsound (infamously allowed in Java). In the general case, yes. But, do you see any errors with the code ```d class Base {} class Derived

Re: Unittests pass, and then an invalid memory operation happens after?

2024-03-27 Thread Steven Schveighoffer via Digitalmars-d-learn
On Wednesday, 27 March 2024 at 21:43:48 UTC, Liam McGillivray wrote: In my current [game project](https://github.com/LiamM32/Open_Emblem), [something strange](https://github.com/LiamM32/Open_Emblem/issues/20) has happened as of a recent commit. When running `dub test`, all the unittests

Re: Reworking the control flow for my tactical role-playing game

2024-03-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On Sunday, 17 March 2024 at 00:14:55 UTC, Liam McGillivray wrote: As many of you know, I have been trying to write a tactical role-playing game (a mix of turn-based stategy & RPG) in D. This is the furthest I have ever gotten in making an interactive program from the main function up. Right

Re: Disable wrilten buf in docker

2024-03-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On Tuesday, 12 March 2024 at 06:36:09 UTC, zoujiaqing wrote: Hi, my application use writeln in docker don't display. Python add -u disable it. https://stackoverflow.com/questions/29663459/why-doesnt-python-app-print-anything-when-run-in-a-detached-docker-container Use setvbuf to switch to

Re: New update fix

2024-03-03 Thread Steven Schveighoffer via Digitalmars-d-learn
On Saturday, 2 March 2024 at 09:18:58 UTC, user1234 wrote: On Saturday, 2 March 2024 at 08:41:40 UTC, Salih Dincer wrote: SLM, What exactly did this patch with the new update fix? Nothing, it looks like what happened is that the issue was wrongly referenced by a dlang.org PR

Re: Error when using `import`.

2024-02-26 Thread Steven Schveighoffer via Digitalmars-d-learn
On Monday, 26 February 2024 at 23:27:49 UTC, Liam McGillivray wrote: I don't know whether I should continue this topic or start a new one now that the problem mentioned in the title is fixed. I have now uploaded some of the code to [a GitHub repository](https://github.com/LiamM32/Open_Emblem).

Re: Error when using `import`.

2024-02-26 Thread Steven Schveighoffer via Digitalmars-d-learn
On Monday, 26 February 2024 at 22:40:49 UTC, Liam McGillivray wrote: On Sunday, 25 February 2024 at 03:23:03 UTC, Paul Backus wrote: You can't give a class the same name as the file it's in. If you do, then when you try to use it from another file, the compiler will get confused and think

Re: The difference between the dates in years

2024-02-10 Thread Steven Schveighoffer via Digitalmars-d-learn
On Saturday, 10 February 2024 at 15:53:09 UTC, Alexander Zhirov wrote: Is it possible to calculate the difference between dates in years using regular means? Something like that ``` writeln(Date(1999, 3, 1).diffMonths(Date(1999, 1, 1))); ``` At the same time, keep in mind that the month and

Re: The difference between the dates in years

2024-02-10 Thread Steven Schveighoffer via Digitalmars-d-learn
On Saturday, 10 February 2024 at 23:48:56 UTC, Jonathan M Davis wrote: If I understand correctly, he cares about how far into the month the dates are, whereas diffMonths ignores the smaller units, meaning that you get the same result no matter when in the month the dates are. So, 2000-05-10

Re: The difference between the dates in years

2024-02-10 Thread Steven Schveighoffer via Digitalmars-d-learn
On Saturday, 10 February 2024 at 15:53:09 UTC, Alexander Zhirov wrote: Is it possible to calculate the difference between dates in years using regular means? Something like that ``` writeln(Date(1999, 3, 1).diffMonths(Date(1999, 1, 1))); ``` At the same time, keep in mind that the month and

Re: How to get the client's MAC address in Vibe

2024-02-08 Thread Steven Schveighoffer via Digitalmars-d-learn
On Wednesday, 7 February 2024 at 22:16:54 UTC, Alexander Zhirov wrote: Is there a way to identify a client by MAC address when using the Vibe library? The `NetworkAddress` [structure](https://vibed.org/api/vibe.core.net/NetworkAddress) does not provide such features. Or did I miss something?

Re: Scripting with Variant from std.variant: parameter passing

2024-02-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On Friday, 2 February 2024 at 08:22:42 UTC, Carl Sturtivant wrote: It seems I cannot pass e.g. an int argument to a Variant function parameter. What's the simplest way to work around this restriction? You'd have to implement the function that accepts the parameters and wraps in a Variant.

Re: import locality with function parameters

2024-02-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On Friday, 2 February 2024 at 00:29:51 UTC, Carl Sturtivant wrote: Hello, I seem to recall that there is surprising template to import a module and get a type from it inside the declaration of the type of a parameter to a function, so that the module need not be imported outside of the

Re: Effective String to Date conversion?

2024-01-31 Thread Steven Schveighoffer via Digitalmars-d-learn
On Monday, 22 January 2024 at 10:56:04 UTC, atzensepp wrote: Dear D-gurus, being new to D I am trying my first steps and the language is quite intuitive and appealing. When reading a file and creating a hash for the reocrds I want to get only the most recent ones. For this I need to convert

Re: Safety is not what you think

2024-01-30 Thread Steven Schveighoffer via Digitalmars-d-learn
On Tuesday, 30 January 2024 at 15:38:26 UTC, Paul Backus wrote: This definitely isn't allowed in C or C++. I wonder what the rationale is for having this behavior in D? It isn't allowed in C, but allowed in C++ https://godbolt.org/z/9xTPhsb5G As for rationale... I don't know why it wouldn't

Re: Accessing array elements with a pointer-to-array

2024-01-27 Thread Steven Schveighoffer via Digitalmars-d-learn
On Friday, 26 January 2024 at 11:38:39 UTC, Stephen Tashiro wrote: On Thursday, 25 January 2024 at 20:36:49 UTC, Kagamin wrote: On Thursday, 25 January 2024 at 20:11:05 UTC, Stephen Tashiro wrote: void main() { ulong [3][2] static_array = [ [0,1,2],[3,4,5] ];

Re: Providing implicit conversion of

2024-01-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On Sunday, 21 January 2024 at 16:05:40 UTC, Gavin Gray wrote: The following code: ulong charlie = 11; long johnstone = std.algorithm.comparison.max(0, -charlie); writeln(format!"johnstone %s"(johnstone)); Results in (without any warning(s)): johnstone -11 However you choose to look at

Re: Delegates and values captured inside loops

2024-01-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On Sunday, 21 January 2024 at 14:52:45 UTC, Renato wrote: On Saturday, 20 January 2024 at 16:53:12 UTC, ryuukk_ wrote: This is the workaround according to: https://issues.dlang.org/show_bug.cgi?id=21929#c9 Go used to have the same issue [but they fixed

Re: vector crash

2024-01-17 Thread Steven Schveighoffer via Digitalmars-d-learn
On Thursday, 18 January 2024 at 03:07:13 UTC, zjh wrote: ```d import dparse.ast; import dparse.lexer; import dparse.parser : parseModule; import dparse.rollback_allocator : RollbackAllocator; import core.stdcpp.vector; import core.stdcpp.string; ... ``` I have no experience with using cpp from

Re: `static` function ... cannot access variable in frame of ...

2024-01-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On Monday, 15 January 2024 at 22:23:27 UTC, Bastiaan Veelo wrote: On Monday, 15 January 2024 at 18:43:43 UTC, user1234 wrote: The two calls are not equivalent. so what is passed as alias need to be static too. Thanks all. I thought a static member function just isn't able to access the

Re: Socket handle leak and active handle warning with Vibe-D

2024-01-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On Monday, 15 January 2024 at 18:40:00 UTC, bomat wrote: Sorry, I probably should have mentioned I was on Windows. For testing it under Linux I commented out the call to `connectMongoDB`, since I don't have it installed there - and the warning went away. Interesting, I did not suspect that as

Re: Socket handle leak and active handle warning with Vibe-D

2024-01-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On Monday, 15 January 2024 at 17:24:40 UTC, bomat wrote: On Sunday, 14 January 2024 at 20:36:44 UTC, Steven Schveighoffer wrote: There should be a version you can enable that tells you where that socket handle was allocated. That might give you a further clue as to why it's not closed when the

Re: Socket handle leak and active handle warning with Vibe-D

2024-01-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On Saturday, 13 January 2024 at 20:49:54 UTC, bomat wrote: I am still getting this in 2024 and vibe.d 0.9.7: ``` Warning: 1 socket handles leaked at driver shutdown. ``` I was wondering if maybe someone has new info on this... There should be a version you can enable that tells you where

Re: Non-blocking keyboard input

2024-01-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On Sunday, 14 January 2024 at 13:41:26 UTC, Joe wrote: This does not actually work on my computer. It still blocks. Adam is no longer using mainstream D, and apparently not posting on this forum. I suggest you try to contact him via the arsd github page: https://github.com/adamdruppe/arsd

Re: Synchronisation help

2024-01-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On Monday, 1 January 2024 at 15:48:16 UTC, Anonymouse wrote: What is the common solution here? Do I add a module-level `Object thing` and move everything accessing the AA into `synchronized(.thing)` statements? Or maybe add a `shared static` something to `Foo` and synchronise with

Re: jsoniopipe - exaples?

2023-12-29 Thread Steven Schveighoffer via Digitalmars-d-learn
On Friday, 29 December 2023 at 08:09:58 UTC, Zz wrote: Hi, Here are some samples from the std.json documentation. Any idea on how to do something similar using jsoniopipe? Directly copied from https://dlang.org/phobos/std_json.html import std.conv : to; // parse a file or string of json into

Re: How to get serve-d to find dub dependencies

2023-12-24 Thread Steven Schveighoffer via Digitalmars-d-learn
On Saturday, 23 December 2023 at 16:28:28 UTC, Renato wrote: On Saturday, 23 December 2023 at 16:13:01 UTC, Renato wrote: I am trying to use dependencies, so I need dub. On emacs, the imports from dub libraries cannot be found, even though dub can build it fine. How can I get emacs/serve-d

Re: Operator "+=" overloading for class?

2023-12-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On Monday, 18 December 2023 at 14:38:14 UTC, Ki Rill wrote: your code just return result value, but it should not return but save result to "this" see example at https://dlang.org/spec/operatoroverloading.html#index_op_assignment I get an error, but don't understand why. ```d auto

Re: Manually relesing memory

2023-12-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On Saturday, 9 December 2023 at 10:12:11 UTC, Vlad Stanimir wrote: I am new to the language and am curios about manual memory management options. From what i can tell dlang offers the option for both manul and automatic management of memory resources. You might find all the answers in

Re: now I need -allinst when dmd compiles the unittest

2023-12-04 Thread Steven Schveighoffer via Digitalmars-d-learn
On Friday, 1 December 2023 at 22:00:52 UTC, kdevel wrote: If I not use -allinst the linker complains when using the current msgpack-d v1.0.5, e.g. [...]msgpack-d/src/msgpack/package.d:203: undefined reference to `pure nothrow @nogc @safe immutable(char)[]

Re: Advent of Code 2023

2023-12-03 Thread Steven Schveighoffer via Digitalmars-d-learn
On Sunday, 3 December 2023 at 18:56:32 UTC, Johannes Miesenhardt wrote: On Sunday, 3 December 2023 at 14:51:37 UTC, Siarhei Siamashka wrote: [...] Thanks, this is super helpful. I have one other question, in the solution you posted and also the one I posted in the discord today. I was

Re: msghdr and cmsghdr mismatch for alpine musl

2023-11-26 Thread Steven Schveighoffer via Digitalmars-d-learn
On Saturday, 25 November 2023 at 05:04:57 UTC, d007 wrote: `import core.sys.posix.sys.socket : msghdr, cmsghdr, iovec;` `msg_iovlen`, `msg_controllen`, `cmsg_len` is ulong for x86-64 in druntime. in alpine musl, they are int, socklen_t(uint), socklen_t(uint). Is this mismatch can

Re: Dirty DMD

2023-11-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On Saturday, 18 November 2023 at 18:52:07 UTC, JN wrote: Latest DMD for Windows downloaded from here: https://downloads.dlang.org/releases/2.x/2.105.3/dmd-2.105.3.exe reports version as dirty: DMD64 D Compiler v2.105.3-dirty Copyright (C) 1999-2023 by The D Language Foundation, All Rights

Re: D: How to check if a function is chained? a().b().c();

2023-11-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On Saturday, 18 November 2023 at 07:47:19 UTC, BoQsc wrote: Let's say we have a chain of functions. ``` a().b().c(); ``` I would like to have a behaviour in `a()` that would check if there is `b()` or `c()` chained to it. If `a();`is not chained: do a `writeln("You forgot to chain this

Re: Struct copy constructor with inout

2023-11-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On Tuesday, 14 November 2023 at 13:58:17 UTC, Paul Backus wrote: It's easier to see if you compare the actual and expected argument lists side-by-side Expected: (ref const(S1) s) const Actual: (const(S1) ) ^ Mismatched

Re: Struct copy constructor with inout

2023-11-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On Tuesday, 14 November 2023 at 08:50:34 UTC, dhs wrote: I am using following code: ```d struct S1 { this(ref const S1 s) const { writeln("copy"); } int i; } struct S2 { this(ref inout S2 s) inout { writeln("copy"); } int i; } void test() { const(S1) s1; S1 ss1 = s1;

Re: Dlang installer with VSCode broken

2023-11-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On Sunday, 5 November 2023 at 22:28:29 UTC, Daniel Donnelly, Jr. wrote: This is on my friend's machine, who I am teaching D. What can be done? Can you describe what you did? Also, might be helpful to file an issue on the code-d github repository itself: https://github.com/Pure-D/code-d

Re: Convert String to Date and Add ±N Hours

2023-11-04 Thread Steven Schveighoffer via Digitalmars-d-learn
On Saturday, 4 November 2023 at 18:11:53 UTC, Vahid wrote: Hi, I have a date string with the format of "2023-11-04 23:10:20". I want to convert this string to Date object and also, add ±N hours to it. For example: `"2023-11-04 23:10:20" + "+2:00" = "2023-11-05 01:10:20"` `"2023-11-04

Re: why remove octal literal support?

2023-11-03 Thread Steven Schveighoffer via Digitalmars-d-learn
On Friday, 3 November 2023 at 15:07:41 UTC, d007 wrote: dlang is know for compile speed, but in reality d project compile slow because so much ctfe and tempalte. Why bring more ctfe call by remmove octal literal ? octal literals are extremely error prone, because people sometimes use

Re: What are the best available D (not C) File input/output options?

2023-11-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On Thursday, 2 November 2023 at 15:46:23 UTC, confuzzled wrote: I tried std.io but write() only outputs ubyte[] while I'm trying to output text so I abandoned idea early. Just specifically to answer this, this is so you understand this is what is going into the file -- bytes. You should

Re: is the array literal in a loop stack or heap allocated?

2023-10-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/10/23 10:54 PM, mw wrote: Hi, I want to confirm: in the following loop, is the array literal `a` vs. `b` stack or heap allocated? and how many times? ask the compiler: ```d void main() @nogc { int[2] a; int[] b; int i; while(++i <=100) { a = [i, i+1]; // array literal //b =

Re: T[] opIndex() Error: .. signal 11

2023-10-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/5/23 1:49 AM, ag0aep6g wrote: For some further reading, there's an open issue about the unexpected slicing: https://issues.dlang.org/show_bug.cgi?id=14619 Thank you I had forgotten about that issue! -Steve

Re: T[] opIndex() Error: .. signal 11

2023-10-03 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/3/23 11:12 AM, Joel wrote: The following program crashes, but doesn’t if I change (see title) T[] to auto. The program doesn’t even use that method/function. What’s the story? It's a stack overflow. when doing foreach on your type, the compiler *always* uses a slice first if it

Re: The difference between T[] opIndex() and T[] opSlice()

2023-10-03 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/3/23 12:09 PM, Paul Backus wrote: On Tuesday, 3 October 2023 at 13:07:00 UTC, Steven Schveighoffer wrote: Now, you can define a further `opIndexAssign(T val, size_t idx)`. However, now you lose capabilities like `a[0]++`, which I don't think has a possibility of implementing using an

Re: The difference between T[] opIndex() and T[] opSlice()

2023-10-03 Thread Steven Schveighoffer via Digitalmars-d-learn
On Monday, 2 October 2023 at 20:42:14 UTC, Paul Backus wrote: On Monday, 2 October 2023 at 20:34:11 UTC, Salih Dincer wrote: In an old version (for example, v2.0.83), the code you implemented in the places where Slice is written above works as desired. In the most current versions, the

Re: The difference between T[] opIndex() and T[] opSlice()

2023-10-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/1/23 1:41 PM, Salih Dincer wrote: Hi, What is the difference between T[] opIndex() and T[] opSlice(), which haven't parameters? None. It used to be that opSlice was the only way, and the mechanisms opSlice uses are still valid. -Steve

Re: Straight Forward Arrays

2023-10-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/1/23 1:13 PM, dhs wrote: It may not be a problem in practice. My concern was performance, because each time we add an element to the array, the garbage collector has to map the slice to the allocation it belongs to. FWIW, there is a cache that makes this decently fast, so it doesn't

Re: Straight Forward Arrays

2023-10-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/1/23 10:34 AM, Steven Schveighoffer wrote: The complexity is from the way d does operator overloading and indexing. It should be pretty straightforward. I’ll see if I can post a simple wrapper. I didn't tackle any attribute or memory safety issues, or many operator overloads, but

Re: Straight Forward Arrays

2023-10-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On Sunday, 1 October 2023 at 13:24:27 UTC, dhs wrote: On Sunday, 1 October 2023 at 13:05:12 UTC, Steven Schveighoffer wrote: On Sunday, 1 October 2023 at 09:01:53 UTC, dhs wrote: [...] Std::vector uses value semantics. D does not have anything like that. It could be done someone just has to

Re: Straight Forward Arrays

2023-10-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On Sunday, 1 October 2023 at 09:01:53 UTC, dhs wrote: Hi, Is there a straight forward Array type in D similar to C++'s vector class? Something along the lines of the tuple: (pointer to elements, length, capacity). [...] Std::vector uses value semantics. D does not have anything like

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

2023-09-25 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/23/23 8:07 AM, 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. You might misunderstand how vibe is

Re: range shortened method not enabled, compile with compiler switch `-preview=shortenedMethods`

2023-09-24 Thread Steven Schveighoffer via Digitalmars-d-learn
On Sunday, 24 September 2023 at 10:00:31 UTC, Joe wrote: For absolutely no reason I started getting this error. Last night I compiled the project and it worked just fine. This morning I made a single insignificant change and tried to compile and got that error. Only possible thing is that for

Re: "readln" after "readf"

2023-09-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On Thursday, 21 September 2023 at 09:14:14 UTC, pascal111 wrote: I've a problem when I'm using "readln" after "readf" that I couldn't see my program rest and the lines of the execution ran fast: module main; import std.stdio; import std.string; import std.conv; int main(string[] args) {

Re: How to use core.vararg to print D variadic arguments and their types without using ! (template instantiation)?

2023-09-16 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/15/23 4:14 PM, Basile B. wrote: On Thursday, 14 September 2023 at 15:19:29 UTC, BoQsc wrote: https://dlang.org/phobos/core_vararg.html The common way to use **va_arg** is `va_arg!(int)(_argptr);` What would be the alternative way or syntax that behave exactly the same way, even if more

Re: Setting struct as default parameter of a function using struct literal?

2023-09-11 Thread Steven Schveighoffer via Digitalmars-d-learn
On Monday, 11 September 2023 at 19:59:37 UTC, ryuukk_ wrote: I would love to be able to use C style designated initialization everywhere too.. Recent version of D added named arguments so you can do something like: ```D void someFunction(Options option = Options(silenceErrors: false))

Re: malloc error when trying to assign the returned pointer to a struct field

2023-09-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On Saturday, 9 September 2023 at 09:21:32 UTC, rempas wrote: Now, if only one could expect how and why "libc" knows that and doesn't just care to give me the memory I asked it for? Or it could be than D does something additional without telling us? Which can explain when this memory is only

Re: malloc error when trying to assign the returned pointer to a struct field

2023-09-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On Friday, 8 September 2023 at 07:59:37 UTC, rempas wrote: I do have the following struct: ... That's some minimal code that I do have just to showcase it. This is not ideal. Why? Because 99% of the time, a poster has come here with a problem they don't know how to solve, and have focused

Re: AA vs __gshared

2023-08-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/12/23 5:55 AM, IchorDev wrote: On Thursday, 10 August 2023 at 15:20:28 UTC, Steven Schveighoffer wrote: That shouldn't matter. Well, it does here. The AA is mutated during the loop, so perhaps this is an optimisation quirk where it works with `for` but segfaults in `foreach`? I've

Re: sort with char’s

2023-08-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On Saturday, 12 August 2023 at 06:47:50 UTC, Joel wrote: writeln(name[].each!(n => n.write)); // get "christensenyes" //, " <> ", name[].sort!"a>b".each!(n => n.write)); This writes each character individually, and then at the end writes the result of `each` with a newline. In this

Re: Why is GC.collect not @safe?

2023-08-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/2/23 7:40 AM, Nick Treleaven wrote: Presumably an allocation like `new T` (for a type with a @safe constructor) can be made anywhere a call to `GC.collect` can be made, which may trigger a collection. So why isn't `GC.collect` marked @safe? It should be. Maybe historical reasons? One

Re: HTTP Post Body Parameters

2023-08-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/1/23 7:57 PM, Vahid wrote: Hi, I want to submit a request to server with "x-www-form-urlencoded" header. This is the simplified version of my code:     auto http = HTTP("https://myurl.com/api;);     http.addRequestHeader("Content-Type", "application/x-www-form-urlencoded");    

Re: Anyone help me with a stack dump?

2023-07-31 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/31/23 9:09 AM, Cecil Ward wrote: The unitttests that I have just put in crash spectacularly with an access violation. I built the code with LDC for Aarch64 / OSX and I fired up lldb. I now have to learn lldb quick. (BTW Where can I get an x86 / linux build of lldb or similar ?) This is

Re: AA vs __gshared

2023-07-28 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/28/23 11:15 AM, IchorDev wrote: On Friday, 28 July 2023 at 11:15:31 UTC, Steven Schveighoffer wrote: All `__gshared` does is give you storage that is accessible from all threads, "All __gshared does is give you [a live bomb, ready to go off at any moment]" !! It seems like it's not

Re: Syntax for Static Import of User Define Attributes

2023-07-28 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/28/23 8:10 AM, Vijay Nayar wrote: However, this makes me wonder. Is there any reason why the `@` shouldn't recognize the dots in a fully-qualified-name on its own, without the need for parentheses? It might be possible to expand the grammar. It seems very specific to UDAs, as it doesn't

Re: Syntax for Static Import of User Define Attributes

2023-07-28 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/28/23 4:15 AM, Vijay Nayar wrote: On Thursday, 27 July 2023 at 21:24:44 UTC, Dennis wrote: On Thursday, 27 July 2023 at 21:19:08 UTC, Vijay Nayar wrote: Attempted Fix 2: Enclose the entire attribute name in parenthesis. ``` static import vibe.data.serialization; class

Re: Designated initializers to function argument

2023-07-28 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/28/23 3:35 AM, IchorDev wrote: On Tuesday, 11 July 2023 at 17:43:43 UTC, Steven Schveighoffer wrote: On 7/11/23 11:22 AM, Ki Rill wrote: On Tuesday, 11 July 2023 at 15:16:54 UTC, Ki Rill wrote: apply(Appearance(color: BLACK, strokeWidth: 4)); // other fields are default initialized:

Re: AA vs __gshared

2023-07-28 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/28/23 4:39 AM, IchorDev wrote: Issue is, this code I posted actually runs just fine, unlike the real code. My actual code does this HIGHLY SUSPICIOUS thing when printing their length each time before using them: ``` 766 766 765 766 767 768 768 768 768 768 768 768 768 768 768 768 768 768

Re: Which D compiler is the most maintained and future-proof? [DMD GDC and LDC]

2023-07-24 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/24/23 9:30 AM, cc wrote: On Monday, 24 July 2023 at 09:29:09 UTC, Richard (Rikki) Andrew Cattermole wrote: There isn't a huge concern with which one you use. Its quite common to use dmd for development, and ldc for release for example. They all share the same frontend, so they really

Re: Garbage Collectors

2023-07-22 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/19/23 10:46 AM, Johan wrote: On Wednesday, 19 July 2023 at 11:27:14 UTC, Richard (Rikki) Andrew Cattermole wrote: [...] you would have to do a new build of druntime/phobos special which isn't the easiest thing to do. Side remark: LDC ships with the ldc-build-runtime tool which should

Re: Garbage Collectors

2023-07-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/19/23 3:24 AM, IchorDev wrote: So, D’s default garbage collector is the one named “conservative” in DRuntime… I see there’s also “manual” which doesn’t actually function as a GC, which is interesting. Nothing says what ProtoGC is… so I guess it’s useless. Has anyone ever published any

Re: Print debug data

2023-07-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/18/23 5:04 PM, Alain De Vos wrote: ? use `stats` instead of `Stats`. The `Stats` name is the type, whereas the `stats` method is the call that gets the stats. It's kind of a terrible message, I wish it would change to something more informative. -Steve

Re: How to free memory ater use of "new" to allocate it.

2023-07-17 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/16/23 11:58 PM, Alain De Vos wrote: Maybe code above works when you enforce an Garbage-collection-run ? Code below works fine. So you cannot use "new" but must use malloc? ``` import std.stdio:writefln; import object: destroy; import core.memory: GC; import core.stdc.stdlib: malloc,free;

Re: How to free memory ater use of "new" to allocate it.

2023-07-17 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/16/23 11:41 PM, Alain De Vos wrote: The following program prints two different addresses. Meaning the new allocates memory until the program dies. So the means memory leak by default ? ``` import std.stdio:writefln; import object: destroy; import core.memory: GC; void dofun(){     auto

Re: How to free memory ater use of "new" to allocate it.

2023-07-16 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/16/23 2:41 PM, Alain De Vos wrote: Is this ok ? ``` void main(){ int[] i=new int[1];     import object: destroy; destroy(i);     import core.memory: GC; GC.free(GC.addrOf(cast(void *)(i.ptr))); } ``` No, that won't work. Check out `i` value after you call `destroy` on

Re: Issue De-referencing a Pointer to a Struct in an Array

2023-07-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/14/23 1:23 PM, Pen Hall wrote: I think i figured out my issue... The issue was that 'board' is a pointer, and all of the ways I tried to de-reference it, failed. I just tried the form `(*board)[number][symbol][letter]` which worked to de-reference it.

Re: Giant template - changing types everywhere

2023-07-14 Thread Steven Schveighoffer via Digitalmars-d-learn
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 eponymous templates, you no longer get access to

Re: Giant template - changing types everywhere

2023-07-14 Thread Steven Schveighoffer via Digitalmars-d-learn
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 a giant template encompassing pretty much the

Re: Giant template - changing types everywhere

2023-07-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/13/23 8:08 PM, Cecil Ward wrote: What I really want to do though is provide one single templated function with the kind of characters / strings as a parameter. I want to have something like T Transform( T )( T str) called as auto result = Transform!(dstring)( dstring str ); ```d T[]

Re: Designated initializers to function argument

2023-07-11 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/11/23 11:22 AM, Ki Rill wrote: On Tuesday, 11 July 2023 at 15:16:54 UTC, Ki Rill wrote: ```D // or this apply(Appearance(color: BLACK, strokeWidth: 4)); // other fields are default initialized: strokeOpacity, fillOpacity, etc... ``` Ok, this works with DMD v2.103, but does not work

Re: Pre-expanding alloc cell(s) / reserving space for an associative array

2023-07-10 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/10/23 8:44 AM, H. S. Teoh wrote: On Mon, Jul 10, 2023 at 09:30:57AM +, IchorDev via Digitalmars-d-learn wrote: [...] From the spec it sounds as though (but good luck testing for sure) that if you have (for example) 6 big dummy key-value pairs in the AA to begin with, then if you use

Re: Pre-expanding alloc cell(s) / reserving space for an associative array

2023-07-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/9/23 4:24 PM, Cecil Ward wrote: Before I posted a question about avoiding unnecessary allocs/reallocs when adding entries to an array like so     uint[ dstring ]  arr; when I build it up from nothing with successive insertions. The array is accessed by a key that is a dstring. I was

Re: Linker error, doing something wrong?

2023-07-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/9/23 10:01 AM, Dmitry Olshansky wrote: Trying to compile the following: https://github.com/DmitryOlshansky/photon/blob/master/tests/curl_download.d with: ldc2 curl_download.d -L-lcurl get:   "__D6photon12__ModuleInfoZ", referenced from:   __D13curl_download12__ModuleInfoZ in

Re: Weird template instantiation speed?

2023-07-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/9/23 7:54 AM, IchorDev wrote: While working on some new bindings, I've discovered that if `opAssign` in a struct template "`BindingTempl(T)`" has the return type "`BindingTempl!T` then it adds about 4 seconds to the compile time per instantiation of `BindingTempl`. The added compile time

Re: `static` on module-level functions

2023-07-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/7/23 6:38 AM, IchorDev wrote: Well yes, I even mentioned that in the OP. It's just that I'd expect using `static` "incorrectly" to cause an error, like `const` does. Instead, marking something as `static` *actually* does nothing, and nothing really tells you, so it causes a bit of a

Re: Inserting into zero-length dynamic array

2023-07-04 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/4/23 3:19 PM, Cecil Ward wrote: I have a dynamic array of strings of length zero. When i write to the first element the program crashes, not surprisingly, but what should I be doing?  dstring[] arr;  arr[0] = "my string"d; // BANG !! It depends on the semantic requirement. If the

Re: Zapping a dynamic string

2023-07-04 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/4/23 1:01 PM, Cecil Ward wrote: I have a mutable dynamic array of dchar, grown by successively appending more and more. When I wish to zap it and hand the contents to the GC to be cleaned up, what should I do? What happens if I set the .length to zero? If you want to forget it so the GC

Re: applay for template function with sumtypes result?

2023-07-04 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/4/23 11:15 AM, kiriakov wrote: On Tuesday, 4 July 2023 at 14:42:31 UTC, Steven Schveighoffer wrote: On 7/4/23 10:19 AM, kiriakov wrote: On Tuesday, 4 July 2023 at 12:43:19 UTC, Steven Schveighoffer wrote: On 7/4/23 12:58 AM, kiriakov wrote: It looks like a type mismatch. The function

Re: applay for template function with sumtypes result?

2023-07-04 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/4/23 10:19 AM, kiriakov wrote: On Tuesday, 4 July 2023 at 12:43:19 UTC, Steven Schveighoffer wrote: On 7/4/23 12:58 AM, kiriakov wrote: It looks like a type mismatch. The function accepted should return `Result` but it's returning `ParsResult`. That's the problem Result(T) =

Re: applay for template function with sumtypes result?

2023-07-04 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/4/23 12:58 AM, kiriakov wrote: Hi. I can't handle template. It all looks sad, build ok, test error. ``` struct ParsResult(T) { T[] _in; T[] _out; } struct Err(T) { T[] x; } struct Result(T) {     SumType!(ParsResult!T, Err!T) data;     alias data this;     this(Value)(Value value) {

Re: Inheritance and arrays

2023-07-03 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/3/23 7:37 AM, Arafel wrote: That's very clearly an implementation detail leaking: the semantics of the language shouldn't depend on how interfaces and classes are implemented. It's a semantic detail -- casting an array does *not* make a copy, and an array is not a complex object. It's

  1   2   3   4   5   6   7   8   9   10   >