Array as an argument, ambiguous behaviour.
Sergei Nosov
sergei.nosov at gmail.com
Wed Jan 29 07:31:40 PST 2014
On Wednesday, 29 January 2014 at 15:11:33 UTC, Cooler wrote:
>> Yes, that is how slices work in D. The following article
>> explains the "non-determinism" that you mention:
>>
>> http://dlang.org/d-array-article.html
>>
>> Ali
>
> Thank you for the article.
> Quotation from the article "It is a good idea to note in the
> documentation how the passed in slice might or might not be
> overwritten."
> May be just prohibit at language level the case of fun3()
> function, to do not allow unpredictable behavior?
This behavior is just a consequence of the deliberate decision on
how arrays should be implemented.
Any decision would be a trade-off. Like, if you just disallow
this signature, you will have to use .dup at the caller side if
you want the semantics of fun3. And often this copy might be
unnecessary.
It's really like a ball under the carpet. You make it flat in one
place, but the ball pops up in the other.
The trade-off that D chooses is pretty reasonable. You just have
to accept that and get used to it.
More information about the Digitalmars-d-learn
mailing list