Re: Parallel For

2021-06-16 Thread jfondren via Digitalmars-d-learn
On Wednesday, 16 June 2021 at 06:29:21 UTC, z wrote: On Tuesday, 15 June 2021 at 06:39:24 UTC, seany wrote: ... This is the best I could do: https://run.dlang.io/is/dm8LBP For some reason, LDC refuses to vectorize or even just unroll the nonparallel version, and more than one `parallel`

Re: Predicates Within Strings

2021-06-14 Thread jfondren via Digitalmars-d-learn
On Monday, 14 June 2021 at 15:01:01 UTC, Justin Choi wrote: Could somebody explain or point me to documentation that helps to explain the usage of strings in predicates? My main question is how D infers the omitted variable specifications given otherwise - for example: `filter!(a => a <

Re: Can not get struct member addresses at compile time

2021-06-16 Thread jfondren via Digitalmars-d-learn
On Wednesday, 16 June 2021 at 11:56:31 UTC, Mike Parker wrote: https://dlang.org/spec/pragma.html#crtctor "as a simple replacement for shared static this in betterC mode" Cool. However, ```d immutable int example; version(D_BetterC) { pragma(crt_constructor) extern(C) void initialize()

Re: Unpacking Slices

2021-06-14 Thread jfondren via Digitalmars-d-learn
On Monday, 14 June 2021 at 18:08:27 UTC, Justin Choi wrote: Is there any shortcut for unpacking slices like I'd want to do in a scenario like this? `info = readln.strip.split;` `string a = info[0], b = info[1], c = info[2];` This doesn't leave you with multiple local variables, but it leaves

Re: What is this undefined reference with -betterC about?

2021-06-16 Thread jfondren via Digitalmars-d-learn
On Wednesday, 16 June 2021 at 14:21:40 UTC, jfondren wrote: Why isn't this linking? OK, with verbose commands I see that libhostname.a is built without -betterC So that's why this fails to link. What do I change to 1. a script like this that uses hostname 2. the hostname module so that

Re: What is this undefined reference with -betterC about?

2021-06-16 Thread jfondren via Digitalmars-d-learn
On Wednesday, 16 June 2021 at 16:27:13 UTC, Dennis wrote: On Wednesday, 16 June 2021 at 14:38:10 UTC, jfondren wrote: What do I change to 1. a script like this that uses hostname 2. the hostname module so that both can be built with -betterC when and only when the script is using -betterC?

What is this undefined reference with -betterC about?

2021-06-16 Thread jfondren via Digitalmars-d-learn
Here's a complete script that you can run right now, using a dub module that I just updated: ```d #!/usr/bin/env dub /+ dub.sdl: dependency "hostname" version="~>0.1.1" buildOptions "betterC" +/ extern(C) void main() { import hostname : hostnamez; import core.stdc.stdio :

Re: Parallel For

2021-06-15 Thread jfondren via Digitalmars-d-learn
On Tuesday, 15 June 2021 at 06:39:24 UTC, seany wrote: What am I doing wrong? add a `writeln(c.length);` in your inner loop and consider the output. If you were always pushing to the end of c, then only unique numbers should be output. But I see e.g. six occurrences of 0, four of 8 ... Here's

Re: In general, who should do more work: popFront or front?

2021-06-14 Thread jfondren via Digitalmars-d-learn
On Tuesday, 15 June 2021 at 04:24:09 UTC, surlymoor wrote: All my custom range types perform all their meaningful work in their respective popFront methods, in addition to its expected source data iteration duties. The reason I do this is because I swear I read in a github discussion that

Re: Asking for D solution

2021-06-09 Thread jfondren via Digitalmars-d-learn
On Monday, 7 June 2021 at 23:40:52 UTC, Alexander Tretyak wrote: And now I'm looking for people who can translate this task into other languages (D, Rust, Swift, etc.), and then I will compare all implementations by code readability and by performance. So, can someone provide the most

Re: There are some Feed RSS or mail alert for new Dlang compiler update?

2021-06-12 Thread jfondren via Digitalmars-d-learn
On Saturday, 12 June 2021 at 21:20:23 UTC, Marcone wrote: Becouse I can not find it. https://dlang.org/blog/category/dmd-releases/rss takes you to https://feeds.feedburner.com/OfficialDBlog which includes everything, but still has `` to look for.

Re: There are some Feed RSS or mail alert for new Dlang compiler update?

2021-06-12 Thread jfondren via Digitalmars-d-learn
On Sunday, 13 June 2021 at 01:58:41 UTC, Mike Parker wrote: On Saturday, 12 June 2021 at 21:20:23 UTC, Marcone wrote: Becouse I can not find it. Your best bet is to subscribe to the announce mailing list: http://lists.puremagic.com/cgi-bin/mailman/listinfo/digitalmars-d-announce Martin

Re: semi-final switch?

2021-06-17 Thread jfondren via Digitalmars-d-learn
On Friday, 18 June 2021 at 04:24:19 UTC, jfondren wrote: On Thursday, 17 June 2021 at 21:41:28 UTC, Steven Schveighoffer wrote: A final switch on an enum complains if you don't handle all the enum's cases. I like this feature. ... Oh, and to throw a monkey wrench in here, the value is a

Re: semi-final switch?

2021-06-17 Thread jfondren via Digitalmars-d-learn
On Thursday, 17 June 2021 at 21:41:28 UTC, Steven Schveighoffer wrote: A final switch on an enum complains if you don't handle all the enum's cases. I like this feature. ... Oh, and to throw a monkey wrench in here, the value is a string, not an integer. So I can't use std.conv.to to verify

Re: Display a random image with vibe.d

2021-06-20 Thread jfondren via Digitalmars-d-learn
On Sunday, 20 June 2021 at 12:34:33 UTC, vnr wrote: I don't understand why the image doesn't display, when I take an image from the internet and give the url, it works fine though. ``` $ curl -s http://127.0.0.1:8080/|grep img ``` This is a relative URL, so to satisfy it the

Re: Display a random image with vibe.d

2021-06-20 Thread jfondren via Digitalmars-d-learn
On Sunday, 20 June 2021 at 13:58:22 UTC, vnr wrote: Thanks for the answers, I understand better what is going on. So, what should I do to make my server respond with a random image, and not the random image page? I'm fairly new to vibe.d, so I don't yet know the intricacies of how to handle

Re: BetterC, int to string?

2021-06-18 Thread jfondren via Digitalmars-d-learn
On Friday, 18 June 2021 at 09:05:38 UTC, Mike Brown wrote: Hi all, I would like to convert a D string to an int - im doing this in a compile time function as well. conv throws an error due to it using TypeInfo? How would I do this? Kind regards, Mike BetterC has [some CTFE-related

Re: How to recursively accept data from Python server ?

2021-06-24 Thread jfondren via Digitalmars-d-learn
On Friday, 25 June 2021 at 02:55:50 UTC, Utk wrote: Please help me to resolve this issue. Try stracing your program to see exactly what it's doing with the socket, and try std.socket's lastSocketError

Re: How to call stop from parallel foreach

2021-06-25 Thread jfondren via Digitalmars-d-learn
On Friday, 25 June 2021 at 15:16:30 UTC, jfondren wrote: I reckon that there's some other memory error and that the parallelism is unrelated. @safe: ``` source/AI.d(83,23): Error: cannot take address of local `rData` in `@safe` function `main` source/analysisEngine.d(560,20): Error: cannot

Re: How to call stop from parallel foreach

2021-06-25 Thread jfondren via Digitalmars-d-learn
On Friday, 25 June 2021 at 13:53:17 UTC, seany wrote: I tried this . int[][] pnts ; pnts.length = fld.length; enum threadCount = 2; auto prTaskPool = new TaskPool(threadCount); scope (exit) {

Re: How to call stop from parallel foreach

2021-06-25 Thread jfondren via Digitalmars-d-learn
On Friday, 25 June 2021 at 14:44:13 UTC, seany wrote: This particular location does not cause segfault. It is segfaulting down the line in a completely unrelated location... Wait I will try to make a MWP. [Here is MWP](https://github.com/naturalmechanics/mwp). Please compile with `dub build

Re: difficulty with rectangular arrays

2021-06-11 Thread jfondren via Digitalmars-d-learn
On Friday, 11 June 2021 at 08:30:29 UTC, Moth wrote: ``` class ExampleClass { double[6][3] matrix = 0; //fails to compile - "Error: cannot implicitly convert expression `0` of type `int` to `double[6][3]`" } ``` evidently i'm doing something wrong here, but i can't understand what or

Re: How to disable assigning a value to a property?

2021-07-06 Thread jfondren via Digitalmars-d-learn
On Tuesday, 6 July 2021 at 10:06:11 UTC, Jack Applegame wrote: How to disable `register.clock = 10;` but allow `register.clock(1) = 10;`? I want to get a compilation error on `register.clock = 10;` Some options: 1. return a temporary struct with an opIndex ```d import std.stdio; struct

Re: is it possible to sort a float range ?

2021-06-23 Thread jfondren via Digitalmars-d-learn
On Thursday, 24 June 2021 at 02:33:42 UTC, someone wrote: On Thursday, 24 June 2021 at 01:36:47 UTC, Ali Çehreli wrote: import std.algorithm; lnumRange.sort!(r"a > b"c); return lnumRange; The above works OK. Funny thing indeed, at least to me, totally unexpected. ```d

Re: anonymous functions and scope(exit)

2021-07-03 Thread jfondren via Digitalmars-d-learn
On Saturday, 3 July 2021 at 17:20:47 UTC, Luis wrote: This is intentional ? ... scope(exit) inside of a anonymous functions, it's never called. ``` $ rdmd --eval 'iota(2).map!((int x) { scope(exit) writeln("got: ", x); return x+1; }).array.writeln' got: 0 got: 1 [1, 2] ``` Conclusion:

Re: do we already have sum-modulo-10 algo (aka Luhn's algo) on phobos ?

2021-07-03 Thread jfondren via Digitalmars-d-learn
On Saturday, 3 July 2021 at 17:44:48 UTC, someone wrote: https://en.wikipedia.org/wiki/Luhn_algorithm#Pseudocode_implementation That specific function, in Phobos? no. sum modulo 10? That's just some_var%10 in D. The Wikipedia link ends with a link to RosettaCode:

Re: How to call stop from parallel foreach

2021-06-25 Thread jfondren via Digitalmars-d-learn
On Friday, 25 June 2021 at 19:17:38 UTC, seany wrote: If i use `parallel(...)`it runs. If i use `prTaskPool.parallel(...`, then in the line : `auto prTaskPool = new TaskPool(threadCount);` it hits the error. Please help. parallel() reuses a single taskPool that's only established once.

Re: How to call stop from parallel foreach

2021-06-25 Thread jfondren via Digitalmars-d-learn
On Friday, 25 June 2021 at 19:52:23 UTC, seany wrote: On Friday, 25 June 2021 at 19:30:16 UTC, jfondren wrote: On Friday, 25 June 2021 at 19:17:38 UTC, seany wrote: If i use `parallel(...)`it runs. If i use `prTaskPool.parallel(...`, then in the line : `auto prTaskPool = new

Re: A possible readf int bug

2021-06-27 Thread jfondren via Digitalmars-d-learn
On Sunday, 27 June 2021 at 19:50:09 UTC, Matilda wrote: I'm trying to read from stdin and then print an integer value. This is how my code looks like: ```d import std.stdio; import std.conv; import std.string; void main() { writeln("Input your variant (1 - 10):"); int key;

Re: Sumtype warning

2021-07-11 Thread jfondren via Digitalmars-d-learn
On Sunday, 11 July 2021 at 09:20:23 UTC, JG wrote: I am getting the following message: Warning: struct SumType has method toHash, however it cannot be called with const(SumType!(A,B,C)) this Could someone point in the right direction to understand what I am doing that causes this? The two

Re: Scope of enum

2021-07-11 Thread jfondren via Digitalmars-d-learn
On Sunday, 11 July 2021 at 10:58:58 UTC, DLearner wrote: Is there a way of forcing DMD to extend the scope of `MemSiz` to include `k_mod`? Best regards ``` $ cat k_mod.d import test01; ubyte[MemSiz] MemPool; $ cat test01.d enum MemSiz = 240; void main() { import std.stdio, k_mod;

Re: How do I check if a variable is a multidimensional (2D) array?

2021-07-11 Thread jfondren via Digitalmars-d-learn
On Monday, 12 July 2021 at 04:25:00 UTC, Kirill wrote: I know there is isArray!T and similar functionality in std.traits. But I couldn't find the functionality that can help me check if I have a multidimensional array. Is there any? How do I create my own? Thanks in advance. from

Re: mixin template's alias parameter ... ignored ?

2021-07-12 Thread jfondren via Digitalmars-d-learn
On Monday, 12 July 2021 at 22:35:27 UTC, someone wrote: Bug: `scope` makes no sense if you want to return `lstrSequence` (throughout). Teach me please: if I declare a variable right after the function declaration like this one ... ain't scope its default visibility ? I understand (not quite

Re: How to disable assigning a value to a property?

2021-07-06 Thread jfondren via Digitalmars-d-learn
On Tuesday, 6 July 2021 at 15:24:37 UTC, jfondren wrote: 3. https://run.dlang.io/is/AJM6Vg - hybrid where ClockAssign has an unsafe pointer that the compiler complains about :/ 4. ```d import std.stdio; struct Field { void opAssign(int a) { writefln("Field.opAssign(%s)", a);

Re: Remove array element within function

2021-07-05 Thread jfondren via Digitalmars-d-learn
On Monday, 5 July 2021 at 13:10:55 UTC, Rekel wrote: Am I the only one slightly unamused by how arrays/ranges work? They keep backfiring on me, or require weird additions other languages wouldn't require such as manually changing .length, or worrying about what operation returns a copy etc.

Re: Find a char among string (string.findAmong.char)

2021-07-05 Thread jfondren via Digitalmars-d-learn
On Monday, 5 July 2021 at 18:53:27 UTC, jfondren wrote: If you replace the findAmong call with `[letter].findAmong(alphabet)`, this works. Consider: ```d import std; void main() { import std.ascii : alphabet = letters; string wordExample = "Book."; foreach (letter;

Re: Find a char among string (string.findAmong.char)

2021-07-05 Thread jfondren via Digitalmars-d-learn
On Monday, 5 July 2021 at 19:19:19 UTC, BoQsc wrote: If I use `[letter].findAmong(alphabet)` in my code, it considers a dot (.) punctuation character as a letter. You can see it here: https://run.dlang.io/is/YWmaXU It returns a zero-length array that, because it's not null, is true. That's

Re: Find a char among string (string.findAmong.char)

2021-07-05 Thread jfondren via Digitalmars-d-learn
On Monday, 5 July 2021 at 18:45:10 UTC, BoQsc wrote: I get an error when I try to find that letter is among alphabet. onlineapp.d(13): Error: template `std.algorithm.searching.findAmong` cannot deduce function from argument types `!()(immutable(char), immutable(string))`, candidates are:

Re: Find a char among string (string.findAmong.char)

2021-07-05 Thread jfondren via Digitalmars-d-learn
On Monday, 5 July 2021 at 19:34:14 UTC, BoQsc wrote: But I really don't like how it looks less readable and makes less sense on first look. `if (([letter].findAmong(alphabet)).length)` I'd like to use some method on the `letter` instead of [] And `.length` does not make a lot of sense when

Re: Can I get the time "Duration" in "nsecs" acurracy?

2021-07-09 Thread jfondren via Digitalmars-d-learn
On Friday, 9 July 2021 at 21:13:02 UTC, rempas wrote: ``` Duration dur = end - start; dur = dur.total!"nsecs"; ``` What are you trying to do, assigning a nanosecond value to a Duration? The Duration already has that many nanoseconds in it. and I get the following error message: "Error:

Re: UFCS doubt

2021-07-08 Thread jfondren via Digitalmars-d-learn
On Thursday, 8 July 2021 at 22:24:26 UTC, Antonio wrote: onlineapp.d(9): Error: no property `mfp` for type `onlineapp.C` I supossed that ```mfp(c,20)``` and ```c.mfp(20)``` should be equivalent because UFCS in second example, but it is not... why?

Re: Error: function `...` without `this` cannot be `const`

2021-06-30 Thread jfondren via Digitalmars-d-learn
On Wednesday, 30 June 2021 at 20:12:29 UTC, H. S. Teoh wrote: On Wed, Jun 30, 2021 at 07:40:40PM +, someone via Digitalmars-d-learn wrote: [...] @property int data() { return m_data; } // read property [...] string something() @property { return this.whatever; } [...] Now I am not

Re: anonymous functions and scope(exit)

2021-07-04 Thread jfondren via Digitalmars-d-learn
On Sunday, 4 July 2021 at 08:24:36 UTC, Luis wrote: On Saturday, 3 July 2021 at 22:52:39 UTC, frame wrote: It works if you replace printf() with writeln() or use writeln() after. There must be some buffer issue. Not works as you expected. Yes, replacing by writeln (better said, putting a

Re: anonymous functions and scope(exit)

2021-07-04 Thread jfondren via Digitalmars-d-learn
On Sunday, 4 July 2021 at 10:07:08 UTC, jfondren wrote: By that, what you're running into is an unpleasant interaction between 1. scope(exit)s that you're writing 2. Errors being thrown rather than Exceptions 3. anonymous functions getting inferred as nothrow And a resolution could be to

Re: Potential strategy for avoiding problems with copy of a struct (maybe??)

2021-08-22 Thread jfondren via Digitalmars-d-learn
On Sunday, 22 August 2021 at 13:03:20 UTC, james.p.leblanc wrote: On Sunday, 22 August 2021 at 11:10:33 UTC, jfondren wrote: On Sunday, 22 August 2021 at 07:58:12 UTC, james.p.leblanc wrote: Hello, If you don't get an answer that you like, I suggesting posting functional code and then

Re: Potential strategy for avoiding problems with copy of a struct (maybe??)

2021-08-22 Thread jfondren via Digitalmars-d-learn
On Sunday, 22 August 2021 at 14:40:29 UTC, james.p.leblanc wrote: It is a bit scary how you guessed very closely what I am trying to do. I have a AVX aligned pointers (obtained from fftw_malloc), that I want to protect. To be a bit more specific. The code that reads/writes from to/from

Re: Potential strategy for avoiding problems with copy of a struct (maybe??)

2021-08-22 Thread jfondren via Digitalmars-d-learn
On Sunday, 22 August 2021 at 07:58:12 UTC, james.p.leblanc wrote: Hello, Question about a possible strategy to avoid problems with undesired/unintended copying of a structure: 1) We have a struct, call this **Foo**. 2) We instantiate it with, **x = Foo(a,b,c);** a. our constructor

Re: "...cannot be interpreted at compile time" I can't find the source of the error!

2021-08-19 Thread jfondren via Digitalmars-d-learn
On Friday, 20 August 2021 at 02:30:53 UTC, Pablo De Nápoli wrote: Any idea of which could be the cause of trouble or on how to get more specific diagnosis? With no extra arguments I get a "compile time context created here" addendum. Does that not show up for you or does the line not make

Re: Why the very same code works in main and not in unittest?

2021-08-20 Thread jfondren via Digitalmars-d-learn
On Friday, 20 August 2021 at 16:02:22 UTC, Pablo De Nápoli wrote: Consider the following code: void main() { mpd_context_t ctx; mpd_t* a; mpd_ieee_context(, 128); a= mpd_new(); } It seems to work fine. ... However, if I put the very same code in the

Re: Unexpected result comparing to null

2021-08-23 Thread jfondren via Digitalmars-d-learn
On Monday, 23 August 2021 at 13:00:36 UTC, DLearner wrote: Hi The code below compiles and runs producing 'Not null'. ``` void main() { import std.stdio; int Var1; int* ptrVar; ptrVar = if (ptrVar == null) { writeln("Null"); } else { writeln("Not null");

Re: How to get element type of a slice?

2021-08-18 Thread jfondren via Digitalmars-d-learn
On Thursday, 19 August 2021 at 03:32:47 UTC, Jesse Phillips wrote: On Thursday, 19 August 2021 at 03:29:03 UTC, Jesse Phillips wrote: On Tuesday, 17 August 2021 at 12:33:03 UTC, Ferhat Kurtulmuş wrote: On Tuesday, 17 August 2021 at 12:26:36 UTC, jfondren wrote: On Tuesday, 17 August 2021 at

Re: Quotes and backticks together in a raw string

2021-08-18 Thread jfondren via Digitalmars-d-learn
On Wednesday, 18 August 2021 at 22:18:59 UTC, Brian Tiffin wrote: Google fu is failing on this one. string docs are at https://dlang.org/spec/lex.html Is there a way to have a raw multi-line string literal with both double-quotes and backticks inside?

Re: Concurrency message passing

2021-08-17 Thread jfondren via Digitalmars-d-learn
On Tuesday, 17 August 2021 at 11:05:09 UTC, JG wrote: Hi I have a program with two threads. One thread produces data that is put in a queue and then consumed by the other thread. I initially built a custom queue to do this, but thought this should have some standard solution in D? I looked

Re: How to get element type of a slice?

2021-08-17 Thread jfondren via Digitalmars-d-learn
On Tuesday, 17 August 2021 at 12:21:31 UTC, Ferhat Kurtulmuş wrote: Hello folks, Hope everyone is doing fine. Considering the following code, in the first condition, I am extracting the type Point from the slice Point[]. I searched in the std.traits, and could not find a neater solution

Re: foreach() behavior on ranges

2021-08-24 Thread jfondren via Digitalmars-d-learn
On Tuesday, 24 August 2021 at 08:36:18 UTC, frame wrote: Consider a simple input range that can be iterated with empty(), front() and popFront(). That is comfortable to use with foreach() but what if the foreach loop will be cancelled? If a range isn't depleted yet and continued it will supply

Re: A way to mixin during runtime?

2021-08-27 Thread jfondren via Digitalmars-d-learn
On Friday, 27 August 2021 at 10:34:27 UTC, Kirill wrote: Each csv file will be different. For example: ``` name;surname;age;grade Alex;Wong;18;87 John;Doe;19;65 Alice;Doe;18;73 etc... ``` I'd like to extract the data types automatically. For instance, if using tuples: ``` Tuple!(string,

Re: Mixin/static if issue

2021-08-25 Thread jfondren via Digitalmars-d-learn
On Wednesday, 25 August 2021 at 22:52:23 UTC, DLearner wrote: On Wednesday, 25 August 2021 at 22:33:00 UTC, H. S. Teoh wrote: [...} I think what you meant to write is: static if (typeof(mixin(VarName)).stringof == "uint") { You want the type of the variable named by VarName, not the

Re: compile time compression for associatve array literal

2021-08-23 Thread jfondren via Digitalmars-d-learn
On Monday, 23 August 2021 at 14:04:05 UTC, Brian Tiffin wrote: That's the goal. It's an optional goal at this point. I'm not *really* worried about size of object code, yet, but figured this would be a neat way to shrink the compiled code generated from some large COBOL source fragments

Re: alias this - am I using it wrong?

2021-08-25 Thread jfondren via Digitalmars-d-learn
On Wednesday, 25 August 2021 at 12:11:01 UTC, Johann Lermer wrote: ```d 14 void main () 15 { 16 auto ac = new Alias_Class; 17 Test_Struct ts = ac; // compiles 18 ac = ts; // compiles as well - why? 19 20 auto tc = new Test_Class; 21 ts = tc.ac; //

Re: byte + byte = int: why?

2021-08-29 Thread jfondren via Digitalmars-d-learn
On Sunday, 29 August 2021 at 15:57:18 UTC, Paul Backus wrote: On Sunday, 29 August 2021 at 15:42:18 UTC, Ali Çehreli wrote: Depending on the situation, you may want to use std.conv.to, which does a value range check and throws an exception to prevent an error: byte foo(byte a, byte b) {

Re: Question on Immutability

2021-08-31 Thread jfondren via Digitalmars-d-learn
On Tuesday, 31 August 2021 at 05:42:22 UTC, ag0aep6g wrote: On 31.08.21 02:50, Mike Parker wrote: Member functions marked as immutable can be called on both mutable and immutable instances. That's not true. Demonstrated: ```d struct S { int x; int get() immutable { return x; } }

Re: DMD compiler - warning of unused variables

2021-08-16 Thread jfondren via Digitalmars-d-learn
On Monday, 16 August 2021 at 14:14:27 UTC, DLearner wrote: Hi Please see code below: ``` void main() { import std.stdio; size_t i; size_t j; i = 5; writeln("i = ",i); } ``` Is there a compiler option that would warn that variable 'j' is defined but not used? Best

Re: How to extend the string class to return this inside the square bracket?

2021-08-13 Thread jfondren via Digitalmars-d-learn
On Friday, 13 August 2021 at 22:09:59 UTC, Marcone wrote: Isn't there some unario operator template that I can use with lambda to handle a string literal? So, something other than an exact "lit"[0..this.xx(..)] syntax is fine? What didn't you like about `"Hello

Re: How to extend the string class to return this inside the square bracket?

2021-08-13 Thread jfondren via Digitalmars-d-learn
On Friday, 13 August 2021 at 23:23:55 UTC, Marcone wrote: On Friday, 13 August 2021 at 23:08:07 UTC, jfondren wrote: On Friday, 13 August 2021 at 22:09:59 UTC, Marcone wrote: Isn't there some unario operator template that I can use with lambda to handle a string literal? So, something

Re: std.stdio.File is throwing with the message of: "Access Violation"

2021-08-20 Thread jfondren via Digitalmars-d-learn
On Friday, 20 August 2021 at 21:19:09 UTC, Ruby The Roobster wrote: MessageBoxA(null, "Error", cast(char)[])e.msg,MB_OK | ICON_ERROR); use std.string.toStringz to ensure that e.msg is 0-terminated.

Re: Unqualified class name

2021-08-21 Thread jfondren via Digitalmars-d-learn
On Saturday, 21 August 2021 at 17:33:51 UTC, Jeremy T. Gibson wrote: is there a simple way to get the unqualified name of a class at runtime without having to pass it through std.format? `typeid(class).name` always yields the full classname, including its module information (i.e.,

Re: Unqualified class name

2021-08-21 Thread jfondren via Digitalmars-d-learn
On Saturday, 21 August 2021 at 21:13:58 UTC, Jeremy T. Gibson wrote: On Saturday, 21 August 2021 at 18:27:34 UTC, Ali Çehreli wrote: return __traits(identifier, typeof(this)); That works perfectly! Thanks. =) This is exactly the solution you linked to in your first post, and found

Re: What exactly are the String literrals in D and how they work?

2021-08-15 Thread jfondren via Digitalmars-d-learn
On Sunday, 15 August 2021 at 06:10:53 UTC, rempas wrote: So when I'm doing something like the following: `string name = "John";` Then what's the actual type of the literal `"John"`? ```d unittest { pragma(msg, typeof("John")); // string pragma(msg, is(typeof("John") ==

Re: What exactly are the String literrals in D and how they work?

2021-08-15 Thread jfondren via Digitalmars-d-learn
On Sunday, 15 August 2021 at 07:43:59 UTC, jfondren wrote: On Sunday, 15 August 2021 at 06:10:53 UTC, rempas wrote: ```d unittest { char* s = "John".dup.ptr; s[0] = 'X'; // no segfaults assert(s[0..4] == "Xohn"); // ok } ``` So am I going to have an extra runtime cost having to

Re: What exactly are the String literrals in D and how they work?

2021-08-15 Thread jfondren via Digitalmars-d-learn
On Sunday, 15 August 2021 at 07:47:27 UTC, jfondren wrote: On Sunday, 15 August 2021 at 07:43:59 UTC, jfondren wrote: On Sunday, 15 August 2021 at 06:10:53 UTC, rempas wrote: ```d unittest { char* s = "John".dup.ptr; s[0] = 'X'; // no segfaults assert(s[0..4] == "Xohn"); // ok } ```

Re: What exactly are the String literrals in D and how they work?

2021-08-15 Thread jfondren via Digitalmars-d-learn
On Sunday, 15 August 2021 at 08:11:39 UTC, rempas wrote: On Sunday, 15 August 2021 at 07:43:59 UTC, jfondren wrote: ```d unittest { char* s = "John".dup.ptr; s[0] = 'X'; // no segfaults assert(s[0..4] == "Xohn"); // ok } ``` Well, that one didn't worked out really well for me.

Re: What exactly are the String literrals in D and how they work?

2021-08-15 Thread jfondren via Digitalmars-d-learn
On Sunday, 15 August 2021 at 08:56:07 UTC, rempas wrote: On Sunday, 15 August 2021 at 08:53:50 UTC, Tejas wrote: External C libraries expect strings to be null terminated, so if you do use `.dup`, use `.toStringz` as well. Yeah, yeah I got that. My question is, if I should avoid

Re: how to import .lib library

2021-08-15 Thread jfondren via Digitalmars-d-learn
On Sunday, 15 August 2021 at 10:19:33 UTC, Mike Parker wrote: On Sunday, 15 August 2021 at 10:12:17 UTC, Timofeyka wrote: Thank you for your reply! I wanted to link to my project another project without source code. Yeah, that's not possible. You either need the source or a set of D

Re: Unqualified class name

2021-08-21 Thread jfondren via Digitalmars-d-learn
On Sunday, 22 August 2021 at 00:18:18 UTC, Ali Çehreli wrote: I did not read the linked thread but a "this template parameter" seems to work in this case: class Whoami { string name(this This)() const { return __traits(identifier, This); } } class AnotherOne : Whoami { } unittest {

Re: Dustmite and linking error

2021-09-02 Thread jfondren via Digitalmars-d-learn
On Thursday, 2 September 2021 at 11:04:12 UTC, JG wrote: Hi, We hit a linking error (after upgrading to dub 1.26.0). I thought I would try to use dustmite to create a reduced error test case. One week later it is still running (depth 22). I don't suppose there is anyway of determining when

Re: Run-time setting of immutable variable?

2021-09-02 Thread jfondren via Digitalmars-d-learn
On Thursday, 2 September 2021 at 17:17:15 UTC, DLearner wrote: Surely there is no inconsistency - at run time the array is in a fixed place, so ArrPtr is (or at least should be) a constant, but the contents of the array can vary as the program runs. In the case of `immutable(T)* ArrPtr`,

Re: Documentation generator is not working

2021-09-02 Thread jfondren via Digitalmars-d-learn
On Thursday, 2 September 2021 at 16:20:32 UTC, Vinod K Chandran wrote: Hi all, I am playing with ddoc. I wrote this code-- ```d import std.stdio : log = writeln; void main() { log("Experimenting with dDoc"); } /// A sample function. /// Let's check what we will get in documentation. ///

Re: Forum posting question ... how post a thread question with color syntax highlighting ??

2021-09-05 Thread jfondren via Digitalmars-d-learn
On Sunday, 5 September 2021 at 17:48:51 UTC, james.p.leblanc wrote: Dear All, I have noticed that quite a few posts and responses on this forum include d snippets made with **nicely colored syntax highlighting.** (I do not mean just the bold markdown text.) This increases post clarity

Re: "+=" (overloads) with custom array slices on both lhs, and rhs ??

2021-09-05 Thread jfondren via Digitalmars-d-learn
On Sunday, 5 September 2021 at 20:49:08 UTC, james.p.leblanc wrote: On Sunday, 5 September 2021 at 20:38:29 UTC, Paul Backus wrote: Please post the source code for `myarray_mod` so that we can reproduce the errors you're seeing. Hello Paul, Thanks for having a look ... James Here's a

Re: How to simply parse and print the XML with dxml?

2021-09-09 Thread jfondren via Digitalmars-d-learn
On Thursday, 9 September 2021 at 17:17:23 UTC, tastyminerals wrote: Maybe I missed something obvious in the docs but how can I just parse the XML and print its content? ``` import dxml.parser; auto xml = parseXML!simpleXML(layout); xml.map!(e => e.text).join.writeln; ``` throws

Re: Which operators cannot be overloaded and why not?

2021-09-13 Thread jfondren via Digitalmars-d-learn
On Monday, 13 September 2021 at 14:33:03 UTC, user1234 wrote: - condition al expression ` cond ? exp : exp ` And many other boolean operators, unary !, binary && and || https://dlang.org/spec/operatoroverloading.html lists all the overloadable operators, and

Re: Program crash: GC destroys an object unexpectedly

2021-09-14 Thread jfondren via Digitalmars-d-learn
On Tuesday, 14 September 2021 at 16:56:52 UTC, eugene wrote: On Tuesday, 14 September 2021 at 16:43:50 UTC, jfondren wrote: GC needs to be able to stop your program nice fantasies... and find all of the live objects in it. The misaligned pointer and the reference-containing struct that

Re: Program crash: GC destroys an object unexpectedly

2021-09-14 Thread jfondren via Digitalmars-d-learn
On Tuesday, 14 September 2021 at 14:40:55 UTC, eugene wrote: On Tuesday, 14 September 2021 at 12:09:03 UTC, Steven Schveighoffer wrote: This project is too big and complex Really, "too big and complex"? It's as simple as a tabouret :) It's just a toy/hobby 'project'. A 5-pound phone isn't

Re: Program crash: GC destroys an object unexpectedly

2021-09-14 Thread jfondren via Digitalmars-d-learn
On Tuesday, 14 September 2021 at 15:37:27 UTC, eugene wrote: On Tuesday, 14 September 2021 at 14:56:00 UTC, jfondren wrote: You could fix this by having a 128-bit struct and passing C an index into it It is another "not so funny joke", isn't it? No. And when was the first one? ```d align

Re: Program crash: GC destroys an object unexpectedly

2021-09-14 Thread jfondren via Digitalmars-d-learn
On Tuesday, 14 September 2021 at 16:15:20 UTC, eugene wrote: On Tuesday, 14 September 2021 at 16:07:00 UTC, jfondren wrote: No. And when was the first one? here: On Monday, 13 September 2021 at 18:45:22 UTC, jfondren wrote: auto p = cast(EpollEvent*) pureMalloc(EpollEvent.sizeof); What?

Re: Program crash: GC destroys an object unexpectedly

2021-09-15 Thread jfondren via Digitalmars-d-learn
On Tuesday, 14 September 2021 at 20:59:14 UTC, Ali Çehreli wrote: On 9/14/21 9:56 AM, eugene wrote: > On Tuesday, 14 September 2021 at 16:43:50 UTC, jfondren wrote: >> The misaligned pointer and the >> reference-containing struct that vanishes on the return of your >> corresponding function

Re: Is std.variant useful for types only known at run time?

2021-09-08 Thread jfondren via Digitalmars-d-learn
On Wednesday, 8 September 2021 at 09:55:20 UTC, Chris Piker wrote: Interesting. I presume that the big win for using std.sumtype over a class set is value semantics instead of reference semantics? There's a lot to say about the precise differences. One practical difference that I alluded to

Re: Is std.variant useful for types only known at run time?

2021-09-08 Thread jfondren via Digitalmars-d-learn
On Wednesday, 8 September 2021 at 07:10:21 UTC, Chris Piker wrote: Hi D I'm working on data streaming reading module where the encoding of each input array isn't known until runtime. For example date-time column values may be encoded as: * An ISO-8601 UTC time string (aka char[]) * A

Re: Looking to get typeof parseXML return value

2021-09-06 Thread jfondren via Digitalmars-d-learn
On Tuesday, 7 September 2021 at 04:13:08 UTC, Chris Piker wrote: Any ideas on how to get the return type of `parseXML` below: ``` import dxml.parser; const(char)[] _mmfile; //_mmfile initialization TYPE??? _entityRng = parseXML!(simpleXML)(_mmfile); ``` *before* calling parseXML, so that it

Re: Program crash: GC destroys an object unexpectedly

2021-09-18 Thread jfondren via Digitalmars-d-learn
On Saturday, 18 September 2021 at 09:39:24 UTC, eugene wrote: The definition of this struct was taken from /usr/include/dmd/druntime/import/core/sys/linux/epoll.d ... If the reason for crash was in EpollEvent alignment, programs would segfaults always very soon after start, just right after

Re: MobI? Really?

2021-09-18 Thread jfondren via Digitalmars-d-learn
On Saturday, 18 September 2021 at 20:40:56 UTC, Chris_D wrote: The "D Programming Language Specification" seems to be the most important documentation for D. Is it really only available as Mobi? That is the most bizarre choice of format I've ever seen. Chris No, it's not *only*

Re: Extract base type of any array?

2021-09-18 Thread jfondren via Digitalmars-d-learn
On Sunday, 19 September 2021 at 03:58:41 UTC, Kirill wrote: How can I get the base type of any (multidimensional/static/dynamic/associative) array? Example: ``` void main() { int[][] intArr; double[4][] doubleArr; string[string][] strArr; intArr.example; // T = int

Re: Program crash: GC destroys an object unexpectedly

2021-09-19 Thread jfondren via Digitalmars-d-learn
On Sunday, 19 September 2021 at 08:51:31 UTC, eugene wrote: reference-containing struct that vanishes on the return of your corresponding function I do not think it's a problem, otherwise **both programs would not work at all**. The GC doesn't reliably punish objects living past there not

Re: Merge 2 structs together (into a single struct)?

2021-09-16 Thread jfondren via Digitalmars-d-learn
On Thursday, 16 September 2021 at 20:12:03 UTC, james.p.leblanc wrote: Is there some obvious, and simple solution to this conundrum of mine? I would consider AAs. ```d struct A { int alpha; float x = 1.23; } struct B { int beta; float y = 4.4; string s = "this is fine.";

Re: dub segfault and range error handling

2021-09-16 Thread jfondren via Digitalmars-d-learn
On Thursday, 16 September 2021 at 20:49:28 UTC, seany wrote: I compile with : `dub build -b release --compiler=ldc2` The result executing the compiled binary 'myproj' is is ( whether `writeln (a[1])` is uncommented, or the `test()` function is uncommented) some random number, usually

Re: Merge 2 structs together (into a single struct)?

2021-09-16 Thread jfondren via Digitalmars-d-learn
On Friday, 17 September 2021 at 05:01:36 UTC, james.p.leblanc wrote: Again, thanks to you and many of the D community with helping to learn and appreciate the capabilities of D. It is nice to be here. Yeah. The improved joinStruct is nice enough that I think it's probably a good thing to

Re: GC seems to crash my C-code function

2021-09-17 Thread jfondren via Digitalmars-d-learn
On Friday, 17 September 2021 at 06:27:40 UTC, frame wrote: Thanks, I'm just careful with casting. Does it really allocate from a literal if it's used on the stack only? Is `-vgc` switch reliable? looks to me like it calls ```d // object private U[] _dup(T, U)(scope T[] a) pure nothrow

Re: yet another segfault - array out of bound is not caught by try catch

2021-09-17 Thread jfondren via Digitalmars-d-learn
On Friday, 17 September 2021 at 11:10:33 UTC, seany wrote: Compile with `dub build --compiler=ldc2 `. this should enable array bound checking options. By default, yes. run `dub -v build --compiler=ldc2` to see the exact commands that dub runs. But should it not be caught by range error

Re: Program crash: GC destroys an object unexpectedly

2021-09-13 Thread jfondren via Digitalmars-d-learn
On Monday, 13 September 2021 at 17:18:30 UTC, eugene wrote: Then after pressing ^C (SIGINT) the program gets SIGSEGV, since references to sg0 and sg1 are no longer valid (they are "sitting" in epoll_event structure). engine/ecap.d(54): Error: field `EpollEvent.es` cannot assign to misaligned

Re: How to simply parse and print the XML with dxml?

2021-09-09 Thread jfondren via Digitalmars-d-learn
On Thursday, 9 September 2021 at 23:29:56 UTC, Imperatorn wrote: On Thursday, 9 September 2021 at 18:40:53 UTC, jfondren wrote: On Thursday, 9 September 2021 at 17:17:23 UTC, tastyminerals wrote: [...] dxml.parser is a streaming XML parser. The documentation at

  1   2   3   >