Re: Creating immutable arrays in @safe code

2021-07-17 Thread Dennis via Digitalmars-d-learn
On Saturday, 17 July 2021 at 05:44:24 UTC, ag0aep6g wrote: I tried doing that, but `-preview=dip1000` causes trouble. This fails: (...) I'm not sure what's going on. I'm not completely caught up, but from what I see, pure and immutable have a history of issues: [Issue 11503 - Type system br

Re: Creating immutable arrays in @safe code

2021-07-17 Thread ag0aep6g via Digitalmars-d-learn
On 17.07.21 13:05, Dennis wrote: There used to be a complex `isReturnIsolated` check, but the [fix for issue 15660](https://github.com/dlang/dmd/pull/8048) reduced it to a check 'is the function strongly `pure`' which means 'parameters are values or immutable'. To reduce code breakage, the 'str

Re: Creating immutable arrays in @safe code

2021-07-17 Thread Dennis via Digitalmars-d-learn
On Saturday, 17 July 2021 at 12:05:44 UTC, ag0aep6g wrote: Hm, as far as I understand, "strongly pure" doesn't require `immutable` parameters. `const` should be enough. The spec says: "A strongly pure function has no parameters with mutable indirections" [1]. I just took the description from

Re: Creating immutable arrays in @safe code

2021-07-17 Thread rikki cattermole via Digitalmars-d-learn
On 18/07/2021 12:56 AM, Dennis wrote: I don't know whether the spec or code is correct. Unless otherwise specified, the code is authoritative.

Re: Creating immutable arrays in @safe code

2021-07-17 Thread ag0aep6g via Digitalmars-d-learn
On 17.07.21 14:56, Dennis wrote: On Saturday, 17 July 2021 at 12:05:44 UTC, ag0aep6g wrote: Hm, as far as I understand, "strongly pure" doesn't require `immutable` parameters. `const` should be enough. The spec says: "A strongly pure function has no parameters with mutable indirections" [1].

interface function member declarations needing parameter attributes ?

2021-07-17 Thread someone via Digitalmars-d-learn
```d public interface intefaceWhatever { public bool doSomething( dstring lstrID, classX robjX ); } ``` vs ```d public interface intefaceWhatever { public bool doSomething( const dstring lstrID, ref classX robjX ); } ``` From the interface perspecti

function parameters: is it possible to pass byref ... while being optional at the same time ?

2021-07-17 Thread someone via Digitalmars-d-learn
The following gives me a compiler error when I add the second parameter: is not an lvalue and cannot be modified ```d public bool add( ref classTickerID robjTickerID, ref classExchanges robjExchanges = null /// needing this optional ) { } ``` If I take out the null then the paramete

Re: interface function member declarations needing parameter attributes ?

2021-07-17 Thread Adam Ruppe via Digitalmars-d-learn
On Saturday, 17 July 2021 at 20:42:06 UTC, someone wrote: From the interface perspective: are these signatures identical or not ? No, they are very different. But you also don't gain much from const here and that ref is probably actively harmful so i wouldn't use them here.

Re: function parameters: is it possible to pass byref ... while being optional at the same time ?

2021-07-17 Thread Adam Ruppe via Digitalmars-d-learn
On Saturday, 17 July 2021 at 20:49:58 UTC, someone wrote: ref classTickerID robjTickerID Why are you using ref here at all? You probably shouldn't be using it. But if it is legitimately needed you can do a pointer instead of ref.

Re: function parameters: is it possible to pass byref ... while being optional at the same time ?

2021-07-17 Thread Jack Applegame via Digitalmars-d-learn
On Saturday, 17 July 2021 at 20:49:58 UTC, someone wrote: The following gives me a compiler error when I add the second parameter: is not an lvalue and cannot be modified ```d public bool add( ref classTickerID robjTickerID, ref classExchanges robjExchanges = null /// needing this option

Re: function parameters: is it possible to pass byref ... while being optional at the same time ?

2021-07-17 Thread someone via Digitalmars-d-learn
On Saturday, 17 July 2021 at 21:02:38 UTC, Adam Ruppe wrote: Why are you using ref here at all? Muscle memory I suppose; objects need to be passed by reference, these are the things I'll need to be re-wired to in D. You probably shouldn't be using it. But if it is legitimately needed you c

Re: function parameters: is it possible to pass byref ... while being optional at the same time ?

2021-07-17 Thread someone via Digitalmars-d-learn
On Saturday, 17 July 2021 at 21:46:38 UTC, Jack Applegame wrote: Just remove `ref`, because in D clasess themselves are references. All refs are goners now; thanks :) !

Re: interface function member declarations needing parameter attributes ?

2021-07-17 Thread someone via Digitalmars-d-learn
On Saturday, 17 July 2021 at 21:01:00 UTC, Adam Ruppe wrote: No, they are very different. So the lesson learned is that interfaces can also mandate member function's parameter attributes then ... right ? But you also don't gain much from const here and that ref is probably actively harmful

Re: interface function member declarations needing parameter attributes ?

2021-07-17 Thread Adam D Ruppe via Digitalmars-d-learn
On Saturday, 17 July 2021 at 22:43:15 UTC, someone wrote: So the lesson learned is that interfaces can also mandate member function's parameter attributes then ... right ? A subclass must accept anything the parent class can, but it can also make it stricter if you want. class Base {

Re: interface function member declarations needing parameter attributes ?

2021-07-17 Thread someone via Digitalmars-d-learn
On Saturday, 17 July 2021 at 22:48:00 UTC, Adam D Ruppe wrote: On Saturday, 17 July 2021 at 22:43:15 UTC, someone wrote: So the lesson learned is that interfaces can also mandate member function's parameter attributes then ... right ? A subclass must accept anything the parent class can, but i

Re: function parameters: is it possible to pass byref ... while being optional at the same time ?

2021-07-17 Thread zjh via Digitalmars-d-learn
On Saturday, 17 July 2021 at 22:40:35 UTC, someone wrote: On Saturday, 17 July 2021 at 21:46:38 UTC, Jack Applegame wrote: This must be `Forum Oriented Programming`.

Re: function parameters: is it possible to pass byref ... while being optional at the same time ?

2021-07-17 Thread Brian Tiffin via Digitalmars-d-learn
On Sunday, 18 July 2021 at 00:00:01 UTC, zjh wrote: On Saturday, 17 July 2021 at 22:40:35 UTC, someone wrote: On Saturday, 17 July 2021 at 21:46:38 UTC, Jack Applegame wrote: This must be `Forum Oriented Programming`. It's our best hope. Self taught programming is scary. School taught prog

Re: function parameters: is it possible to pass byref ... while being optional at the same time ?

2021-07-17 Thread Ali Çehreli via Digitalmars-d-learn
On 7/17/21 6:49 PM, Brian Tiffin wrote: > *Practice makes perfect? No, practice makes permanent.* One reference for that quote is "Classical Guitar Pedagogy" by Anthony Glise, Chapter Nine--Practicing. ;) Ali

Re: interface function member declarations needing parameter attributes ?

2021-07-17 Thread someone via Digitalmars-d-learn
On Saturday, 17 July 2021 at 21:01:00 UTC, Adam Ruppe wrote: From the interface perspective: are these signatures identical or not ? No, they are very different. This helped me solve an issue that I carried since a few days ago: I have an interface with function members *not* being declared

Re: function parameters: is it possible to pass byref ... while being optional at the same time ?

2021-07-17 Thread someone via Digitalmars-d-learn
On Sunday, 18 July 2021 at 01:49:11 UTC, Brian Tiffin wrote: It's our best hope. Self taught programming is scary. School taught programming is scary. Corporate taught programming is scary. *Practice makes perfect? No, practice makes permanent.* The sanest path forward for the profession

Re: function parameters: is it possible to pass byref ... while being optional at the same time ?

2021-07-17 Thread Ali Çehreli via Digitalmars-d-learn
On 7/17/21 8:52 PM, someone wrote: > I am a self-taught programmer Same here. > well before college Not here because I had access to a Sinclair Spectrum only in 1985. :/ > I have a degree in electronics engineering Same here. > one of the things that I felt in love with when I was first exp