Re: Using ImportC to augment a big C project with D

2024-02-21 Thread Bastiaan Veelo via Digitalmars-d-learn
On Tuesday, 20 February 2024 at 18:33:42 UTC, Carl Sturtivant wrote: 2. The C source calls exit() from C's stdlib, and D needs to terminate properly. What do you mean by "need"? You can call https://dlang.org/phobos/core_stdc_stdlib.html#.exit from D: ```d import std.stdio; void main() {

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

2024-01-16 Thread Bastiaan Veelo via Digitalmars-d-learn
On Monday, 15 January 2024 at 23:06:00 UTC, Steven Schveighoffer wrote: As a workaround, you can alias the outer function in the struct: ```d struct S { alias foo = S_foo; } ``` This might be less than ideal, but at least it works. It does! And it's good enough for me. Thanks a lot! --

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

2024-01-15 Thread Bastiaan Veelo via Digitalmars-d-learn
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 instance of the struct, but as I understand now it is static all the

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

2024-01-15 Thread Bastiaan Veelo via Digitalmars-d-learn
Hey people, I can use some help understanding why the last line produces a compile error. ```d import std.stdio; struct S { static void foo(alias len)() { writeln(len); } } void S_foo(alias len)() { writeln(len); } void main() { const five = 5; S_foo!five; //

Re: Returning a reference to be manipulated

2023-04-14 Thread Bastiaan Veelo via Digitalmars-d-learn
On Friday, 14 April 2023 at 00:50:31 UTC, kdevel wrote: ``` ref int foo (ref int i) { return i; } ref int bar () { int i; return foo (i); } void main () { import std.stdio; auto i = bar; i.writeln; } ``` Up to dmd v2.100.2 I am warned/get an error during compilation: ``` $

Re: Traverse a DList and insert / remove in place?

2023-03-25 Thread Bastiaan Veelo via Digitalmars-d-learn
On Sunday, 19 March 2023 at 13:15:58 UTC, Armando wrote: I would like to do something like traversing a DList, operating on the current element, and potentially removing that element or inserting a new one before/after it - an easy operation if you code a DList yourself. Maybe I missed

Re: toString best practices

2023-02-15 Thread Bastiaan Veelo via Digitalmars-d-learn
On Thursday, 9 February 2023 at 17:49:58 UTC, Paolo Invernizzi wrote: ``` import std.format, std.range.primitives; struct Point(T) { T x, y; void toString(W)(ref W writer, scope const ref FormatSpec!char f) const if (isOutputRange!(W, char)) { put(writer, "(");

Re: How do you work with lst files?

2022-08-25 Thread Bastiaan Veelo via Digitalmars-d-learn
On Wednesday, 24 August 2022 at 22:29:51 UTC, Christian Köstlin wrote: I want to ask around how you from the dlang community work with .lst coverage files? No personal experience, but there are half a dozen options on https://code.dlang.org/search?q=Coverage — Bastiaan.

Re: How to escape control characters?

2022-08-23 Thread Bastiaan Veelo via Digitalmars-d-learn
On Thursday, 31 March 2016 at 03:15:49 UTC, cy wrote: This might be a dumb question. How do I format a string so that all the newlines print as \n and all the tabs as \t and such? The easiest is this: ```d import std.conv; string str = `Hello "World" line 2`; writeln([str].text[2..$-2]); //

Re: Null terminated character

2022-07-02 Thread Bastiaan Veelo via Digitalmars-d-learn
On Thursday, 23 June 2022 at 16:16:26 UTC, vc wrote: I've try this '\0'*10 and didn't work, i want the results be \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 ```d string nulls = '\0'.repeat(10).array; ``` — Bastiaan.

Re: Why allow initializers of non-static members that allocate?

2022-06-11 Thread Bastiaan Veelo via Digitalmars-d-learn
On Saturday, 11 June 2022 at 10:52:58 UTC, Mike Parker wrote: I agree with your initial assessment that it should be an error. It really only makes sense to allow the dynamic allocation if the fields are immutable and, in the case of arrays, the initializer is a literal. 

Re: Why allow initializers of non-static members that allocate?

2022-06-11 Thread Bastiaan Veelo via Digitalmars-d-learn
On Saturday, 11 June 2022 at 01:52:58 UTC, Mike Parker wrote: People getting bit by `new` in field initialization often enough that I think a warning would be helpful. The problem is so much bigger because it is not just a case of being aware not to use `new` in member initialisers. As you

Re: Why allow initializers of non-static members that allocate?

2022-06-10 Thread Bastiaan Veelo via Digitalmars-d-learn
On Friday, 10 June 2022 at 14:56:24 UTC, Steven Schveighoffer wrote: On 6/10/22 3:46 AM, Mike Parker wrote: I think this is a case where having a warning that's on by default, and which can be explicitly disabled, is useful. "Blah blah .init blah blah. See link-to-something-in-docs. Is this

Re: Why allow initializers of non-static members that allocate?

2022-06-10 Thread Bastiaan Veelo via Digitalmars-d-learn
On Friday, 10 June 2022 at 07:49:43 UTC, Mike Parker wrote: And it *is* documented: Struct fields are by default initialized to whatever the Initializer for the field is, and if none is supplied, to the default initializer for the field's type. The default initializers are evaluated at

