Re: Explain function syntax

2025-09-21 Thread user1234 via Digitalmars-d-learn
On Monday, 22 September 2025 at 00:27:09 UTC, Steven Schveighoffer wrote: On Sunday, 21 September 2025 at 20:33:11 UTC, user1234 wrote: On Saturday, 20 September 2025 at 02:36:47 UTC, Steven Schveighoffer wrote: Looking at historical compilers, the `alias ... =` syntax was added in 2.087.0. B

Re: Explain function syntax

2025-09-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On Sunday, 21 September 2025 at 20:33:11 UTC, user1234 wrote: On Saturday, 20 September 2025 at 02:36:47 UTC, Steven Schveighoffer wrote: What is a function type? It's the internal type that the compiler has for a function, which you actually cannot express in syntax. Actually D has a syntax

Re: Explain function syntax

2025-09-21 Thread user1234 via Digitalmars-d-learn
On Saturday, 20 September 2025 at 02:36:47 UTC, Steven Schveighoffer wrote: What is a function type? It's the internal type that the compiler has for a function, which you actually cannot express in syntax. Actually D has a syntax to expression function types: ```d alias FT = void(int); void

Re: Explain function syntax

2025-09-20 Thread Ali Çehreli via Digitalmars-d-learn
On 9/18/25 10:18 PM, Steven Schveighoffer wrote: > On Thursday, 18 September 2025 at 18:10:13 UTC, Ali Çehreli wrote: >> // Not a delegate: >> static assert(is (typeof(twice) == function)); > You are mistaking the is expression for a function test with the > function pointer type. I dis

Re: Microsoft chose Go instead of C# or Rust to rewrite TypeScript

2025-09-20 Thread drug007 via Digitalmars-d-learn
On 08.09.2025 22:55, Neto wrote: On Monday, 8 September 2025 at 16:51:09 UTC, Serg Gini wrote: And not sure if ecosystem was a significant weight in the decision. Why isn't D production ready? I've been trying to figure it out for a long time. As long as I've known this person in D communi

Re: Discuss: Classes are well supported in D, with Design by Contracts. Shouldn't we take advantage of that?

2025-09-20 Thread Dejan Lekic via Digitalmars-d-learn
On Saturday, 13 September 2025 at 00:43:38 UTC, Brother Bill wrote: I'm not clear about why 'class'es are on the 'avoid' list. They are on some peoples' avoiding list. It does not mean it should be on yours. I can tell you one thing with 100% certainty - if D had no classes I would not be u

Re: Microsoft chose Go instead of C# or Rust to rewrite TypeScript

2025-09-20 Thread An Pham via Digitalmars-d-learn
On Thursday, 11 September 2025 at 12:07:35 UTC, Serg Gini wrote: On Wednesday, 10 September 2025 at 03:46:37 UTC, felixfxu wrote: On Monday, 8 September 2025 at 20:10:52 UTC, Sergey wrote: being focused on required important tasks = complicated I don't quite understand the item above. What's

Re: Debug help - opDispatch - unknown member function

2025-09-20 Thread monkyyy via Digitalmars-d-learn
On Tuesday, 9 September 2025 at 00:40:31 UTC, Brother Bill wrote: https://tour.dlang.org/tour/en/gems/opdispatch-opapply This states: "Any unknown member function call to that type is passed to opDispatch, passing the unknown member function's name as a string template parameter." Specs are

Re: Microsoft chose Go instead of C# or Rust to rewrite TypeScript

2025-09-20 Thread Serg Gini via Digitalmars-d-learn
On Monday, 8 September 2025 at 16:43:10 UTC, Neto wrote: this is the reasoning https://github.com/microsoft/typescript-go/discussions/411 I wonder if they did consider D language. First comment says why Rust would be a good choice "If not C#, I would have expected Rust, since that's where the

Re: Placement new and @trusted

2025-09-20 Thread IchorDev via Digitalmars-d-learn
On Wednesday, 10 September 2025 at 13:13:34 UTC, Richard (Rikki) Andrew Cattermole wrote: Placement new is @system, but you wanted to use it in an @safe function iff the constructor to be called is @safe as well. Pretty much. The reason placement new is @system is because of double-init. It c

Cleared AA == and is have different results. Why?

2025-09-20 Thread Brother Bill via Digitalmars-d-learn
Page 119 of Programming in D It seems odd that == null and is null have different values? Is this a bug or feature? If a feature, what is the meanings of == null vs. is null? source/app.d ``` import std.stdio; void main() { // value[key] int[string] dayNumbers = // key :

Re: Debug help - opDispatch - unknown member function

2025-09-20 Thread Dejan Lekic via Digitalmars-d-learn
On Tuesday, 9 September 2025 at 12:04:07 UTC, Brother Bill wrote: When commenting out the callHome() in struct C, it fails. Obviously if callHome() is explicitly created, it works. If C does not have callHome() method, then ```d mixin("content." ~ name)(vals); ``` will simply fail, beca

Declaring a single const: enum vs const vs immutable

2025-09-20 Thread Brother Bill via Digitalmars-d-learn
Is there any reason to pick one of these vs. another one, or are they all equivalent? If equivalent, it would seem that immutable appears to be the 'strongest', whereas enum has fewer keystrokes. Is there a D 'best practice' for this? ``` const int foo1 = 42; enum foo2 = 42;

