trying to understand in, inout, and ref...
Paul Backus
snarwin at gmail.com
Wed Jan 22 14:23:53 UTC 2020
On Wednesday, 22 January 2020 at 10:49:07 UTC, mark wrote:
> Regarding generate(): allWords should never be changed
> (generate is called in a loop with the same allWords every
> time) -- so should it be `in WordSet allWords`?
For parameters that shouldn't be changed, use const. So it should
be `const WordSet allWords`.
> Regarding update(): ladder and words are both modified in
> update -- so should they be `ref WordList ladder` and `ref
> WordSet words`? And if so, do I need to change the update()
> call in the generate() function?
Yes, they should be `ref`. No, you do not have to change the
update() call.
> compatibles is (will be) modified in generate() but not in
> update(), so should it be `in WordSet compatibles`?
It should be `const WordSet compatibles`.
More information about the Digitalmars-d-learn
mailing list