Re: Why allow initializers of non-static members that allocate?

2022-06-10 Thread Bastiaan Veelo via Digitalmars-d-learn
On Friday, 10 June 2022 at 07:46:36 UTC, Mike Parker wrote: On Friday, 10 June 2022 at 07:35:17 UTC, Bastiaan Veelo wrote: Is there a use case where this makes sense? I would have much appreciated the compiler slapping me on the fingers, but it doesn't. I understand that it is safe and that

Why allow initializers of non-static members that allocate?

2022-06-10 Thread Bastiaan Veelo via Digitalmars-d-learn
I have been foolish enough to make a mistake like this: ```d struct S { int[] arr = new int[](5); } ``` This is terrible because ```d S s1; S s2; s2.arr[0] = 42; writeln(s1.arr[0]); // 42 Gotcha! ``` Of course there are less obvious variants of the same mistake: ```d import std; struct S {

Re: Library for image editing and text insertion

2022-04-27 Thread Bastiaan Veelo via Digitalmars-d-learn
On Wednesday, 27 April 2022 at 09:27:24 UTC, Alexander Zhirov wrote: Now I would like to reduce the size of the executable file and it would be great at all! Try the `-release` option to `dmd`. Or use LDC. -- Bastiaan.

Re: Language server

2022-04-27 Thread Bastiaan Veelo via Digitalmars-d-learn
On Tuesday, 26 April 2022 at 18:15:57 UTC, Alain De Vos wrote: In a perfect world there would be someone uploading a youtube video how to implement neovim with a dlang language-server. With function-completions-help where hints are given about the functions and libraries. If anyone could do

Re: How to use Vector Extensions in an opBinary

2022-04-21 Thread Bastiaan Veelo via Digitalmars-d-learn
On Thursday, 21 April 2022 at 15:31:04 UTC, HuskyNator wrote: On Sunday, 17 April 2022 at 17:04:57 UTC, Bastiaan Veelo wrote: You might want to have a look at https://code.dlang.org/packages/intel-intrinsics — Bastiaan. This does not discuss core.simd or __vector type, or did I

Re: Can Enums be integral types?

2022-04-19 Thread Bastiaan Veelo via Digitalmars-d-learn
On Tuesday, 19 April 2022 at 01:25:13 UTC, Era Scarecrow wrote: The 'integral' or numeric value is used for uniqueness, […] There is nothing that requires enum values to be unique, though: ```d import std; void main() { enum E {Zero = 0, One = 0, Two = 0} writeln(E.Two); // Zero! } ```

Re: Can Enums be integral types?

2022-04-17 Thread Bastiaan Veelo via Digitalmars-d-learn
On Saturday, 16 April 2022 at 11:39:01 UTC, Manfred Nowak wrote: In the specs(17) about enums the word "integral" has no match. But because the default basetype is `int`, which is an integral type, enums might be integral types whenever their basetype is an integral type. On the other hand

Re: How to use Vector Extensions in an opBinary

2022-04-17 Thread Bastiaan Veelo via Digitalmars-d-learn
On Sunday, 17 April 2022 at 11:16:25 UTC, HuskyNator wrote: I recently found out there is [support for vector extensions](https://dlang.org/spec/simd.html) But I have found I don't really understand how to use it, not even mentioning the more complex stuff. I couldn't find any good examples

Re: package libs on windows

2022-02-01 Thread Bastiaan Veelo via Digitalmars-d-learn
On Tuesday, 1 February 2022 at 21:17:09 UTC, Abby wrote: I would like to know if there is a way to set path to lib to downloaded with package instead of harcoded. That’s documented on the [package page](https://code.dlang.org/packages/d2sqlite3). Are you trying to link with a separately

Re: std.signals: Why emit() not extist?

2021-12-30 Thread Bastiaan Veelo via Digitalmars-d-learn
On Thursday, 30 December 2021 at 19:13:10 UTC, Marcone wrote: I get this error: Error: undefined identifier `emit`, did you mean function `exit`? Did you `import std.signals`? — Bastiaan.

Re: First time using Parallel

2021-12-26 Thread Bastiaan Veelo via Digitalmars-d-learn
On Sunday, 26 December 2021 at 15:20:09 UTC, Bastiaan Veelo wrote: So if you use `workerLocalStorage` to give each thread an `appender!string` to write output to, and afterwards write those to `stdout`, you'll get your output in order without sorting. Scratch that, I misunderstood the

Re: First time using Parallel

2021-12-26 Thread Bastiaan Veelo via Digitalmars-d-learn
On Sunday, 26 December 2021 at 06:10:03 UTC, Era Scarecrow wrote: [...] ```d foreach(value; taskPool.parallel(range) ){code} ``` [...] Now said results are out of order [...] So I suppose, is there anything I need to know? About shared resources or how to wait until all threads are

Re: Why does is the RandomAccessInfinite interface not a valid RandomAccessRange?

2021-12-19 Thread Bastiaan Veelo via Digitalmars-d-learn
On Sunday, 19 December 2021 at 09:19:31 UTC, D Lark wrote: Do you know if there's a nightly version I can specify to use your fix? Are you inheriting from `RandomAccessInfinite`? Then you can probably add ```d static if (__VERSION__ < 2099) enum bool empty = false; ``` to make it work.

Re: DMD32 D Compiler v2.097.2-dirty ?

2021-09-08 Thread Bastiaan Veelo via Digitalmars-d-learn
On Monday, 6 September 2021 at 15:37:31 UTC, Paul wrote: I like to write CLEAN code:) Why does my DMD installation say v2.097.2-dirty? https://forum.dlang.org/post/qqxmnoshytmzflviw...@forum.dlang.org I suppose it is due to how the scripts work that produce the compiler release. I guess

Re: Curious effect with traits, meta, and a foreach loop ... mystifies me.

2021-09-08 Thread Bastiaan Veelo via Digitalmars-d-learn
On Tuesday, 7 September 2021 at 17:24:34 UTC, james.p.leblanc wrote: ```d /*…*/ // this is fine (notice that 'val' is never used foreach( i, val ; u.tupleof ){ ptr = u.tupleof[i].x.ptr; writeln("ptr: ", ptr); } // this fails with: "Error: variable 'i' cannot be read at

Re: implimenting interface function by inheriting from other class

2021-08-21 Thread Bastiaan Veelo via Digitalmars-d-learn
On Saturday, 21 August 2021 at 20:35:43 UTC, Alexey wrote: Hello ```D interface Int { void coolFunc(); } class C1 { void coolFunc() { return; } } class C2 : C1, Int { } void main() { auto c = new C2; } ``` dmd says it's not Ok: t.d(14): Error: class `t.C2`

Re: simple (I think) eponymous template question ... what is proper idimatic way ?

2021-08-17 Thread Bastiaan Veelo via Digitalmars-d-learn
On Tuesday, 17 August 2021 at 20:29:51 UTC, james.p.leblanc wrote: So, below is my code: import std.stdio; import std.meta : AliasSeq; template isAmong(T, S...) { static if (S.length == 0) enum isAmong = false; else enum isAmong = is(T == S) || isAmong(T, S[1..$]); } alias

Re: Getting a working example of opIndexAssign using opSlice ... have troubles ...

2021-08-15 Thread Bastiaan Veelo via Digitalmars-d-learn
On Sunday, 15 August 2021 at 20:41:51 UTC, james.p.leblanc wrote: struct A { int opIndexAssign(int v); // overloads a[] = v int opIndexAssign(int v, size_t[2] x); // overloads a[i .. j] = v int[2] opSlice(size_t x, size_t y); // overloads i .. j }

Re: D has the same memory model as C++

2021-08-11 Thread Bastiaan Veelo via Digitalmars-d-learn
On Wednesday, 11 August 2021 at 05:33:06 UTC, Tejas wrote: On Tuesday, 10 August 2021 at 21:19:39 UTC, Bastiaan Veelo wrote: On Tuesday, 10 August 2021 at 16:00:37 UTC, Tejas wrote: Basically, what are the subtle gotcha's in the differences between C++ and D code that looks similar The only

Re: D has the same memory model as C++

2021-08-10 Thread Bastiaan Veelo via Digitalmars-d-learn
On Tuesday, 10 August 2021 at 18:13:17 UTC, Tejas wrote: On Tuesday, 10 August 2021 at 18:07:35 UTC, Bastiaan Veelo wrote: On Tuesday, 10 August 2021 at 16:00:37 UTC, Tejas wrote: there's casting away const, a clearly seperate language feature which has no equivalent in D; You *can* cast

Re: D has the same memory model as C++

2021-08-10 Thread Bastiaan Veelo via Digitalmars-d-learn
On Tuesday, 10 August 2021 at 16:00:37 UTC, Tejas wrote: Basically, what are the subtle gotcha's in the differences between C++ and D code that looks similar The only gotcha that comes to my mind is that `private` means private to the module in D, not private to the aggregate. — Bastiaan.

Re: D has the same memory model as C++

2021-08-10 Thread Bastiaan Veelo via Digitalmars-d-learn
On Tuesday, 10 August 2021 at 16:00:37 UTC, Tejas wrote: there's casting away const, a clearly seperate language feature which has no equivalent in D; You *can* cast away `const` in D: https://run.dlang.io/is/sWa5Mf — Bastiaan.

Re: Error when compile with DMD using -m64?

2021-08-10 Thread Bastiaan Veelo via Digitalmars-d-learn
On Tuesday, 10 August 2021 at 17:13:31 UTC, Marcone wrote: On Tuesday, 10 August 2021 at 15:55:42 UTC, Bastiaan Veelo wrote: Use `size_t` and `ptrdiff_t` instead to make your program compile in both 32 bit and 64 bit modes. https://dlang.org/spec/type.html#aliased-types -- Bastiaan. Thank

Re: Error when compile with DMD using -m64?

2021-08-10 Thread Bastiaan Veelo via Digitalmars-d-learn
On Tuesday, 10 August 2021 at 01:29:04 UTC, Marcone wrote: Solved converting long and int. Use `size_t` and `ptrdiff_t` instead to make your program compile in both 32 bit and 64 bit modes. https://dlang.org/spec/type.html#aliased-types -- Bastiaan.

Re: How Add Local modules mymodule.d using DUB?

2021-08-09 Thread Bastiaan Veelo via Digitalmars-d-learn
On Monday, 9 August 2021 at 16:32:13 UTC, Marcone wrote: My main program need import a local module called mymodule.d. How can I add this module using DUB? Thank you. Let’s assume you just created a dub project in `myproject` with `dub init`. Place `mymodule.d` alongside `app.d` in

Re: writef, compile-checked format, pointer

2021-08-09 Thread Bastiaan Veelo via Digitalmars-d-learn
On Monday, 9 August 2021 at 22:01:18 UTC, Patrick Schluter wrote: On Monday, 9 August 2021 at 19:38:28 UTC, novice2 wrote: format!"fmt"() and writef!"fmt"() templates with compile-time checked format string not accept %X for pointers, but format() and writef() accept it

Re: Exit before second main with -funittest

2021-07-30 Thread Bastiaan Veelo via Digitalmars-d-learn
On Friday, 30 July 2021 at 05:51:41 UTC, Brian Tiffin wrote: [... interesting account of the D experience ...] **Kudos team and contributors.** Can't really suggest that many improvements to resources needed for learning D, as a hobbyist not on a clock, being new still and low enough to not

Re: how to make D program footprint smaller ?

2021-07-10 Thread Bastiaan Veelo via Digitalmars-d-learn
On Friday, 9 July 2021 at 03:07:04 UTC, dangbinghoo wrote: as questioned in the previous thread, I need to find out something like `--as-needed` options available for D. You are probably looking for the [-i](https://dlang.org/dmd-osx.html#switch-i%5B) compiler option. As far as I know `dub`

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

2021-07-09 Thread Bastiaan Veelo via Digitalmars-d-learn
On Friday, 9 July 2021 at 21:13:02 UTC, rempas wrote: On Friday, 9 July 2021 at 20:54:21 UTC, Paul Backus wrote: On Friday, 9 July 2021 at 20:43:48 UTC, rempas wrote: I'm reading the library reference for [core.time](https://dlang.org/phobos/core_time.html#Duration) and It says that the

Re: Is there an alias for standard libraries to use in import statement?

2021-07-04 Thread Bastiaan Veelo via Digitalmars-d-learn
On Sunday, 4 July 2021 at 07:40:44 UTC, BoQsc wrote: I just started with a fresh look at the D language and would like to be able to rewrite this code: import std; void main() { writeln("Hello D"); } Into more readable standard library name: import system; void main() {

Re: Printing Tuple!(...)[] using for loop?

2021-07-02 Thread Bastiaan Veelo via Digitalmars-d-learn
On Friday, 2 July 2021 at 04:21:24 UTC, Kirill wrote: I have a `Tuple!(string, ..., string)[] data` If there are only strings in the tuple, it could be simplified by making it a static array of strings instead. The compile-time index issue would go away. —Bastiaan

Re: How to call stop from parallel foreach

2021-06-24 Thread Bastiaan Veelo via Digitalmars-d-learn
On Thursday, 24 June 2021 at 20:56:26 UTC, Ali Çehreli wrote: On 6/24/21 1:33 PM, Bastiaan Veelo wrote: > distributes the load across all cores (but one). Last time I checked, the current thread would run tasks as well. Ali Indeed, thanks. — Bastiaan.

Re: How to call stop from parallel foreach

2021-06-24 Thread Bastiaan Veelo via Digitalmars-d-learn
On Thursday, 24 June 2021 at 21:05:28 UTC, Bastiaan Veelo wrote: On Thursday, 24 June 2021 at 20:41:40 UTC, seany wrote: Is there any way to control the number of CPU cores used in parallelization ? E.g : take 3 cores for the first parallel foreach - and then for the second one, take 3 cores

Re: How to call stop from parallel foreach

2021-06-24 Thread Bastiaan Veelo via Digitalmars-d-learn
On Thursday, 24 June 2021 at 20:41:40 UTC, seany wrote: On Thursday, 24 June 2021 at 20:33:00 UTC, Bastiaan Veelo wrote: By the way, nesting parallel `foreach` does not make much sense, as one level already distributes the load across all cores (but one). Additional parallelisation will

Re: How to call stop from parallel foreach

2021-06-24 Thread Bastiaan Veelo via Digitalmars-d-learn
On Thursday, 24 June 2021 at 18:23:01 UTC, seany wrote: I have seen [this](https://forum.dlang.org/thread/akhbvvjgeaspmjntz...@forum.dlang.org). I can't call break form parallel foreach. Okey, Is there a way to easily call .stop() from such a case? Yes there is, but it won’t break the

Re: Financial Library

2021-06-13 Thread Bastiaan Veelo via Digitalmars-d-learn
On Sunday, 13 June 2021 at 12:46:29 UTC, Financial Wiz wrote: What are some of the best Financial Libraries for D? I would like to be able to aggregate as much accurate information as possible. Thanks. I am not into financials, but these libs show up in a search:

Re: Inclusion of Parenthesis on Certain Functions

2021-06-13 Thread Bastiaan Veelo via Digitalmars-d-learn
On Sunday, 13 June 2021 at 15:45:53 UTC, Justin Choi wrote: I've tried looking through the documentation but can't find an explanation for why you can use it without parenthesis. https://dlang.org/spec/function.html#optional-parenthesis (Some exceptions regarding delegates and function

Re: coreutils with D trials, wc, binary vs well formed utf

2021-05-24 Thread Bastiaan Veelo via Digitalmars-d-learn
On Monday, 24 May 2021 at 16:58:33 UTC, btiffin wrote: [...] Just bumped into https://dlang.org/blog/2020/01/28/wc-in-d-712-characters-without-a-single-branch/ [...] Is there a(n easy-ish) way to fix up that wc.d source in the blog to fallback to byte stream mode when a utf-8 reader fails

Re: Struct initialization extra comma - should it compile

2021-04-25 Thread Bastiaan Veelo via Digitalmars-d-learn
On Sunday, 25 April 2021 at 13:39:54 UTC, JN wrote: struct Foo { int x, y, z; } void main() { Foo bar = Foo(1,); } This compiles without syntax errors, is this expected? Yes, the

Re: When should I use SortedRange.release?

2021-04-23 Thread Bastiaan Veelo via Digitalmars-d-learn
On Friday, 23 April 2021 at 21:34:39 UTC, Steven Schveighoffer wrote: `SortedRange` itself is kind of a kludge of "policy" that isn't fit for function. I use release to get the original data type out (via r.save.release), but that's about it. See my rant about it

Re: When should I use SortedRange.release?

2021-04-23 Thread Bastiaan Veelo via Digitalmars-d-learn
On Friday, 23 April 2021 at 18:35:25 UTC, Paul Backus wrote: On Friday, 23 April 2021 at 17:35:13 UTC, Bastiaan Veelo wrote: What happens when a range is released? What happens if a range is not released? What happens if a range is released more than once? And what does "controlled" imply

When should I use SortedRange.release?

2021-04-23 Thread Bastiaan Veelo via Digitalmars-d-learn
For reference, `SortedRange.release` is [documented](https://dlang.org/phobos/std_range.html#.SortedRange) as such: "Releases the controlled range and returns it." Wow thanks! I love functions that are named exactly as what they do ;-) Seriously though, I still don't know what it is that it

Re: Range Error

2021-04-11 Thread Bastiaan Veelo via Digitalmars-d-learn
On Sunday, 11 April 2021 at 19:45:30 UTC, Ruby The Roobster wrote: What am I doing wrong here? Is it the 'for' loop? Yes, there is a `7` where there should be an `i` on this line: ```d for(int i=7;7>=0;i--) ``` This will go on forever, so you get a range error as soon as `i < 0`.

Re: Example for Mir-Random fails

2021-04-03 Thread Bastiaan Veelo via Digitalmars-d-learn
On Saturday, 3 April 2021 at 19:02:34 UTC, Brad wrote: I just do not know enough about the D libraries to figure out what is wrong. I know it is a case of type mismatch. The example appears on the Mir-Random page as listed under DUB: https://code.dlang.org/packages/mir-random [...] I

Re: C++/D class interop example crashes

2021-03-27 Thread Bastiaan Veelo via Digitalmars-d-learn
On Saturday, 27 March 2021 at 15:09:20 UTC, Jan wrote: I just tried to get this example to work: https://dlang.org/spec/cpp_interface.html#using_d_classes_from_cpp It kept crashing for me with a 'privileged instruction' error when the function 'bar' was executed. Finally I removed the call to

Re: Contributing CDF bindings to Deimos

2021-03-25 Thread Bastiaan Veelo via Digitalmars-d-learn
On Thursday, 25 March 2021 at 04:00:33 UTC, Chris Piker wrote: As an aside, software developers at NASA Goddard have now heard of D which is nice. They were pleased to see that it was supported by gcc. (Hat tip to the GDC team) That’s cool. I’d love to see NASA on

Re: Why are enums with base type string not considered strings?

2021-03-14 Thread Bastiaan Veelo via Digitalmars-d-learn
On Sunday, 14 March 2021 at 16:09:39 UTC, Imperatorn wrote: On Sunday, 14 March 2021 at 10:42:17 UTC, wolframw wrote: enum BoolEnum : bool { TestBool = false } enum CharEnum : char { TestChar = 'A' } enum StringEnum : string { TestString = "Hello" } pragma(msg, isBoolean!BoolEnum);

Re: Dlang spec

2021-03-13 Thread Bastiaan Veelo via Digitalmars-d-learn
On Thursday, 11 March 2021 at 19:38:01 UTC, Imperatorn wrote: I created some PDFs (on request) of the dlang spec mobi-file and uploaded them here: https://gofile.io/d/ijctZt Different converters were used, hence multiple files. Maybe someone can upload a good version on dlang.org and link to

Re: D's Continous Changing

2021-03-04 Thread Bastiaan Veelo via Digitalmars-d-learn
On Wednesday, 3 March 2021 at 23:30:20 UTC, harakim wrote: Contrast to me trying to figure out how to format a number in binary. format!"%b"(number) does not work but is very similar to what is suggested in the documentation. I was able to figure out it's format("%b", number) but it took a few

Re: D's Continous Changing

2021-03-04 Thread Bastiaan Veelo via Digitalmars-d-learn
On Wednesday, 3 March 2021 at 23:30:20 UTC, harakim wrote: Every time I come back to a D program I wrote over a year ago, it seems like there are numerous breaking changes and it takes me a while to get it to compile again. I am porting a large code base from Extended Pascal to D and I know

Re: Minimize GC memory footprint

2021-02-05 Thread Bastiaan Veelo via Digitalmars-d-learn
On Wednesday, 3 February 2021 at 13:37:42 UTC, frame wrote: I have to deal with GC as long I want to use other libraries that are relying on it or even just phobos. Conclusion so far (for Windows): 32bit: - GC just doesn't work at all ?? Do you mean no collections happen? 32bit GC should

Re: Using the Standard Library with C++ Interop

2021-02-05 Thread Bastiaan Veelo via Digitalmars-d-learn
On Friday, 5 February 2021 at 21:40:29 UTC, wolfiesnotfine wrote: In any case, I'm unsure how I would runtime init from C++. Is there a specific function I should call? https://dlang.org/phobos/core_runtime.html#.rt_init Could this be done at compile time in a consteval or constexpr

Re: writeln and write at CTFE

2021-01-13 Thread Bastiaan Veelo via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 09:11:53 UTC, Guillaume Piolat wrote: On Wednesday, 13 January 2021 at 08:35:09 UTC, Andrey wrote: Hello all, Tell me please how can I "writeln" and "write" in function that is used in CTFE? At the moment I get this: import\std\stdio.d(4952,5): Error: variable

Re: Using a betterC dub package in ordinary D

2021-01-08 Thread Bastiaan Veelo via Digitalmars-d-learn
On Friday, 8 January 2021 at 18:28:36 UTC, Ferhat Kurtulmuş wrote: On Friday, 8 January 2021 at 15:40:12 UTC, Bastiaan Veelo wrote: Hi, When I use earcutd [1] in an ordinary D project, I get a link error for the __D7earcutd12__ModuleInfoZ symbol. [...] Dear Bastiaan, I am not an expert in

Using a betterC dub package in ordinary D

2021-01-08 Thread Bastiaan Veelo via Digitalmars-d-learn
Hi, When I use earcutd [1] in an ordinary D project, I get a link error for the __D7earcutd12__ModuleInfoZ symbol. This is because the earcutd dub.json has `"dflags": ["-betterC"]`. I think this is in error, my understanding of betterC code is that it can be compiled with "-betterC", but

Re: Writing a really fast lexer

2020-12-12 Thread Bastiaan Veelo via Digitalmars-d-learn
On Saturday, 12 December 2020 at 18:15:11 UTC, vnr wrote: On Saturday, 12 December 2020 at 16:43:43 UTC, Bastiaan Veelo wrote: Have you looked at Pegged [1]? It will give you the lexer and parser in one go. I'd be very interested to see how it performs on that kind of input. -- Bastiaan.

Re: Writing a really fast lexer

2020-12-12 Thread Bastiaan Veelo via Digitalmars-d-learn
On Friday, 11 December 2020 at 19:49:12 UTC, vnr wrote: For a project with good performance, I would need to be able to analyse text. To do so, I would write a parser by hand using the recursive descent algorithm, based on a stream of tokens. I started writing a lexer with the d-lex package

Re: Pass enum variable as const ref arg

2020-12-04 Thread Bastiaan Veelo via Digitalmars-d-learn
On Friday, 4 December 2020 at 12:54:25 UTC, Andrey wrote: Hello, void test(const ref string[3] qazzz) { qazzz.writeln; } void main() { enum string[3] value = ["qwer", "ggg", "v"]; test(value); } Gives errors: It works if you pass `-preview=rvaluerefparam` to the compiler. But the

Re: Is garbage detection a thing?

2020-11-29 Thread Bastiaan Veelo via Digitalmars-d-learn
On Sunday, 29 November 2020 at 16:05:04 UTC, Mark wrote: Hi, can I ask you something in general? I don't know anyone whom I could ask. I'm a hobbyist with no science degree or job in computing, and also know no other programmers. I have no good understanding why "garbage collection" is a

Re: Can't pass [] to extern function object method

2020-11-18 Thread Bastiaan Veelo via Digitalmars-d-learn
On Wednesday, 18 November 2020 at 10:50:12 UTC, frame wrote: I found the "bug". It was caused by a debug {} statement within a struct method. I assume that the debug symbol is just incompatible called from the DLL context. Were the DLL and main program built in different modes

Re: How can execute method in new Thread?

2020-11-15 Thread Bastiaan Veelo via Digitalmars-d-learn
On Saturday, 14 November 2020 at 17:21:15 UTC, Marcone wrote: Error: D:\dmd2\windows\bin\..\..\src\phobos\std\parallelism.d(516): Error: struct `Fruit` does not overload () I think you need to pass the this pointer somehow. This works: import std; struct Fruit { string name;

Re: App hangs, GC.collect() fixet it. Why?

2020-09-29 Thread Bastiaan Veelo via Digitalmars-d-learn
On Monday, 28 September 2020 at 21:58:31 UTC, Steven Schveighoffer wrote: On 9/28/20 3:28 PM, Bastiaan Veelo wrote: I’m leaning towards ditching the memory mapped I/O on the D end, and replace it by regular serialisation/deserialisation. That will be a manual rewrite though, which is a bit of

Re: App hangs, GC.collect() fixet it. Why?

2020-09-28 Thread Bastiaan Veelo via Digitalmars-d-learn
On Monday, 28 September 2020 at 15:44:44 UTC, Steven Schveighoffer wrote: On 9/28/20 8:57 AM, Bastiaan Veelo wrote: I am glad to have found the cause of the breakage finally, but it won't be easy to find a generic solution... Obviously, this isn't a real piece of code, but there is no way

Re: App hangs, GC.collect() fixet it. Why?

2020-09-28 Thread Bastiaan Veelo via Digitalmars-d-learn
On Friday, 5 June 2020 at 21:20:09 UTC, Steven Schveighoffer wrote: This kind of sounds like a codegen bug, a race condition, or (worst case) memory corruption. I think it must have been memory corruption: I had not realized that our old Pascal compiler aligns struct members on one byte

Re: Why Pegged action dont not work in this case ?

2020-06-11 Thread Bastiaan Veelo via Digitalmars-d-learn
On Sunday, 19 April 2020 at 16:47:06 UTC, Basile B. wrote: I 've started experimenting Pegged action. Quickly i got blocked by this problem. The start action works where I use the rule but not directly in the rule. I don't understand the difference between how you use "where" and "directly

App hangs, GC.collect() fixet it. Why?

2020-06-05 Thread Bastiaan Veelo via Digitalmars-d-learn
I've been tracking down a hang in our pilot app. Using writeln, it appears to hang at newing a slice. After many hours of trying things, I discovered that program flow would continue past that point when I inserted a call to `GC.collect()` just before. Then it stalled again at a call to Win32

Re: Postblit segfault.

2020-06-01 Thread Bastiaan Veelo via Digitalmars-d-learn
On Monday, 1 June 2020 at 09:42:44 UTC, Boris Carvajal wrote: On Monday, 1 June 2020 at 06:35:36 UTC, MaoKo wrote: Hello, I don't understand why this code segfault on Reduced to: import std.stdio; struct S {} void main() { S[1] s; writeln(s); } This used to work up to dmd 2.084.1. It

Re: CT BitArray

2020-04-02 Thread Bastiaan Veelo via Digitalmars-d-learn
On Thursday, 1 November 2018 at 08:50:38 UTC, Bastiaan Veelo wrote: On Thursday, 1 November 2018 at 00:01:04 UTC, Stefan Koch wrote: On Wednesday, 31 October 2018 at 23:14:08 UTC, Bastiaan Veelo wrote: Currently, BitArray is not usable at compile time, so you cannot do ``` enum e =

Re: New with alias

2020-03-10 Thread Bastiaan Veelo via Digitalmars-d-learn
On Tuesday, 10 March 2020 at 06:09:23 UTC, tcak wrote: I write a code as below: auto result = new char[4]; It allocates memory as expected. This is a slice of four chars, which can be used as a dynamic array. Later I define an alias and do the above step: alias Pattern = char[4]; This

Re: Specify dmd or ldc compiler and version in a json dub file?

2020-01-20 Thread Bastiaan Veelo via Digitalmars-d-learn
On Tuesday, 8 August 2017 at 09:17:02 UTC, data pulverizer wrote: I would like to know how to specify dmd or ldc compiler and version in a json dub file. Update: you can at least specify these in the toolchain requirements section:

Re: Slice/Substr [0..?lastIndexOf(".")] How refer itself without create a variable?

2019-12-05 Thread Bastiaan Veelo via Digitalmars-d-learn
On Thursday, 5 December 2019 at 11:28:51 UTC, Marcone wrote: Simple example: writeln("Hi\nHow are you?\nGood".splitLines()[0][0..?lastIndexOf(r"\")]); How to refer to this string in lastIndexOf() without create a variable? Thank you. .splitLines[0] already just produces "Hi", containing

Re: const and immutable values, D vs C++?

2019-12-04 Thread Bastiaan Veelo via Digitalmars-d-learn
On Wednesday, 4 December 2019 at 14:44:43 UTC, Ola Fosheim Grøstad wrote: When is there a noticable difference when using const values instead of immutable values in a function body? And when should immutable be used instead of const? f(){ const x = g(); immutable y = g(); ... do stuff

Re: Unexpected aliasing

2019-11-12 Thread Bastiaan Veelo via Digitalmars-d-learn
On Tuesday, 12 November 2019 at 08:15:20 UTC, Basile B. wrote: I'm curious to know what is the equivalent in Pascal that your transpiler fails to translate since Pascal records don't have constructors at all. Maybe you used an old school 'Object' ? Note that Extended Pascal is not exactly

Re: Unexpected aliasing

2019-11-12 Thread Bastiaan Veelo via Digitalmars-d-learn
On Monday, 11 November 2019 at 21:52:12 UTC, Jonathan M Davis wrote: On Monday, November 11, 2019 12:17:37 PM MST Bastiaan Veelo via Digitalmars- d-learn wrote: [...] I could use some help in rewriting the code below so that arr1 and arr2 each have their own data; ideally with minimal

Re: Unexpected aliasing

2019-11-12 Thread Bastiaan Veelo via Digitalmars-d-learn
On Monday, 11 November 2019 at 20:05:11 UTC, Antonio Corbi wrote: Defining and using a constructor for WrapIntegerArray seems to work: void main() { import std.stdio; WrapIntegerArray arr1 = WrapIntegerArray(5); arr1[0] = 42; WrapIntegerArray arr2 =

Unexpected aliasing

2019-11-11 Thread Bastiaan Veelo via Digitalmars-d-learn
Recently I got my first surprise with our use of D. The symptom was that two local variables in two different functions appeared to be sharing data. A simplified example is shown below (the original was machine translated from Pascal and involved templates and various levels of indirection).

Re: Saving and loading large data sets easily and efficiently

2019-10-03 Thread Bastiaan Veelo via Digitalmars-d-learn
On Monday, 30 September 2019 at 20:10:21 UTC, Brett wrote: [...] The way the data is structured is that I have a master array of non-ptr structs. E.g., S[] Data; S*[] OtherStuff; then every pointer points to an element in to Data. I did not use int's as "pointers" for a specific

Re: How to use #pragma omp parallel for collapse(n) in dlang?

2019-08-15 Thread Bastiaan Veelo via Digitalmars-d-learn
On Tuesday, 13 August 2019 at 08:41:07 UTC, ijet wrote: How to use #pragma omp parallel for collapse(n) in dlang? I don’t understand the question. Bastiaan.

Re: 1 new

2019-08-03 Thread Bastiaan Veelo via Digitalmars-d-learn
On Friday, 2 August 2019 at 18:25:28 UTC, jmh530 wrote: When I navigate to https://forum.dlang.org/ I have a message that says "1 new reply" to "your posts." Normally, I click on that "1 new reply" and find the post that's new, go to it, and the message disappears. However, it doesn't seem to

Re: How to get name of my application (project)

2019-08-03 Thread Bastiaan Veelo via Digitalmars-d-learn
On Saturday, 3 August 2019 at 09:26:03 UTC, Andrey wrote: Hello, how to get name of my application (project) that we write in dub.json? Is there any compile-time constant like __MODULE__? The name of an application is not a compile time constant: you can rename the executable at any time.

Re: Help me decide D or C

2019-08-02 Thread Bastiaan Veelo via Digitalmars-d-learn
On Friday, 2 August 2019 at 13:45:17 UTC, Alexandre wrote: On Friday, 2 August 2019 at 12:30:44 UTC, berni wrote: On Wednesday, 31 July 2019 at 18:38:02 UTC, Alexandre wrote: [...] In my oppinion C should have been deprecated about 50 years ago and it's not worth while to learn it if you

Re: Help me decide D or C

2019-08-02 Thread Bastiaan Veelo via Digitalmars-d-learn
On Thursday, 1 August 2019 at 20:02:08 UTC, Aurélien Plazzotta wrote: [...] But don't fool yourself, D is not for beginners. Ali Çehreli is a very skilled programmer, ergo, he can't reason like a new/starting programmer anymore, regardless of his patience and kindness. I am sorry, but this

Re: 1 - 17 ms, 553 ╬╝s, and 1 hnsec

2019-05-17 Thread Bastiaan Veelo via Digitalmars-d-learn
On Friday, 17 May 2019 at 18:36:00 UTC, ag0aep6g wrote: I'd suggest "17 ms, and 553.1µs" for a better default (1 hns is 0.1 µs, right?). No weird "hnsecs", no false precision, still all the data that is there. I was going to propose the same. Hns is weird. Bastiaan.

Re: Windows / redirect STDERR to see assert messages

2019-05-14 Thread Bastiaan Veelo via Digitalmars-d-learn
On Sunday, 12 May 2019 at 13:39:15 UTC, Robert M. Münch wrote: When developing Windows GUI applications I use: // detach from console and attach to a new one, works for x86 and x86_64 FreeConsole(); AllocConsole(); freopen("CONIN$", "r", stdin); freopen("CONOUT$",

Re: CTFE in imported static initializers

2019-05-14 Thread Bastiaan Veelo via Digitalmars-d-learn
On Monday, 13 May 2019 at 20:39:57 UTC, Steven Schveighoffer wrote: Why? I can't even use it at compile time... pragma(msg, moddata.length); Is that a good test or "usable at compile time", though? Isn't pragma(msg) done at an earlier stage than CTFE? I think that was the argument for

Re: Compile time mapping

2019-05-12 Thread Bastiaan Veelo via Digitalmars-d-learn
On Sunday, 12 May 2019 at 18:47:20 UTC, Bogdan wrote: On Sunday, 12 May 2019 at 17:53:56 UTC, Bastiaan Veelo wrote: If I understand your question correctly, you have two enums of equal length, and you want to convert members across enums according to their position, right? My question was

  1   2   3   >