Re: Why is std.variant bad?

2025-09-20 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 20 September 2025 at 01:46:47 UTC, monkyyy wrote: This was before my time. I was under the impression that it was somehow class and oo related badness when people talked about using TypeInfo; but when I my own experiments say that typeinfo is just another tool I see 3k lines of c

Re: Explain function syntax

2025-09-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On Friday, 19 September 2025 at 16:58:38 UTC, Ali Çehreli wrote: On 9/18/25 10:18 PM, Steven Schveighoffer wrote: > On Thursday, 18 September 2025 at 18:10:13 UTC, Ali Çehreli wrote: >> // Not a delegate: >> static assert(is (typeof(twice) == function)); > You are mistaking the is expre

Why is std.variant bad?

2025-09-19 Thread monkyyy via Digitalmars-d-learn
This was before my time. I was under the impression that it was somehow class and oo related badness when people talked about using TypeInfo; but when I my own experiments say that typeinfo is just another tool I see 3k lines of code compared to my 50; Im going to say its but the postmorden s

Re: Debug help - opDispatch - unknown member function

2025-09-19 Thread Brother Bill via Digitalmars-d-learn
On Tuesday, 9 September 2025 at 01:24:59 UTC, monkyyy wrote: ``` // I suggest a habit of avoiding simple names when generating mixin code ``` Please provide an example where providing simple names causes 'trouble'.

Re: Discuss: Classes are well supported in D, with Design by Contracts. Shouldn't we take advantage of that?

2025-09-19 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Sep 13, 2025 at 12:43:38AM +, Brother Bill via Digitalmars-d-learn wrote: > I'm not clear about why 'class'es are on the 'avoid' list. Whose avoid list? I'd say that I usually don't use classes, not because I'm trying to avoid them, but b

Re: Explain function syntax

