Re: what exactly is string length?

2021-04-01 Thread Computermatronic via Digitalmars-d-learn

On Friday, 2 April 2021 at 05:02:52 UTC, mw wrote:
Ahh, I got what I see (from writeln) is not what get string 
here ;-)


And I just tried:

string t = text("head-", strip(s), "-tail");

It's the same behavior.

So how can I trim the leading & trailing `\0` from the static 
char array?


strip only removes whitespace, not null characters. You'd have to 
do something like
```d string t = cast(string)text("head-", s, "-tail").filter!`a 
!= '\0'`().array;```
I would assume there would be a better way, but I haven't been 
able to find a dedicated function for stripping null chars in std.


Re: what exactly is string length?

2021-04-01 Thread Computermatronic via Digitalmars-d-learn

On Friday, 2 April 2021 at 04:49:22 UTC, mw wrote:

So you mean inside the writeln() call, the 0s are skipped?

Well, if I use `string t` as filename, it will try to looking 
for a file called:


"head-abc\0\0\0-tail" instead of just "head-abc-tail" ?

or it's platform dependent?


I would imagine that it's platform dependant, but given most 
platforms adhere to the C ABI, and C string are null terminated, 
you'd end up looking for a file called "head-abc".


Re: using tuple as value type for associative array

2018-06-20 Thread Computermatronic via Digitalmars-d-learn

On Thursday, 21 June 2018 at 02:44:12 UTC, Flaze07 wrote:

when I do
Tuple!(uint, "first", uint, "second")[string] what; //I tried 
aliasing the tuple as well

what["something"].first = 20;
I get range error
but when I do
uint[string] what2;
what2 = 20;
I get none of those range error, so...how do I use tuple as 
value type for associative array ?


what["something"].first = 20 will attempt to get an element of 
what, then assign a member, while what2["something"] = 20 will 
add an element to what2 with the value of 20. Since 
what["something"] is not present, it will throw a range error.


Try what["something"] = tuple(20, 0); instead.



How to task pool in vibe.d?

2018-06-09 Thread Computermatronic via Digitalmars-d-learn
I'd like to create a bunch of tasks in vibe.d, then wait for them 
all to complete.


Using std.concurrency and std.parallelism this is trivial.

I could just spawn a bunch of vibe.d tasks and then iteratively 
join them, but I would think vibe.d would provide some primitives 
for task-pooling.


Re: Confusion/trying to understand CTFE keywords

2018-06-03 Thread Computermatronic via Digitalmars-d-learn

On Sunday, 3 June 2018 at 21:32:06 UTC, gdelazzari wrote:
I'm trying to understand why
keywords such as "static" or "enum" are used to denote compile 
time "things". What I mean is that those keywords are also used 
for other purposes, so I find it a bit confusing. Couldn't a 
keyword like "ctfe" (just making it up right now) exist?


I believe the enum was chosen over a dedicated keyword for 
compile-time constants to prevent adding another keyword, as D 
already has quite a few.