Re: member func is best choice for pointers?

2023-04-06 Thread Salih Dincer via Digitalmars-d-learn
On Thursday, 6 April 2023 at 14:26:01 UTC, a11e99z wrote: member func has invariant that **this** is not null (programmer thinks so). global func hasn't the one and programmer should check for it before doing something ... I understand what you mean. When you try to access the last node of a

Re: Prevent console line advancing on user input

2023-04-06 Thread anonymouse via Digitalmars-d-learn
On Thursday, 6 April 2023 at 14:51:43 UTC, Steven Schveighoffer wrote: On 4/6/23 4:01 AM, anonymouse wrote: Wondering if this is possible? [snip] You need to use a terminal-control library, such as `arsd.terminal` https://github.com/adamdruppe/arsd/blob/master/terminal.d -Steve That works

Re: constant pointer failing to compile

2023-04-06 Thread Jacob Shtokolov via Digitalmars-d-learn
On Thursday, 6 April 2023 at 20:23:29 UTC, Jacob Shtokolov wrote: On Thursday, 6 April 2023 at 00:46:26 UTC, Josh Holtrop wrote: I am trying to port a small C project to D and am getting a Ah, just noticed that other people have already responded! Sorry about that! BTW, your `&data[0]` C-like

Re: constant pointer failing to compile

2023-04-06 Thread Jacob Shtokolov via Digitalmars-d-learn
On Thursday, 6 April 2023 at 00:46:26 UTC, Josh Holtrop wrote: I am trying to port a small C project to D and am getting a compilation error I don't understand. It seems like the compiler is just missing some type hints. Try this: ```d import std.stdio; __gshared immutable ubyte[4] data = [

Re: constant pointer failing to compile

2023-04-06 Thread Salih Dincer via Digitalmars-d-learn
On Thursday, 6 April 2023 at 00:46:26 UTC, Josh Holtrop wrote: ``` constarrptr.d(5): Error: cannot use non-constant CTFE pointer in an initializer `cast(immutable(ubyte)*)data` ``` Why? And how can I do the equivalent to what I have been doing in C? I want these pointers to be generated at co

Re: regex matching but not capturing

2023-04-06 Thread Ali Çehreli via Digitalmars-d-learn
On 4/6/23 11:08, Paul wrote: ways to access those repetitive ", cc" s on the end.  I don't think my regex is capturing them. Some internets think you are in parser territory: https://stackoverflow.com/questions/1407435/how-do-i-regex-match-with-grouping-with-unknown-number-of-groups Ali

Re: regex matching but not capturing

2023-04-06 Thread Paul via Digitalmars-d-learn
On Thursday, 6 April 2023 at 16:27:23 UTC, Alex Bryan wrote: My understanding browsing the documentation is the matchAll returns a range of Captures (struct documented at https://dlang.org/phobos/std_regex.html#Captures). In your for loop I think c[0] will contain the current full match (curre

Re: regex matching but not capturing

2023-04-06 Thread Alex Bryan via Digitalmars-d-learn
On Thursday, 6 April 2023 at 15:52:16 UTC, Paul wrote: My regex is matching but doesnt seem to be capturing. You may recognize this from the AOC challenges. file contains... **Valve AA has flow rate=0; tunnels lead to valves DD, II, BB** **Valve BB has flow rate=13; tunnels lead to valves CC,

regex matching but not capturing

2023-04-06 Thread Paul via Digitalmars-d-learn
My regex is matching but doesnt seem to be capturing. You may recognize this from the AOC challenges. file contains... **Valve AA has flow rate=0; tunnels lead to valves DD, II, BB** **Valve BB has flow rate=13; tunnels lead to valves CC, AA** **Valve CC has flow rate=2; tunnels lead to valves

Re: Prevent console line advancing on user input

2023-04-06 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/6/23 4:01 AM, anonymouse wrote: Wondering if this is possible? Ask a user at input and wait for response: write("Is the sky blue? "); readf!" %s\n"(response); If the user's response is correct, I'd like to change the color of provided response to indicate it was correct then advance to th

Re: foreach (i; taskPool.parallel(0..2_000_000)

2023-04-06 Thread Paul via Digitalmars-d-learn
On Thursday, 6 April 2023 at 01:44:15 UTC, H. S. Teoh wrote: D ranges are conceptually sequential, but the actual underlying memory access patterns depends on the concrete type at runtime. An array's elements are stored sequentially in memory, and arrays are ranges. But a linked-list can al

member func is best choice for pointers?

2023-04-06 Thread a11e99z via Digitalmars-d-learn
```d import std, core.lifetime; struct Node { Node* pNext; void func() { "Node::func %s".writeln( pNext); } } void func( Node* p ) { "::func %s(%s)".writeln( p, p == null ? p : p.next); } void main() { Node n; auto pn = &n; //cast( Node* )0; pn.func(); // prints: Node::func

Re: constant pointer failing to compile

2023-04-06 Thread Josh Holtrop via Digitalmars-d-learn
On Thursday, 6 April 2023 at 00:59:12 UTC, Mathias LANG wrote: immutable ubyte[4] data = [1, 2, 3, 4]; Using a static array instead of a slice will do the trick. You can leave the `__gshared` if you want, but it is redundant on a global, initialized `immutable` variable. Yes, thank you, usi

Re: short guide on getting started with D

2023-04-06 Thread cgenie via Digitalmars-d-learn
On Wednesday, 5 April 2023 at 05:52:33 UTC, thinkunix wrote: Thank you for these remarks! My observations: #1 typo: After that, add this meso.build file: "meso.build" should be "meson.build" Fixed. #2 Does it matter where the dlang = import... block goes in the meson.build file? I add

Prevent console line advancing on user input

2023-04-06 Thread anonymouse via Digitalmars-d-learn
Wondering if this is possible? Ask a user at input and wait for response: write("Is the sky blue? "); readf!" %s\n"(response); If the user's response is correct, I'd like to change the color of provided response to indicate it was correct then advance to the next line and ask a different ques