Re: Thinking about the difference between fixed and 'dynamic' arrays.

2022-12-05 Thread Stefan Koch via Digitalmars-d-learn
On Sunday, 4 December 2022 at 09:54:53 UTC, Salih Dincer wrote: Recently DIP1044 was published about enum and although we can use `with()` instead we waste time unnecessarily... With cannot be used in calls. Hence when calling a function you need to either spell out the enum type or wrap the c

Re: Thinking about the difference between fixed and 'dynamic' arrays.

2022-12-04 Thread Salih Dincer via Digitalmars-d-learn
On Wednesday, 30 November 2022 at 03:04:47 UTC, Basile B. wrote: I have implemented that in [styx](https://gitlab.com/styx-lang/styx). 1. You have the type for dynamic arrays, called TypeRcArray, syntax is `Type[+]` 2. You have the type for slices (what you describe as a window), syntax is

Re: Thinking about the difference between fixed and 'dynamic' arrays.

2022-12-03 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 3 December 2022 at 22:46:31 UTC, DLearner wrote: I agree should not change existing meaning of ``` int[] A; ``` But why not allow a construct for value-type variable arrays like: ``` int[*] B; ``` There's no reason to add more complexity to the language for this when the same r

Re: Thinking about the difference between fixed and 'dynamic' arrays.

2022-12-03 Thread DLearner via Digitalmars-d-learn
On Wednesday, 30 November 2022 at 02:29:03 UTC, Paul Backus wrote: [...] If you want a dynamic array with value semantics, you should use a library-defined container type (e.g., `struct DynamicArray`). I agree should not change existing meaning of ``` int[] A; ``` But why not allow a const

Re: Thinking about the difference between fixed and 'dynamic' arrays.

2022-11-30 Thread Ali Çehreli via Digitalmars-d-learn
On 11/29/22 15:25, DLearner wrote: > 'dynamic array' is > not a reasonable description for a construct that behaves like > VarArr2[3] becoming 40. I agree with you: It has always bothered me to call the following a dynamic array: int[] arr; 'arr' is not a dynamic array but the slice interf

Re: Thinking about the difference between fixed and 'dynamic' arrays.

2022-11-30 Thread Basile.B via Digitalmars-d-learn
On Wednesday, 30 November 2022 at 03:04:47 UTC, Basile B. wrote: Essentially slices are only useful to be consumed locally, typically ```d while mySlice.length do { slice = slice[1..$]; } ``` sorry I cant force push, it was obviously meant to be written as ```d while mySlice.length do {

Re: Thinking about the difference between fixed and 'dynamic' arrays.

2022-11-29 Thread Basile B. via Digitalmars-d-learn
On Tuesday, 29 November 2022 at 18:59:46 UTC, DLearner wrote: To me, it appears that there are really two (_entirely separate_) concepts: A. Supporting the useful concept of variable length (but otherwise entirely conventional) arrays; B. Supporting a language feature that acts as a window to

Re: Thinking about the difference between fixed and 'dynamic' arrays.

2022-11-29 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 29 November 2022 at 18:59:46 UTC, DLearner wrote: To me, it appears that there are really two (_entirely separate_) concepts: A. Supporting the useful concept of variable length (but otherwise entirely conventional) arrays; B. Supporting a language feature that acts as a window to

Re: Thinking about the difference between fixed and 'dynamic' arrays.

2022-11-29 Thread Vladimir Panteleev via Digitalmars-d-learn
On Wednesday, 30 November 2022 at 01:53:10 UTC, Siarhei Siamashka wrote: Rust also appears to be picky about the order of operations: ```Rust fn main() { let mut a = [1, 2, 3, 4, 5]; let c = a; let b = &mut a; b[1] = 99; println!("{:?}", b); // [1, 99, 3, 4, 5] print

Re: Thinking about the difference between fixed and 'dynamic' arrays.

2022-11-29 Thread Siarhei Siamashka via Digitalmars-d-learn
On Wednesday, 30 November 2022 at 00:40:57 UTC, Vladimir Panteleev wrote: On Tuesday, 29 November 2022 at 18:59:46 UTC, DLearner wrote: Suggestion: it would be clearer if the two concepts were separated: 1. Convert 'int[] VarArr;' so it produces a straightforward _value-type_ variable array, ca

Re: Thinking about the difference between fixed and 'dynamic' arrays.

2022-11-29 Thread Siarhei Siamashka via Digitalmars-d-learn
On Tuesday, 29 November 2022 at 23:25:46 UTC, DLearner wrote: Many languages also have variable length arrays, I suggest D's 'dynamic array' _does not_ operate as expected. I'm not suggesting that the result contradicts D's definition of 'dynamic array', nor it's implementation, just that 'dynam

Re: Thinking about the difference between fixed and 'dynamic' arrays.

2022-11-29 Thread Vladimir Panteleev via Digitalmars-d-learn
On Wednesday, 30 November 2022 at 00:40:57 UTC, Vladimir Panteleev wrote: On Tuesday, 29 November 2022 at 18:59:46 UTC, DLearner wrote: Suggestion: it would be clearer if the two concepts were separated: 1. Convert 'int[] VarArr;' so it produces a straightforward _value-type_ variable array, ca

Re: Thinking about the difference between fixed and 'dynamic' arrays.

2022-11-29 Thread Vladimir Panteleev via Digitalmars-d-learn
On Tuesday, 29 November 2022 at 18:59:46 UTC, DLearner wrote: Suggestion: it would be clearer if the two concepts were separated: 1. Convert 'int[] VarArr;' so it produces a straightforward _value-type_ variable array, called 'VarArr'; 2. Implement a new concept 'int slice Window;' to produce an

Re: Thinking about the difference between fixed and 'dynamic' arrays.

2022-11-29 Thread matheus via Digitalmars-d-learn
On Tuesday, 29 November 2022 at 23:25:46 UTC, DLearner wrote: On Tuesday, 29 November 2022 at 19:06:20 UTC, rikki cattermole wrote: [...] Please see the following example: ... I think this was discussed before a few weeks ago here (But I don't remember the thread), and this is a design choic

Re: Thinking about the difference between fixed and 'dynamic' arrays.

2022-11-29 Thread DLearner via Digitalmars-d-learn
On Tuesday, 29 November 2022 at 19:06:20 UTC, rikki cattermole wrote: [...] Please see the following example: ``` void main() { import std.stdio; int[] VarArr1, VarArr2; VarArr1.length = 6; VarArr1[5] = 10; VarArr1[4] = 9; VarArr1[3] = 8; VarArr1[2] = 7; VarArr1[1] = 6

Re: Thinking about the difference between fixed and 'dynamic' arrays.

2022-11-29 Thread rikki cattermole via Digitalmars-d-learn
Okay you have misunderstand a lot here. We have two types of arrays: - Static, fixed sized stored on stack. - Dynamic, variable sized, stored on the heap. However dynamic arrays are not actually a distinct type in the type system, its a language extension to use runtime hooks using the GC. W