How to update Associative Array?

Ali Çehreli acehreli at yahoo.com
Mon Feb 14 01:04:08 UTC 2022


On 2/13/22 05:58, kdevel wrote:
 > On Sunday, 13 February 2022 at 01:27:45 UTC, Ali Çehreli wrote:
 >> [...]
 >> > If I remove the constraint (the if-stuff) I get
 >> >
 >> >     v1.d(12): Error: cannot implicitly convert expression
 >> `kv.value()`
 >> > of type `byte` to `string`
 >> >     v1.d(23): Error: template instance
 >> `v1.update!(string[int],
 >> > byte[short])` error instantiating
 >>
 >> That's inferior because now the error message is pointing at the
 >> implementation of a library function and confuses everyone.
 >
 > It confuses me not really. (Function) templates are by their very nature
 > visible to the user and I got used to reading the implementations.

Point taken but how deep should we understand library code, not all 
being Phobos. My pet peeve:

import std.stdio;

void main(string[] args) {
   writefln!"hello"(42);
}

/usr/include/dlang/dmd/std/stdio.d(4442): Error: no property `msg` for 
type `string`

I am happy that it's caught at compile time but what 'msg' property are 
we talking about? What does it have to be with me?

I would like it if the

It would be better if the compilation error said:

   Must satify formatSpecsMatchArgs!("hello", int)

I am not sure whether it's practical or efficient at compile time.

 > The constraints appear artificial to me: Neither are there means which
 > ensure
 > that a list of Constraints is complete nor is it ensured that a list of
 > constraints is not overly restrictive.

Agreed.

 > It seems that these Constraints
 > constitute
 > another class of things which may get out of sync with the actual code
 > (besides program documentation, program comments and function names).

Agreed.

 >
 > Doesn't this re-iteration of what is already implicitly contained in the
 > line
 >
 >     target[kv.key] = kv.value;

I don't agree with that because there is no 'target', 'kv', etc. in the 
programmer's code. Should we really expect the programmers be 
programmers? :p

 > violate the DRY principle?

Agreed.

Ali



More information about the Digitalmars-d-learn mailing list