Re: nested function overloading

2022-06-21 Thread monkyyy via Digitalmars-d-learn
On Monday, 20 June 2022 at 13:20:51 UTC, Steven Schveighoffer wrote: And you can also use an inner struct to define overloaded functions. I believe templates make a better bandaid ```d void main(){ template bar(){ void bar_(int){} void bar_(float){}

Re: int | missing | absent

2022-06-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/2/22 9:24 AM, bauss wrote: On Thursday, 2 June 2022 at 08:27:32 UTC, Antonio wrote: JSON properties can be - a value - null - absent What's the standard way to define a serialziable/deserializable structs supporting properties of any of this 4 kinds?: * int * int | null * int | absent *

Re: int | missing | absent

2022-06-21 Thread Antonio via Digitalmars-d-learn
On Thursday, 2 June 2022 at 13:24:08 UTC, bauss wrote: On Thursday, 2 June 2022 at 08:27:32 UTC, Antonio wrote: JSON properties can be - a value - null - absent What's the standard way to define a serialziable/deserializable structs supporting properties of any of this 4 kinds?: * int * int

Re: destroy and @safe

2022-06-21 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jun 21, 2022 at 06:28:14PM +, Paul Backus via Digitalmars-d-learn wrote: > On Tuesday, 21 June 2022 at 17:33:46 UTC, H. S. Teoh wrote: > > > > Does the language allow you to declare a @system delegate inside > > @safe code? > > Yes. This compiles: > > void main() @safe > { >

Re: destroy and @safe

2022-06-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/21/22 1:33 PM, H. S. Teoh wrote: On Tue, Jun 21, 2022 at 01:29:47PM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: ```d void foo(void delegate() @system dg) @safe { int *bar; @system void corrupt() { bar = cast(int *)0xdeadbeef;} dg = &corrupt; // can I call dg

Re: destroy and @safe

2022-06-21 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 21 June 2022 at 17:33:46 UTC, H. S. Teoh wrote: Does the language allow you to declare a @system delegate inside @safe code? Yes. This compiles: void main() @safe { void delegate() @system dg = () @system { /* do scary stuff */ }; }

Re: Better way to achieve the following

2022-06-21 Thread Ali Çehreli via Digitalmars-d-learn
On 6/21/22 10:09, JG wrote: Suppose we are often writing something like ```d theFirstName[theFirstIndex].theSecondName[theSecondIndex].thirdName[theThirdIndex]=x; ``` One would like to something like ```d alias shortName = theFirstName[theFirstIndex].theSecondName[theSecondIndex].thirdName[th

Re: Better way to achieve the following

2022-06-21 Thread Tejas via Digitalmars-d-learn
On Tuesday, 21 June 2022 at 17:09:28 UTC, JG wrote: Suppose we are often writing something like ```d theFirstName[theFirstIndex].theSecondName[theSecondIndex].thirdName[theThirdIndex]=x; ``` One would like to something like ```d alias shortName = theFirstName[theFirstIndex].theSecondName[theSeco

Re: Better way to achieve the following

2022-06-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/21/22 1:19 PM, JG wrote: On Tuesday, 21 June 2022 at 17:15:02 UTC, Steven Schveighoffer wrote: On 6/21/22 1:09 PM, JG wrote: Thoughts? Use a pointer? Especially if you are using `.method` calls, this just works seamlessly. Thanks for the suggestion.  My immediate reaction is that fo

Re: destroy and @safe

2022-06-21 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jun 21, 2022 at 01:29:47PM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: > On 6/21/22 1:17 PM, H. S. Teoh wrote: [...] > > This is why I've proposed in the past that @safe functions should be > > allowed to call @system delegates that they receive as arguments. The > > reasoni

Re: destroy and @safe

2022-06-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/21/22 1:17 PM, H. S. Teoh wrote: On Tue, Jun 21, 2022 at 04:47:44PM +, Antonio via Digitalmars-d-learn wrote: On Tuesday, 21 June 2022 at 16:20:32 UTC, Antonio wrote: My code starts to be a @safe/@trusted mess (because external libraries). The only solution I have is to "wrap" them o

Re: Better way to achieve the following

2022-06-21 Thread JG via Digitalmars-d-learn
On Tuesday, 21 June 2022 at 17:15:02 UTC, Steven Schveighoffer wrote: On 6/21/22 1:09 PM, JG wrote: Thoughts? Use a pointer? Especially if you are using `.method` calls, this just works seamlessly. -Steve Thanks for the suggestion. My immediate reaction is that for `.method` calls I wou

Re: Better way to achieve the following

2022-06-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/21/22 1:09 PM, JG wrote: Thoughts? Use a pointer? Especially if you are using `.method` calls, this just works seamlessly. -Steve

Re: destroy and @safe

2022-06-21 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jun 21, 2022 at 04:47:44PM +, Antonio via Digitalmars-d-learn wrote: > On Tuesday, 21 June 2022 at 16:20:32 UTC, Antonio wrote: > > > My code starts to be a @safe/@trusted mess (because external > > libraries). The only solution I have is to "wrap" them or to trust > > all code by def

Re: destroy and @safe

2022-06-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/21/22 12:33 PM, Antonio wrote: On Tuesday, 21 June 2022 at 15:14:43 UTC, Steven Schveighoffer wrote: You delegate doesn't seem to be marked @safe as well. Thanks a lot Steve, I didn't found a way (or example) to specify the delegate must be @safe until I have found vibe.d.db.post

Better way to achieve the following

2022-06-21 Thread JG via Digitalmars-d-learn
Suppose we are often writing something like ```d theFirstName[theFirstIndex].theSecondName[theSecondIndex].thirdName[theThirdIndex]=x; ``` One would like to something like ```d alias shortName = theFirstName[theFirstIndex].theSecondName[theSecondIndex].thirdName[theThirdIndex]; shortName = x; ``

Re: destroy and @safe

2022-06-21 Thread Antonio via Digitalmars-d-learn
On Tuesday, 21 June 2022 at 16:20:32 UTC, Antonio wrote: My code starts to be a @safe/@trusted mess (because external libraries). The only solution I have is to "wrap" them or to trust all code by default (I'm using vibe.d that forces @safe code) Only as a comment: I can remember now when d

Re: destroy and @safe

2022-06-21 Thread Antonio via Digitalmars-d-learn
On Tuesday, 21 June 2022 at 15:14:43 UTC, Steven Schveighoffer wrote: You delegate doesn't seem to be marked @safe as well. Thanks a lot Steve, I didn't found a way (or example) to specify the delegate must be @safe until I have found vibe.d.db.postgress implementation (that you maint

Re: destroy and @safe

2022-06-21 Thread Antonio via Digitalmars-d-learn
On Tuesday, 21 June 2022 at 15:13:36 UTC, Paul Backus wrote: If the destructor is `@system`, then the only way to call `destroy` in `@safe` code is to (1) determine the conditions necessary to call the destructor without violating memory safety, (2) ensure that those conditions are met (using

Re: destroy and @safe

2022-06-21 Thread Adam D Ruppe via Digitalmars-d-learn
On Tuesday, 21 June 2022 at 15:13:36 UTC, Paul Backus wrote: `destroy` should be `@safe` as long as the destructor it's calling is `@safe`. For classes, the current dmd+druntime implementation makes it impossible to determine statically if the destructor is safe or not. Structs I'm not sure

Re: destroy and @safe

2022-06-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/21/22 10:40 AM, Antonio wrote: I'm using explicitly destroy!false(obj) for a "deterministic" resources release. I replicate the c# "using" pattern, or the python "with" pattern with my own "use" template supposing object are RAII i.e.: ```d Item[] items = query("...").use( (Answer a) =

Re: destroy and @safe

2022-06-21 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 21 June 2022 at 14:40:41 UTC, Antonio wrote: The problem: "use" can't be @safe because it contains a call to "destroy". `destroy` should be `@safe` as long as the destructor it's calling is `@safe`. If the destructor is `@system`, then the only way to call `destroy` in `@safe`

destroy and @safe

2022-06-21 Thread Antonio via Digitalmars-d-learn
I'm using explicitly destroy!false(obj) for a "deterministic" resources release. I replicate the c# "using" pattern, or the python "with" pattern with my own "use" template supposing object are RAII i.e.: ```d Item[] items = query("...").use( (Answer a) => a.rangify.map!(rowToItem).array()

Re: Failure due to memcpy being called at compile time

2022-06-21 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 21 June 2022 at 04:30:25 UTC, JG wrote: On Tuesday, 21 June 2022 at 01:39:43 UTC, Paul Backus wrote: Update: a new release of [the `sumtype` package on code.dlang.org][1] is available that includes the fix for this bug. `std.sumtype` will be fixed in the next Phobos release, 2.10

Re: Any way to define variables from one scope in another scope?

2022-06-21 Thread bauss via Digitalmars-d-learn
On Monday, 20 June 2022 at 13:56:04 UTC, Ruby The Roobster wrote: Is there any way to define variables in an outer scope from an inner scope? I was thinking ```d void main() { int .y = 3; } ``` would work, but it doesn't. No and it would only lead to bugs. If you have access to an inner