Re: Send empty assoc array to function

2020-07-10 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/10/20 4:15 AM, Max Samukha wrote: On Thursday, 9 July 2020 at 21:04:57 UTC, Steven Schveighoffer wrote: Why isn't [] accepted as an empty AA literal? Because it's an empty dynamic array literal. If D were to accept an empty AA literal, I'd expect it to be [:]. Just as typeof(null)

Re: Send empty assoc array to function

2020-07-10 Thread JN via Digitalmars-d-learn
On Friday, 10 July 2020 at 03:59:37 UTC, Mike Parker wrote: Meh. You could say the same about foo(int[]), or foo(SomeClass). AAs are reference types. Reference type instances can be null. Oh, that actually makes sense. I always thought assoc arrays are value types. Anyway, even if they are

Re: Send empty assoc array to function

2020-07-10 Thread Max Samukha via Digitalmars-d-learn
On Friday, 10 July 2020 at 08:15:24 UTC, Max Samukha wrote: a unfortunate an unfortunate

Re: Send empty assoc array to function

2020-07-10 Thread Max Samukha via Digitalmars-d-learn
On Thursday, 9 July 2020 at 21:04:57 UTC, Steven Schveighoffer wrote: Why isn't [] accepted as an empty AA literal? Because it's an empty dynamic array literal. If D were to accept an empty AA literal, I'd expect it to be [:]. -Steve Just as typeof(null) is a subtype of all nullable

Re: Send empty assoc array to function

2020-07-09 Thread Mike Parker via Digitalmars-d-learn
On Friday, 10 July 2020 at 03:59:37 UTC, Mike Parker wrote: On Thursday, 9 July 2020 at 21:13:49 UTC, JN wrote: Interesting. Often in D discussion, an argument pops up that the language should be protecting against hidden breakages from API changes. This would be an example of that

Re: Send empty assoc array to function

2020-07-09 Thread Mike Parker via Digitalmars-d-learn
On Thursday, 9 July 2020 at 21:13:49 UTC, JN wrote: Interesting. Often in D discussion, an argument pops up that the language should be protecting against hidden breakages from API changes. This would be an example of that happening. void foo(int[int] bar), someone calls it with a null,

Re: Send empty assoc array to function

2020-07-09 Thread Jesse Phillips via Digitalmars-d-learn
On Thursday, 9 July 2020 at 20:08:47 UTC, Anonymouse wrote: On Thursday, 9 July 2020 at 19:53:42 UTC, JN wrote: void foo(int[int] bar) { // ... } Is it possible to send an empty array literal? foo( [ 0 : 2 ] ) works foo( [] ) doesn't int[int] empty; foo(empty); works but it's two lines

Re: Send empty assoc array to function

2020-07-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/9/20 5:13 PM, JN wrote: On Thursday, 9 July 2020 at 20:24:11 UTC, Steven Schveighoffer wrote: On 7/9/20 4:04 PM, JN wrote: Hmm, foo(null) seems to work, but is it correct way to do it? Yes, that is correct. Interesting. Often in D discussion, an argument pops up that the language

Re: Send empty assoc array to function

2020-07-09 Thread JN via Digitalmars-d-learn
On Thursday, 9 July 2020 at 20:24:11 UTC, Steven Schveighoffer wrote: On 7/9/20 4:04 PM, JN wrote: On Thursday, 9 July 2020 at 19:53:42 UTC, JN wrote: void foo(int[int] bar) {     // ... } Is it possible to send an empty array literal? foo( [ 0 : 2 ] ) works foo( [] ) doesn't int[int]

Re: Send empty assoc array to function

2020-07-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/9/20 4:31 PM, Max Samukha wrote: On Thursday, 9 July 2020 at 20:24:11 UTC, Steven Schveighoffer wrote: Yes, that is correct. Why isn't [] accepted as an empty AA literal? Because it's an empty dynamic array literal. If D were to accept an empty AA literal, I'd expect it to be [:].

Re: Send empty assoc array to function

2020-07-09 Thread Max Samukha via Digitalmars-d-learn
On Thursday, 9 July 2020 at 20:24:11 UTC, Steven Schveighoffer wrote: Yes, that is correct. -Steve Why isn't [] accepted as an empty AA literal?

Re: Send empty assoc array to function

2020-07-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/9/20 4:04 PM, JN wrote: On Thursday, 9 July 2020 at 19:53:42 UTC, JN wrote: void foo(int[int] bar) {     // ... } Is it possible to send an empty array literal? foo( [ 0 : 2 ] ) works foo( [] ) doesn't int[int] empty; foo(empty); works but it's two lines Hmm, foo(null) seems to

Re: Send empty assoc array to function

2020-07-09 Thread Anonymouse via Digitalmars-d-learn
On Thursday, 9 July 2020 at 19:53:42 UTC, JN wrote: void foo(int[int] bar) { // ... } Is it possible to send an empty array literal? foo( [ 0 : 2 ] ) works foo( [] ) doesn't int[int] empty; foo(empty); works but it's two lines I always did foo((int[int]).init);

Re: Send empty assoc array to function

2020-07-09 Thread Max Samukha via Digitalmars-d-learn
On Thursday, 9 July 2020 at 19:53:42 UTC, JN wrote: foo( [] ) doesn't Should work in principle, but you can foo(null) to work around.

Re: Send empty assoc array to function

2020-07-09 Thread JN via Digitalmars-d-learn
On Thursday, 9 July 2020 at 19:53:42 UTC, JN wrote: void foo(int[int] bar) { // ... } Is it possible to send an empty array literal? foo( [ 0 : 2 ] ) works foo( [] ) doesn't int[int] empty; foo(empty); works but it's two lines Hmm, foo(null) seems to work, but is it correct way to do