Re: How to obtain Variant underlying type?

2022-07-09 Thread jfondren via Digitalmars-d-learn
On Saturday, 9 July 2022 at 23:04:20 UTC, anonymouse wrote: On Saturday, 9 July 2022 at 14:46:36 UTC, Adam D Ruppe wrote: Impossible; Variant's type is only known at runtime, and this would require compile time knowledge. Hmmm. Okay, thanks. What I really need to know is how many dimensions

Re: How to obtain Variant underlying type?

2022-07-10 Thread jfondren via Digitalmars-d-learn
On Monday, 11 July 2022 at 03:17:33 UTC, anonymouse wrote: On Sunday, 10 July 2022 at 18:31:46 UTC, drug007 wrote: I'd like to say that using of exception to break loop is really bad. Exception is exceptional thing but in the case above the exception is ordinary completion of the loop happens

Re: Choosing the correct compiler version

2022-07-19 Thread jfondren via Digitalmars-d-learn
On Tuesday, 19 July 2022 at 15:33:59 UTC, Alexander Zhirov wrote: On Tuesday, 19 July 2022 at 15:28:44 UTC, Alexander Zhirov wrote: I'm trying to install dmd with my hands in order to build ldc2 from the sources, but I can't: I need to build a compiler under x32 in order to compile a program

Re: Obsecure problem 2