2025-09-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On Thursday, 18 September 2025 at 18:10:13 UTC, Ali Çehreli wrote: As stated by multiple people, most nested functions will be 'delegates'. However, a nested function is a 'function' if it does not touch local scope: ```d void main() { int twice(int i) { return i * 2; } //

Re: Debug help - opDispatch - unknown member function

2025-09-18 Thread monkyyy via Digitalmars-d-learn
On Tuesday, 9 September 2025 at 00:40:31 UTC, Brother Bill wrote: https://tour.dlang.org/tour/en/gems/opdispatch-opapply This states: "Any unknown member function call to that type is passed to opDispatch, passing the unknown member function's name as a string template parameter." [...] yo

Re: help for example with Condition

2025-09-18 Thread novicetoo via Digitalmars-d-learn
cond and mutex are global variables, and "Starting with dmd version 2.030, the default storage class for statics and globals will be thread local storage (TLS)" https://dlang.org/articles/migrate-to-shared.html

Re: Explain function syntax

2025-09-18 Thread Ali Çehreli via Digitalmars-d-learn
As stated by multiple people, most nested functions will be 'delegates'. However, a nested function is a 'function' if it does not touch local scope: void main() { int twice(int i) { return i * 2; } // Not a delegate: static assert(is (typeof(twice) == function)); } Ali

Re: Explain function syntax

2025-09-18 Thread Dejan Lekic via Digitalmars-d-learn
On Wednesday, 17 September 2025 at 22:16:50 UTC, Brother Bill wrote: In the following from Programming in D, page 483, we use function keyword. I expect that the first int in ``` int function(int); ``` represents the return value. What does the second (int) refer to? Second int is the type

Re: Placement new and @trusted

2025-09-18 Thread IchorDev via Digitalmars-d-learn
On Thursday, 11 September 2025 at 11:47:40 UTC, Dennis wrote: The trick that's used in druntime is putting the part that still needs to be checked for attributes inside an `if (false)` block, for example: ```d private T moveImpl(T)(return scope ref T source) { // Properly infer safety from

Re: Explain function syntax

2025-09-18 Thread Luna via Digitalmars-d-learn
On Wednesday, 17 September 2025 at 22:16:50 UTC, Brother Bill wrote: In the following from Programming in D, page 483, we use function keyword. I expect that the first int in ``` int function(int); ``` represents the return value. What does the second (int) refer to? Then there is another ex

Re: Explain function syntax

2025-09-18 Thread kdevel via Digitalmars-d-learn
On Wednesday, 17 September 2025 at 22:16:50 UTC, Brother Bill wrote: return value => increment + value; // ← compilation ERROR ```d void main() { auto calc = makeCalculator; writeln (calc (1)); } alias Calculator = int function(int); Calculator makeCalculator() {

Re: Placement new and @trusted

2025-09-17 Thread IchorDev via Digitalmars-d-learn
On Wednesday, 10 September 2025 at 14:45:52 UTC, Richard (Rikki) Andrew Cattermole wrote: The caller is responsible for guaranteeing that the memory passed in is uninitialized, and that behavior is @system. Yeah but I should be able to mark it as `@trusted` without trusting some random bloody

Re: Explain function syntax

2025-09-17 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 17 September 2025 at 22:16:50 UTC, Brother Bill wrote: Then there is another example with 'delegate' instead of 'function. ``` import std.stdio; void main() { } alias Calculator = int function(int); Calculator makeCalculator() { int increment = 10; return value

Re: Debug help - delegate from dlang Tour

2025-09-17 Thread evilrat via Digitalmars-d-learn
On Monday, 8 September 2025 at 14:32:32 UTC, Brother Bill wrote: https://tour.dlang.org/tour/en/basics/delegates This is so simple. What is D complaining about? Should this also work with a Template, as shown? ``` import std.stdio; void main() { // auto add(T)(T lhs, T rhs) //

Re: Placement new and @trusted

2025-09-17 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
Ok, gotcha. Placement new is @system, but you wanted to use it in an @safe function iff the constructor to be called is @safe as well. The reason placement new is @system is because of double-init. It can't be a safe operation.

Re: Explain function syntax

2025-09-17 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Sep 17, 2025 at 10:16:50PM +, Brother Bill via Digitalmars-d-learn wrote: > In the following from Programming in D, page 483, we use function keyword. > > I expect that the first int in > ``` > int function(int); > ``` > > represents the return value. >

Re: Explain function syntax

2025-09-17 Thread monkyyy via Digitalmars-d-learn
On Wednesday, 17 September 2025 at 22:16:50 UTC, Brother Bill wrote: ``` import std.stdio; void main() { } alias Calculator = int function(int); Calculator makeCalculator() { int increment = 10; return value => increment + value; // ← compilation ERROR } ``` function is alm

Explain function syntax

2025-09-17 Thread Brother Bill via Digitalmars-d-learn
In the following from Programming in D, page 483, we use function keyword. I expect that the first int in ``` int function(int); ``` represents the return value. What does the second (int) refer to? Then there is another example with 'delegate' instead of 'function. ``` import std.stdio;

Re: Debug help - delegate from dlang Tour

2025-09-17 Thread Brother Bill via Digitalmars-d-learn
This works: ``` import std.stdio; void main() { foo(); } void foo() { int addMyInts(int lhs, int rhs) { return lhs + rhs; } int doSomething(int delegate(int, int) doer) { // call passed function return doer(

Re: Cleared AA == and is have different results. Why?

2025-09-17 Thread Brother Bill via Digitalmars-d-learn
On Wednesday, 10 September 2025 at 14:25:05 UTC, IchorDev wrote: On Wednesday, 10 September 2025 at 14:01:29 UTC, Brother Bill wrote: what is the meanings of == null vs. is null? You have already asked this question [here before](https://forum.dlang.org/thread/nvaiwzvcrahnwzior...@forum.dlang

Re: Preventing .init for Archive struct, Programming in D, page 295

2025-09-17 Thread Dejan Lekic via Digitalmars-d-learn
On Friday, 12 September 2025 at 15:20:38 UTC, Brother Bill wrote: Is is possible to 'disable' .init for a struct? You do not want .init? Fine: ```d Archive noInit = void; ```

Re: Placement new and @trusted

2025-09-17 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 11 September 2025 at 11:47:40 UTC, Dennis wrote: On Wednesday, 10 September 2025 at 12:29:24 UTC, IchorDev wrote: If anyone has any ideas, please let me know. The trick that's used in druntime is putting the part that still needs to be checked for attributes inside an `if (false)

Re: understanding mir, generic nd array iterator

2025-09-17 Thread jmh530 via Digitalmars-d-learn
On Wednesday, 17 September 2025 at 14:57:19 UTC, monkyyy wrote: [snip] Sorry, I'm having trouble understanding what you're trying to do.

Re: Preventing .init for Archive struct, Programming in D, page 295

2025-09-17 Thread Monkyyy via Digitalmars-d-learn
On Friday, 12 September 2025 at 15:20:38 UTC, Brother Bill wrote: Is is possible to 'disable' .init for a struct? No (and honestly it's bad style to break the constructors)

Re: Microsoft chose Go instead of C# or Rust to rewrite TypeScript

2025-09-17 Thread Ali Çehreli via Digitalmars-d-learn
On 9/8/25 12:55 PM, Neto wrote: > On Monday, 8 September 2025 at 16:51:09 UTC, Serg Gini wrote: >> On Monday, 8 September 2025 at 16:43:10 UTC, Neto wrote: >> Yes, I know there are companies that are using it in production. >> Even several big ones like Weka and Symmetry. > Why isn't D productio

Re: understanding mir, generic nd array iterator

2025-09-17 Thread jmh530 via Digitalmars-d-learn
On Wednesday, 10 September 2025 at 20:23:28 UTC, monkyyy wrote: [snip] Documentation for mir iterators is here: http://mir-algorithm.libmir.org/mir_ndslice_iterator.html If you want to use mir without using the GC. You can allocate with malloc, custom allocator, or use an RC allocator. http:

Re: understanding mir, generic nd array iterator

2025-09-17 Thread monkyyy via Digitalmars-d-learn
On Wednesday, 17 September 2025 at 12:06:32 UTC, jmh530 wrote: On Wednesday, 10 September 2025 at 20:23:28 UTC, monkyyy wrote: [snip] Documentation for mir iterators is here: http://mir-algorithm.libmir.org/mir_ndslice_iterator.html I see nd-iota but it seems under powered(handling only the

Re: Discuss: Classes are well supported in D, with Design by Contracts. Shouldn't we take advantage of that?

2025-09-16 Thread monkyyy via Digitalmars-d-learn
On Saturday, 13 September 2025 at 01:00:17 UTC, Mike Parker wrote: What 'avoid list'? Mine in the last thread

Re: understanding mir, generic nd array iterator

2025-09-15 Thread Andy Valencia via Digitalmars-d-learn
On Monday, 15 September 2025 at 20:23:23 UTC, monkyyy wrote: mir is a lib that has nd math; that allot of people know is meta programming to hell and back but no one can tell ya how to use it nd is "N" as anonymous int and D as in dimension, 2d vs 3d vs ... 99d Cool... thanks. A world I nev

Re: understanding mir, generic nd array iterator

2025-09-15 Thread monkyyy via Digitalmars-d-learn
On Monday, 15 September 2025 at 20:10:22 UTC, Andy Valencia wrote: On Monday, 15 September 2025 at 17:07:36 UTC, monkyyy wrote: On Monday, 15 September 2025 at 16:59:58 UTC, Dejan Lekic wrote: On Wednesday, 10 September 2025 at 20:23:28 UTC, monkyyy wrote: I asked does a preexisting nd array

Re: understanding mir, generic nd array iterator

2025-09-15 Thread Andy Valencia via Digitalmars-d-learn
On Monday, 15 September 2025 at 17:07:36 UTC, monkyyy wrote: On Monday, 15 September 2025 at 16:59:58 UTC, Dejan Lekic wrote: On Wednesday, 10 September 2025 at 20:23:28 UTC, monkyyy wrote: I asked does a preexisting nd array iterator exist? got links to mir, docs I can barely read (srsly ma

Re: understanding mir, generic nd array iterator

2025-09-15 Thread monkyyy via Digitalmars-d-learn
On Monday, 15 September 2025 at 16:59:58 UTC, Dejan Lekic wrote: On Wednesday, 10 September 2025 at 20:23:28 UTC, monkyyy wrote: I asked does a preexisting nd array iterator exist? got links to mir, docs I can barely read (srsly math language is anticomprehension) I can barely read your po

Re: understanding mir, generic nd array iterator

2025-09-15 Thread Dejan Lekic via Digitalmars-d-learn
On Wednesday, 10 September 2025 at 20:23:28 UTC, monkyyy wrote: I asked does a preexisting nd array iterator exist? got links to mir, docs I can barely read (srsly math language is anticomprehension) I can barely read your posts, yet I do not complain...

Re: understanding mir, generic nd array iterator

2025-09-14 Thread monkyyy via Digitalmars-d-learn
On Wednesday, 10 September 2025 at 20:23:28 UTC, monkyyy wrote: I asked does a preexisting nd array iterator exist? got links to mir, docs I can barely read (srsly math language is anticomprehension) ndslice allocates, so, hottake misnamed. A slice is a reference to an array, a dynmaic arr

Re: Is RDTSC pure?

2025-09-14 Thread IchorDev via Digitalmars-d-learn
On Sunday, 14 September 2025 at 02:50:42 UTC, Jonathan M Davis wrote: Memory gets weird on top of that because of the desire to use the GC with pure functions and the argument that two objects with the same value are the same even though they're different places in memory (so whether they're re

Re: Is RDTSC pure?

2025-09-13 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, September 12, 2025 3:48:49 AM Mountain Daylight Time IchorDev via Digitalmars-d-learn wrote: > Recently I wanted to write a pure function that returns an > unpredictable number, so I decided to use RDTSC (and any > equivalent instruction for other CPU architectures) to do this

Re: Preventing .init for Archive struct, Programming in D, page 295

2025-09-13 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, September 12, 2025 9:20:38 AM Mountain Daylight Time Brother Bill via Digitalmars-d-learn wrote: > Is is possible to 'disable' .init for a struct? Technically, yes, but you should absolutely never do it, and it will likely become illegal to do so at some point in the fut

Re: Preventing .init for Archive struct, Programming in D, page 295

2025-09-13 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, September 12, 2025 5:58:57 PM Mountain Daylight Time Brother Bill via Digitalmars-d-learn wrote: > Is it time to consider D 3.x.x, that takes the best of D, > discards the mistakes, the mud and the hair, so most well written > D 2.x.x programs still work? Unless, something si

Re: Discuss: Classes are well supported in D, with Design by Contracts. Shouldn't we take advantage of that?

2025-09-13 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, September 12, 2025 6:43:38 PM Mountain Daylight Time Brother Bill via Digitalmars-d-learn wrote: > I'm not clear about why 'class'es are on the 'avoid' list. It's more that there's rarely any reason to use classes in D for the average program. If

Re: Discuss: Classes are well supported in D, with Design by Contracts. Shouldn't we take advantage of that?

2025-09-13 Thread Neto via Digitalmars-d-learn
On Saturday, 13 September 2025 at 15:26:15 UTC, H. S. Teoh wrote: On Sat, Sep 13, 2025 at 12:43:38AM +, Brother Bill via Digitalmars-d-learn wrote: [...] Whose avoid list? [...] what are those real profiles that you're using now?

Re: Microsoft chose Go instead of C# or Rust to rewrite TypeScript

2025-09-13 Thread Brother Bill via Digitalmars-d-learn
On Monday, 8 September 2025 at 20:10:52 UTC, Sergey wrote: On Monday, 8 September 2025 at 19:55:20 UTC, Neto wrote: Why isn't D production ready? One has to ask why to choose a production language. 1. First one has to be aware that it exists. a. See Eiffel and D Eiffel has been in prod

Re: help for example with Condition

2025-09-13 Thread novicetoo via Digitalmars-d-learn
On Thursday, 11 September 2025 at 09:51:55 UTC, Mikhail wrote: I don't understand what I should do? Define global variables as shared? Andrea Fontana reply more good than my. But I hope you read article for new knowledges. Anyway, IMHO, if you want use global variable from two ore more thread

Re: Preventing .init for Archive struct, Programming in D, page 295

2025-09-13 Thread Brother Bill via Digitalmars-d-learn
On Friday, 12 September 2025 at 15:24:46 UTC, Monkyyy wrote: On Friday, 12 September 2025 at 15:20:38 UTC, Brother Bill wrote: Is is possible to 'disable' .init for a struct? No (and honestly it's bad style to break the constructors) Please expound on why its 'bad style' to disable construct

Re: Preventing .init for Archive struct, Programming in D, page 295

2025-09-12 Thread Brother Bill via Digitalmars-d-learn
On Friday, 12 September 2025 at 21:46:51 UTC, monkyyy wrote: On Friday, 12 September 2025 at 20:10:25 UTC, H. S. Teoh wrote: Phobos code was legendary for being a standard library that didn't make your head hurt when you read it. (If you've ever tried reading the source code for Glibc, or the s

Discuss: Classes are well supported in D, with Design by Contracts. Shouldn't we take advantage of that?

2025-09-12 Thread Brother Bill via Digitalmars-d-learn
I'm not clear about why 'class'es are on the 'avoid' list. D has excellent support for Single inheritance, Interfaces, Design by Contract (DbC), GC, etc. I'm aware that there is a small run time cost for selecting the right virtual method. To reduce this cost, one must final-ize methods that

Re: Preventing .init for Archive struct, Programming in D, page 295

2025-09-12 Thread monkyyy via Digitalmars-d-learn
On Friday, 12 September 2025 at 23:58:57 UTC, Brother Bill wrote: On Friday, 12 September 2025 at 21:46:51 UTC, monkyyy wrote: On Friday, 12 September 2025 at 20:10:25 UTC, H. S. Teoh wrote: Phobos code was legendary for being a standard library that didn't make your head hurt when you read it.

Re: Discuss: Classes are well supported in D, with Design by Contracts. Shouldn't we take advantage of that?

2025-09-12 Thread Mike Parker via Digitalmars-d-learn
On Saturday, 13 September 2025 at 00:43:38 UTC, Brother Bill wrote: I'm not clear about why 'class'es are on the 'avoid' list. D has excellent support for Single inheritance, Interfaces, Design by Contract (DbC), GC, etc. I'm aware that there is a small run time cost for selecting the right vi

Re: Preventing .init for Archive struct, Programming in D, page 295

2025-09-12 Thread monkyyy via Digitalmars-d-learn
On Friday, 12 September 2025 at 20:10:25 UTC, H. S. Teoh wrote: Phobos code was legendary for being a standard library that didn't make your head hurt when you read it. (If you've ever tried reading the source code for Glibc, or the standard library for almost any other language, really, you'll

Preventing .init for Archive struct, Programming in D, page 295

2025-09-12 Thread Brother Bill via Digitalmars-d-learn
Is is possible to 'disable' .init for a struct? source/app.d ``` import std.stdio; void main() { // Can still create Archive with an empty filename. We can't have that. auto noDefault = Archive.init; writefln("fileName: [%s]", noDefault.fileName); } // adding a constructor au

Re: When not capturing the return value of a string mixin expression, I get "found `End of File` when expecting `;`"

2025-09-12 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Sep 12, 2025 at 03:41:15PM +, realhet via Digitalmars-d-learn wrote: > On Friday, 12 September 2025 at 15:28:58 UTC, Monkyyy wrote: > > On Friday, 12 September 2025 at 08:36:42 UTC, realhet wrote: > > > Hi, > > > > > > ```d > > > import std

Re: Preventing .init for Archive struct, Programming in D, page 295

2025-09-12 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Sep 12, 2025 at 06:19:46PM +, Brother Bill via Digitalmars-d-learn wrote: [...] > As a newbie to D, really trying to understand it, I am merely trying > to uncover how to effectively use D. When Programming in D book, page > 292, section 52.4 talks about 'postblit&#x

Re: Preventing .init for Archive struct, Programming in D, page 295

2025-09-12 Thread monkyyy via Digitalmars-d-learn
On Friday, 12 September 2025 at 18:19:46 UTC, Brother Bill wrote: Is there a 'style' guide for D, such as: Do this, Don't do that, avoid this, etc.? Someone will link the "offical" style guide, but thats nothing id follow "There are these features in the language, but you should avoid the

Re: Preventing .init for Archive struct, Programming in D, page 295

2025-09-12 Thread Brother Bill via Digitalmars-d-learn
On Friday, 12 September 2025 at 15:38:15 UTC, Monkyyy wrote: On Friday, 12 September 2025 at 15:31:37 UTC, Brother Bill wrote: On Friday, 12 September 2025 at 15:24:46 UTC, Monkyyy wrote: On Friday, 12 September 2025 at 15:20:38 UTC, Brother Bill wrote: Is is possible to 'disable' .init for a

Re: When not capturing the return value of a string mixin expression, I get "found `End of File` when expecting `;`"

2025-09-12 Thread Dejan Lekic via Digitalmars-d-learn
On Friday, 12 September 2025 at 13:27:53 UTC, realhet wrote: (x); <- Is not a construct that comes to my mind as useful, but this was it. This forces the mixin to expect an expression and not a statement. Thanks for sharing it! - I did not know this works. :)

Re: When not capturing the return value of a string mixin expression, I get "found `End of File` when expecting `;`"

2025-09-12 Thread realhet via Digitalmars-d-learn
On Friday, 12 September 2025 at 12:23:21 UTC, Nick Treleaven wrote: On Friday, 12 September 2025 at 09:17:10 UTC, realhet wrote: On Friday, 12 September 2025 at 08:44:47 UTC, Stefan Koch wrote: On Friday, 12 September 2025 at 08:36:42 UTC, realhet wrote: I did a complete 'martix' of these com

Re: When not capturing the return value of a string mixin expression, I get "found `End of File` when expecting `;`"

2025-09-12 Thread realhet via Digitalmars-d-learn
On Friday, 12 September 2025 at 09:55:01 UTC, IchorDev wrote: On Friday, 12 September 2025 at 08:36:42 UTC, realhet wrote: Is this a feature or a bug? :D You will have to start writing much weirder code than this to Yea, I don't think I dare to do such crazy things, like an lambda in an UDA

Re: When not capturing the return value of a string mixin expression, I get "found `End of File` when expecting `;`"

2025-09-12 Thread realhet via Digitalmars-d-learn
On Friday, 12 September 2025 at 15:28:58 UTC, Monkyyy wrote: On Friday, 12 September 2025 at 08:36:42 UTC, realhet wrote: Hi, ```d import std; [...] It's seeing the eof of the mix file no? This is the smallest example so far: ```d import std; void main() { ( mixin("(()=>1)()") ); //i

Re: Preventing .init for Archive struct, Programming in D, page 295

2025-09-12 Thread Monkyyy via Digitalmars-d-learn
On Friday, 12 September 2025 at 15:31:37 UTC, Brother Bill wrote: On Friday, 12 September 2025 at 15:24:46 UTC, Monkyyy wrote: On Friday, 12 September 2025 at 15:20:38 UTC, Brother Bill wrote: Is is possible to 'disable' .init for a struct? No (and honestly it's bad style to break the constru

Re: Is RDTSC pure?

2025-09-12 Thread IchorDev via Digitalmars-d-learn
On Friday, 12 September 2025 at 14:48:43 UTC, Kagamin wrote: malloc is weakly pure, because it returns mutable pointer. The difference is when you call it from strongly pure function, then it doesn't matter, how many times malloc was called. And if the compiler tries to memoise it?

Re: When not capturing the return value of a string mixin expression, I get "found `End of File` when expecting `;`"

2025-09-12 Thread Monkyyy via Digitalmars-d-learn
On Friday, 12 September 2025 at 08:36:42 UTC, realhet wrote: Hi, ```d import std; [...] It's seeing the eof of the mix file no?

Re: Is RDTSC pure?

2025-09-12 Thread Kagamin via Digitalmars-d-learn
malloc is weakly pure, because it returns mutable pointer. The difference is when you call it from strongly pure function, then it doesn't matter, how many times malloc was called.

Re: When not capturing the return value of a string mixin expression, I get "found `End of File` when expecting `;`"

2025-09-12 Thread Nick Treleaven via Digitalmars-d-learn
On Friday, 12 September 2025 at 09:17:10 UTC, realhet wrote: On Friday, 12 September 2025 at 08:44:47 UTC, Stefan Koch wrote: On Friday, 12 September 2025 at 08:36:42 UTC, realhet wrote: Hi, thanks for quick answer! When I turn the string mixin into a statement by putting a `;` at its end, th

Re: When not capturing the return value of a string mixin expression, I get "found `End of File` when expecting `;`"

2025-09-12 Thread IchorDev via Digitalmars-d-learn
On Friday, 12 September 2025 at 08:36:42 UTC, realhet wrote: Is this a feature or a bug? :D You will have to start writing much weirder code than this to find compiler bugs in D because when a bug is fixed, a new test is created to make sure it doesn't regress. Surface-level features are usu

Re: Placement new and @trusted

2025-09-12 Thread Nick Treleaven via Digitalmars-d-learn
On Thursday, 11 September 2025 at 08:06:17 UTC, IchorDev wrote: But that's the thing: all I want is to construct objects into *freshly-allocated*, *uninitialised memory*; so my desired use-case has a safe interface and can therefore be marked `@trusted`. However the constructor is a wildcard, s

Is RDTSC pure?

2025-09-12 Thread IchorDev via Digitalmars-d-learn
Recently I wanted to write a pure function that returns an unpredictable number, so I decided to use RDTSC (and any equivalent instruction for other CPU architectures) to do this, since the compiler allows RDTSC to be marked as `pure`. However, in the end I discarded this idea because I figured

Re: Placement new and @trusted

2025-09-12 Thread IchorDev via Digitalmars-d-learn
On Thursday, 11 September 2025 at 17:16:35 UTC, Paul Backus wrote: ```d void inferSystem() @system pure nothrow @nogc {} T* example(T)() { static if (!isSafe!(() { new T(); }) inferSystem(); return (() @trusted => new (new void[](T.sizeof)) T())(); } ``` Unfortunately that woul

Re: When not capturing the return value of a string mixin expression, I get "found `End of File` when expecting `;`"

2025-09-12 Thread Dejan Lekic via Digitalmars-d-learn
On Friday, 12 September 2025 at 08:36:42 UTC, realhet wrote: Is this a feature or a bug? :D Is there a way to make this processing_and_optional_returning thing better? It is a bug in your code. Change line 6 to ```d (){ val += 1; return val; }(); ``` After the added `;` it should wo

Re: When not capturing the return value of a string mixin expression, I get "found `End of File` when expecting `;`"

2025-09-12 Thread realhet via Digitalmars-d-learn
On Friday, 12 September 2025 at 08:44:47 UTC, Stefan Koch wrote: On Friday, 12 September 2025 at 08:36:42 UTC, realhet wrote: Hi, thanks for quick answer! When I turn the string mixin into a statement by putting a `;` at its end, the enum bla = `(){return 4;}();` `mixin(bla);` Case works p

Re: When not capturing the return value of a string mixin expression, I get "found `End of File` when expecting `;`"

2025-09-12 Thread Stefan Koch via Digitalmars-d-learn
On Friday, 12 September 2025 at 08:36:42 UTC, realhet wrote: Hi, ```d import std; void main() { int val = 4; enum prog = q{ (){ val += 1; return val; }() }; //mixin(prog); // auto dummy = mixin(prog); //Must capture the return value, otherwise it hallucinates EOF.

When not capturing the return value of a string mixin expression, I get "found `End of File` when expecting `;`"

2025-09-12 Thread realhet via Digitalmars-d-learn
Hi, ```d import std; void main() { int val = 4; enum prog = q{ (){ val += 1; return val; }() }; //mixin(prog); // auto dummy = mixin(prog); //Must capture the return value, otherwise it hallucinates EOF. writeln(val); } ``` When uncommentingmixin(prog); It

Re: Placement new and @trusted

2025-09-11 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 11/09/2025 12:29 AM, IchorDev wrote: I thought the 'placement new' feature might replace my need for `emplace`, but I don't see a way to mark a placement new as `@trusted` without marking the call to the object's constructor as `@trusted` also? ```d void main() @safe{ X x; //pla

Debug help - opDispatch - unknown member function

2025-09-11 Thread Brother Bill via Digitalmars-d-learn
https://tour.dlang.org/tour/en/gems/opdispatch-opapply This states: "Any unknown member function call to that type is passed to opDispatch, passing the unknown member function's name as a string template parameter." So I tried that. But the compiler didn't like it. How should I play the game

Re: Debug help - opDispatch - unknown member function

2025-09-11 Thread monkyyy via Digitalmars-d-learn
On Tuesday, 9 September 2025 at 11:57:54 UTC, Brother Bill wrote: On Tuesday, 9 September 2025 at 01:24:59 UTC, monkyyy wrote: ``` // I suggest a habit of avoiding simple names when generating mixin code ``` Please provide an example where providing simple names causes 'trouble'. ```d im

Re: Microsoft chose Go instead of C# or Rust to rewrite TypeScript

2025-09-11 Thread Kapendev via Digitalmars-d-learn
On Tuesday, 9 September 2025 at 21:08:59 UTC, drug007 wrote: On 09.09.2025 01:53, Kapendev wrote: On Monday, 8 September 2025 at 21:25:25 UTC, drug007 wrote: On 08.09.2025 22:55, Neto wrote: On Monday, 8 September 2025 at 16:51:09 UTC, Serg Gini wrote: And not sure if ecosystem was a signifi

Re: Declaring a single const: enum vs const vs immutable

2025-09-11 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Sep 10, 2025 at 05:15:16PM +, monkyyy via Digitalmars-d-learn wrote: [...] > I just do always enum; going all in on compile time abstractions Be careful, this may not always be what you want. For example: ```d enum data = [ 1, 2, 3 ]; void main() { auto buffer = d

Re: Debug help - opDispatch - unknown member function

2025-09-11 Thread monkyyy via Digitalmars-d-learn
On Tuesday, 9 September 2025 at 20:56:19 UTC, Steven Schveighoffer wrote: On Tuesday, 9 September 2025 at 20:08:06 UTC, monkyyy wrote: On Tuesday, 9 September 2025 at 19:17:11 UTC, Steven Schveighoffer wrote: In short `opDispatch` only is valid if it compiles. If it doesn't compile, it's as i

Re: Microsoft chose Go instead of C# or Rust to rewrite TypeScript

2025-09-11 Thread Serg Gini via Digitalmars-d-learn
On Wednesday, 10 September 2025 at 03:46:37 UTC, felixfxu wrote: On Monday, 8 September 2025 at 20:10:52 UTC, Sergey wrote: being focused on required important tasks = complicated I don't quite understand the item above. What's dlang's `"required important tasks"` now? This one actually ove

Re: Placement new and @trusted

2025-09-11 Thread Dennis via Digitalmars-d-learn
On Wednesday, 10 September 2025 at 12:29:24 UTC, IchorDev wrote: If anyone has any ideas, please let me know. The trick that's used in druntime is putting the part that still needs to be checked for attributes inside an `if (false)` block, for example: https://github.com/dlang/dmd/blob/c817

Re: help for example with Condition

2025-09-11 Thread Mikhail via Digitalmars-d-learn
On Thursday, 11 September 2025 at 09:51:55 UTC, Mikhail wrote: On Thursday, 11 September 2025 at 09:40:22 UTC, novicetoo wrote: cond and mutex are global variables, and "Starting with dmd version 2.030, the default storage class for statics and globals will be thread local storage (TLS)" http

Re: help for example with Condition

2025-09-11 Thread Mikhail via Digitalmars-d-learn
On Thursday, 11 September 2025 at 09:40:22 UTC, novicetoo wrote: cond and mutex are global variables, and "Starting with dmd version 2.030, the default storage class for statics and globals will be thread local storage (TLS)" https://dlang.org/articles/migrate-to-shared.html I don't understan

Re: help for example with Condition

2025-09-11 Thread Andrea Fontana via Digitalmars-d-learn
On Thursday, 11 September 2025 at 09:29:29 UTC, Mikhail wrote: I wrote simple example to learn how the work Conditions. But program closed with signal, what's wrong? import std.stdio; import core.thread; import core.sync.condition; import core.sync.mutex; Condition cond; Mutex mutex; void thr

help for example with Condition

2025-09-11 Thread Mikhail via Digitalmars-d-learn
I wrote simple example to learn how the work Conditions. But program closed with signal, what's wrong? import std.stdio; import core.thread; import core.sync.condition; import core.sync.mutex; Condition cond; Mutex mutex; void threadFunction() { writeln("This is running in a separate threa

Re: Declaring a single const: enum vs const vs immutable

2025-09-11 Thread IchorDev via Digitalmars-d-learn
On Wednesday, 10 September 2025 at 17:33:48 UTC, H. S. Teoh wrote: `enum` defines a compile-time constant. It occupies no space, and its value is "copied" into every expression in which it appears. [...] `const` and `immutable` are type qualifiers, and declaring a constant with them creates a

Re: Placement new and @trusted

2025-09-11 Thread IchorDev via Digitalmars-d-learn
On Thursday, 11 September 2025 at 03:47:02 UTC, Richard (Rikki) Andrew Cattermole wrote: It did go through the DIP process. Blast, you're right. I've even seen the DIP Development post for it before, too! I didn't read into it at the time. I could've probably identified this problem and raise

Re: Placement new and @trusted

2025-09-11 Thread IchorDev via Digitalmars-d-learn
On Thursday, 11 September 2025 at 04:19:02 UTC, Paul Backus wrote: The problem is not really with placement new, it's with constructors. Constructors are allowed to mutate immutable objects (under the assumption that they are initializing a newly-created object). If you call a constructor twice

  1   2   3   4   5   6   7   8   9   10   >