2022-08-03 Thread jfondren via Digitalmars-d-learn
On Wednesday, 3 August 2022 at 16:59:53 UTC, pascal111 wrote: I tried to make a template that receive lambda expression to apply it on a given range the user specifies, but I found non-understood problem: Compare with: ```D auto foo(Range)(Range range) { // remove isInputRange!T test ...

Re: Obsecure problem 2

2022-08-03 Thread jfondren via Digitalmars-d-learn
On Wednesday, 3 August 2022 at 17:33:40 UTC, pascal111 wrote: On Wednesday, 3 August 2022 at 17:09:11 UTC, jfondren wrote: On Wednesday, 3 August 2022 at 16:59:53 UTC, pascal111 wrote: I tried to make a template that receive lambda expression to apply it on a given range the user specifies, but

Re: Obsecure problem 2

2022-08-03 Thread jfondren via Digitalmars-d-learn
On Wednesday, 3 August 2022 at 18:33:37 UTC, pascal111 wrote: I changed it to "x=notfunny(x);" and has the same result. Now you are changing the value of the temporary loop variable that is still immediately discarded afterwards. You should return a new range that has the values you want, no

Re: Obsecure problem 2

2022-08-03 Thread jfondren via Digitalmars-d-learn
On Wednesday, 3 August 2022 at 19:11:51 UTC, pascal111 wrote: On Wednesday, 3 August 2022 at 18:53:35 UTC, jfondren wrote: On Wednesday, 3 August 2022 at 18:33:37 UTC, pascal111 wrote: I changed it to "x=notfunny(x);" and has the same result. Now you are changing the value of the temporary lo

Re: Unittest Absurdity

2022-08-04 Thread jfondren via Digitalmars-d-learn
On Friday, 5 August 2022 at 01:25:50 UTC, Ruby The Roobster wrote: On Friday, 5 August 2022 at 01:23:40 UTC, Ruby The Roobster wrote: [SNIP] Any function other than an operator overload seems to work fine. Also, this isn't mentioned in the spec. Additional Information: Fails for both DMD an

Re: Unittest Absurdity

2022-08-04 Thread jfondren via Digitalmars-d-learn
On Friday, 5 August 2022 at 01:38:48 UTC, jfondren wrote: Here's a complete example that passes tests: ```d struct S { int n; void opOpAssign(string op)(S rhs) if (op == "/") { n++; } } unittest { auto a = S(1), b = S(2); a /= b; b /= a; assert(a.n == 2);

Re: Unittest Absurdity

2022-08-04 Thread jfondren via Digitalmars-d-learn
On Friday, 5 August 2022 at 01:53:42 UTC, Ruby The Roobster wrote: On Friday, 5 August 2022 at 01:38:48 UTC, jfondren wrote: Here's a complete example that passes tests: ```d struct S { int n; void opOpAssign(string op)(S rhs) if (op == "/") { n++; } } Nevermind. I have t

Re: Unittest Absurdity

2022-08-04 Thread jfondren via Digitalmars-d-learn
On Friday, 5 August 2022 at 02:20:31 UTC, Steven Schveighoffer wrote: On 8/4/22 9:51 PM, Paul Backus wrote: Another option: use -vcg-ast, and have the compiler tell you what it's actually calling. It's not ignoring that line, it's just not doing what you think it's doing. The output's not tha

Re: Verbosity in D

2022-08-07 Thread jfondren via Digitalmars-d-learn
On Sunday, 7 August 2022 at 16:01:08 UTC, pascal111 wrote: It's clear by working with D that it has the same bad point like Pascal language; the "verbosity". Is there any plans in future to make some shorthanded techniques that clean verbosity from D? That's not clear to me at all, and your P

Re: "min" and "max"

2022-08-09 Thread jfondren via Digitalmars-d-learn
On Wednesday, 10 August 2022 at 00:03:37 UTC, pascal111 wrote: On Tuesday, 9 August 2022 at 23:56:53 UTC, Paul Backus wrote: On Tuesday, 9 August 2022 at 23:35:23 UTC, pascal111 wrote: "min" and "max" in "std.algorithm" can be used with single values to pick up the min and max values, but it di

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 idiomati

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 why

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 annou

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 < 3)(arr)

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: 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 front

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: 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` corru

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() {

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 : printf;

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 bo

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? Th

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 th

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 string

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 bugs](

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 t

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 ret

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 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: 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 ta

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. Your

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 TaskPool(threadCo

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; //readf("

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 su

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: it's

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: https://rosettacode.org/wiki

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 wri

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 submi

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. (Ki

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: /dla

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; wordExample)

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 wh

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 rea

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 Fiel

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: 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? https://dlang.org/spec/function.html#pseudo-

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: can

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 r

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; w

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 https://gi

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 s

Re: static assert not printing out along the error diagnostic

2021-07-13 Thread jfondren via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 03:06:06 UTC, someone wrote: in main() ... so then I went to the D docs and to Ali's book afterward and there I tested his example to same results. The current behavior seems like it could be taken for a bug, or at least room for improvement in letting static asse

Re: static assert not printing out along the error diagnostic

2021-07-14 Thread jfondren via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 18:04:44 UTC, someone wrote: On Wednesday, 14 July 2021 at 06:28:37 UTC, jfondren wrote: alternate 1: - pull tests out into a named enum template, like std.traits - always static assert enum, rather than conditionally asserting false - always have the rest of the

Re: Reference Counted Class

2021-07-14 Thread jfondren via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 18:33:56 UTC, Tejas wrote: For deterministic object destruction, there's the ```scope``` storage class: ```d scope class_instance = new class(); scope(exit) class_instance.destroy ``` One or the other. The `scope(exit)` will still fire on scope exit in the case

Re: static assert not printing out along the error diagnostic

2021-07-14 Thread jfondren via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 22:59:38 UTC, someone wrote: Please, go to the bottom of the unittest block and uncomment one of those lines (DMD version here is DMD64 D Compiler v2.096.1): so, these lines: ```d stringUGC32 lugcSequence3 = stringUGC32(cast(char) 'x'); stringUGC32 lugc

Re: Manipulate and parse jasonb object in timescaledb(postgresql)

2021-07-14 Thread jfondren via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 21:56:11 UTC, Alain De Vos wrote: With good select operators i can extract the data i need for instance: select measurement->'room.temperature' from mytable; Now how to process that further as json object ? or jsonb object in dlang ? You'll need to either lean

Re: Manipulate and parse jasonb object in timescaledb(postgresql)

2021-07-14 Thread jfondren via Digitalmars-d-learn
On Thursday, 15 July 2021 at 01:08:28 UTC, Alain De Vos wrote: As an example i show this. https://docs.python.org/3/library/json.html But that is more what i look for. That's JSON, not JSONB. D has JSON support in https://dlang.org/phobos/std_json.html

Re: How to create friends of a class at compile time?

2021-07-15 Thread jfondren via Digitalmars-d-learn
On Thursday, 15 July 2021 at 17:21:45 UTC, Tejas wrote: I can do it like this in C++: ``` template class def { friend typename abc; } ``` I am just hopelessly confused on how to achieve the same in D. Uncharitably: D is a friendless language. Charitably: D is so much more friendly that in

Re: Please help me understand this function signature: std.stdio.File.byLine

2021-07-15 Thread jfondren via Digitalmars-d-learn
On Thursday, 15 July 2021 at 18:08:45 UTC, Scotpip wrote: The relevant function appears to be [std.stdio.File.byLine](https://dlang.org/library/std/stdio/file.by_line.html). The default isn't breaking the lines properly, so I have to pass in the line ending. But the signature has me baffled:

Re: Hello world/Web server task on RosettaCode fails

2021-07-16 Thread jfondren via Digitalmars-d-learn
On Friday, 16 July 2021 at 19:25:32 UTC, btiffin wrote: Using gdc-11 and Seamonkey. https://rosettacode.org/wiki/Hello_world/Web_server#D does not compile. The `while` as you noted is wrong. The server also doesn't turn REUSEADDR on for the server socket, so this will be very annoying to te

Re: Hello world/Web server task on RosettaCode fails

2021-07-16 Thread jfondren via Digitalmars-d-learn
On Friday, 16 July 2021 at 20:04:21 UTC, jfondren wrote: static const greeting = q"EOF Or just `immutable greeting = ...`

Re: issue with static foreach

2021-07-21 Thread jfondren via Digitalmars-d-learn
On Thursday, 22 July 2021 at 03:43:44 UTC, someone wrote: ... it compiles no-more: Error: found `End of File` when expecting `}` following compound statement ... what I am doing wrong ? You'll get the same error from this code: ```d unittest { mixin("{"); mixin("}"); } ``` https://d

Re: associative array with Parallel

2021-07-21 Thread jfondren via Digitalmars-d-learn
On Thursday, 22 July 2021 at 05:46:25 UTC, seany wrote: But what about this : int [ string ] ii; ii.length = somearray.length; foreach(i,dummy; parallel(somearray)) { string j = generateUniqueString(i); ii[j] ~= somefunc(dummy); } Is this also guaranteed thread safe

Re: associative array with Parallel

2021-07-22 Thread jfondren via Digitalmars-d-learn
On Thursday, 22 July 2021 at 07:23:36 UTC, seany wrote: On Thursday, 22 July 2021 at 05:53:01 UTC, jfondren wrote: No. Consider https://programming.guide/hash-tables-open-vs-closed-addressing.html The page says : A key is always stored in the bucket it's hashed to. What if my keys are a

Re: associative array with Parallel

2021-07-22 Thread jfondren via Digitalmars-d-learn
On Thursday, 22 July 2021 at 07:51:04 UTC, seany wrote: OK. Sorry for the bad question : what if i pregenerate every possible key, and fill the associative array where each such key contains some invalid number, say -1 ? You mean where each value contains some invalid number, and the AA's k

Re: Performance issue with fiber

2021-07-24 Thread jfondren via Digitalmars-d-learn
On Saturday, 24 July 2021 at 09:17:47 UTC, Stefan Koch wrote: On Wednesday, 21 July 2021 at 22:51:38 UTC, hanabi1224 wrote: Hi, I'm new to D lang and encounter some performance issues with fiber, not sure if there's something obviously wrong with my code. There is your problem. auto sc

Re: byKeyValue is not available at compilation-time right ?

2021-07-25 Thread jfondren via Digitalmars-d-learn
On Sunday, 25 July 2021 at 05:10:32 UTC, someone wrote: /// implementation: however, would it be possible to dynamically‐load the following enums from a file at compilation‐time ? public immutable enum structureLocations = [ r"BUE"d : typeLocation(r"arg"d, r"Buenos Aires"d, r"ART"d), r"G

Re: Performance issue with fiber

2021-07-26 Thread jfondren via Digitalmars-d-learn
On Monday, 26 July 2021 at 15:27:48 UTC, russhy wrote: ``` build: ``` dub build --compiler=ldc -brelease --single primesv1.d ``` -brelease is a typo issue, i don't think that produce defired effect, most likely it defaulted to debug build it should be -b release No, it builds a release

Re: AA.values un-@safe?!

2021-07-28 Thread jfondren via Digitalmars-d-learn
On Wednesday, 28 July 2021 at 21:04:11 UTC, Per Nordlöw wrote: Why is call to `values` in, for instance, ```d auto _ = string[string].init.values; ``` not `@safe`? I don't know, but .byValue is @safe and returns a forward range, so you could use `.init.byValue.array` instead.

Re: Exit before second main with -funittest

2021-07-29 Thread jfondren via Digitalmars-d-learn
On Friday, 30 July 2021 at 01:01:02 UTC, Brian Tiffin wrote: Is this good, bad or indifferent (a right left choice, first one doesn't matter)? I think you're opening yourself up to errors where some program state persists from one run of main to another. You could think that some set of flags

Re: translate C struct char array into D

2021-07-30 Thread jfondren via Digitalmars-d-learn
On Friday, 30 July 2021 at 14:05:58 UTC, workman wrote: I get want to define this struct in D: ```c struct test1 { struct test1 *prev; struct test1 *next; size_t v1; size_t v2; size_t v3; char data[]; }; ``` The easy way: put a slice there instead of a fake array and a

Re: Any way to create derived classes from Exception with canned messages?

2021-07-31 Thread jfondren via Digitalmars-d-learn
On Saturday, 31 July 2021 at 08:25:56 UTC, Jeremy T. Gibson wrote: Now, https://github.com/dlang/druntime/blob/master/src/object.d clearly expresses that the constructors of Exception are @nogc. Therein lies the problem: there is no way to use the ~ concatenation operator in a @nogc function.

Re: Routing of AssertError messages

2021-07-31 Thread jfondren via Digitalmars-d-learn
On Saturday, 31 July 2021 at 12:03:49 UTC, DLearner wrote: Hi This may be due to Windows, not DMD. Please see code below (held in test.d): ``` void main() { import std.stdio; writeln("Test"); assert(false, "TestAssert"); } ``` ` dmd -i -run test.d ` results in both "Test" and the "Te

Re: Is returning void functions inside void functions a feature or an artifact?

2021-08-02 Thread jfondren via Digitalmars-d-learn
On Monday, 2 August 2021 at 14:31:45 UTC, Rekel wrote: I recently found one can return function calls to void functions, though I don't remember any documentation mentioning this even though it doesn't seem trivial. ```d void print(){ writeln("0"); } void doSomething(int a){ i

Re: Find struct not passed by reference

2021-08-02 Thread jfondren via Digitalmars-d-learn
On Monday, 2 August 2021 at 23:06:42 UTC, frame wrote: Is there a way to find a struct which should be passed by reference but accidentally isn't? Maybe with copy constructors? @disable postblit: ```d struct NoCopy { int n; @disable this(this); } void modify(NoCopy nc) { nc.n++; }

Re: Find struct not passed by reference

2021-08-03 Thread jfondren via Digitalmars-d-learn
On Tuesday, 3 August 2021 at 19:11:16 UTC, frame wrote: On Tuesday, 3 August 2021 at 16:35:04 UTC, Ali Çehreli wrote: Why foreach() does not accept a pointer? pointers don't come with a length?

Re: best/proper way to declare constants ?

2021-08-05 Thread jfondren via Digitalmars-d-learn
On Thursday, 5 August 2021 at 16:06:58 UTC, someone wrote: So if we are talking AA-arrays at compile-time only there should be nothing wrong with the following code ... right ? ... private enum pudtLocations = [ r"BUE"d : structureLocation(r"arg"d, r"Buenos Aires"d, r"ART"d), r"GRU"d :

Re: What is the value for D to allow assign bool to char/dchar? For me, it must be an error.

2021-08-07 Thread jfondren via Digitalmars-d-learn
On Saturday, 7 August 2021 at 21:45:09 UTC, apz28 wrote: void main() { dchar d; d = false; d = true; char c; c = false; c = true; } true is 1 and false is 0. These are valid char and dchar values. Some people and languages are on boar

Re: How suppress (Hide) prompt command console in DMC? Like -mwindows in C++?

2021-08-07 Thread jfondren via Digitalmars-d-learn
On Sunday, 8 August 2021 at 00:23:55 UTC, Adam D Ruppe wrote: On Sunday, 8 August 2021 at 00:02:18 UTC, Marcone wrote: I create a gui program using DMC. I want to know how suppress (Hide) prompt command console in DMC? Like -mwindows in C++. Thank you. use /subsystem:windows a few more detai

Re: seeking advice: possible new @attribute to mark class' default property to avoid alias this ?

2021-08-07 Thread jfondren via Digitalmars-d-learn
On Sunday, 8 August 2021 at 04:51:48 UTC, someone wrote: On Sunday, 8 August 2021 at 04:30:12 UTC, rikki cattermole wrote: So a field that will automatically be resolved to as part of the behavior of generated toString methods. No. A default property can be another object altogether. The best

Re: Proper way to protect (lock) a struct field after initialization ??

2021-08-08 Thread jfondren via Digitalmars-d-learn
On Sunday, 8 August 2021 at 10:11:37 UTC, james.p.leblanc wrote: Hello All. Is there a standard way to protect a field of a struct after the struct has been initialized? Is this possible with a struct? If not, I suppose a class (object) would be needed? If so, are there any simple pointers to

Re: How to divide by space keeping words with spaces inside quotes?

2021-08-08 Thread jfondren via Digitalmars-d-learn
On Sunday, 8 August 2021 at 23:04:32 UTC, Marcone wrote: How to divide by space keeping words with spaces inside quotes? Exanple: string text = "Duck Cat \"Carl Rivers\" Dog"; I want split to: ["Duck", "Cat", "Carl Rivers", "Dog"] ATENTION: I DON'T WANT: ["Duck", "Cat", "Carl", "Rivers", "

Re: .tupleof for static array

2021-08-10 Thread jfondren via Digitalmars-d-learn
On Tuesday, 10 August 2021 at 12:01:24 UTC, Dennis wrote: ```D struct Vec { float x, y, z; } void setPosition(float x, float y, float z) { } void main() { Vec posS = Vec(10, 20, 30); setPosition(posS.tupleof); // pass float[3] posA = [10, 20, 30]; setPosition(posA.tupleof)

Re: Can't compile with ldc in termux

2021-08-11 Thread jfondren via Digitalmars-d-learn
On Wednesday, 11 August 2021 at 18:46:44 UTC, _ZZ_ZZ_ZZ wrote: On Wednesday, 11 August 2021 at 18:20:13 UTC, Paul Backus wrote: Maybe try compiling with `--linker=` (nothing after the `=` sign) and see if that helps? YOU ARE MY HERO!!! it works, and it's great! But in any case ... Can i confi

Re: Can't compile with ldc in termux

2021-08-11 Thread jfondren via Digitalmars-d-learn
On Wednesday, 11 August 2021 at 19:10:09 UTC, _ZZ_ZZ_ZZ wrote: On Wednesday, 11 August 2021 at 18:58:16 UTC, jfondren wrote: confirm the location of ldc2.conf with `ldc2 -v`, then edit that file. Mine was at ../usr/etc/ldc2.conf (relative to $HOME) Mine was at `/data/data/com.termux/files/usr/

Re: Can't compile with ldc in termux

2021-08-11 Thread jfondren via Digitalmars-d-learn
On Wednesday, 11 August 2021 at 19:16:25 UTC, jfondren wrote: With two dashes: ``` default: { switches = [ "-defaultlib=phobos2-ldc,druntime-ldc", "-link-defaultlib-shared=false", "--linker=", // <-- add this ]; ```

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 World!".findSplit("o")[0].w

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 other

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") == immutable(char)

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 first

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. Usi

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 `cast(char*)`

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 interfa

  1   2   3   >