Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: workers/40626 (commit 6c476c22) causes multiple test failures



Bart Schaefer wrote on Tue, Feb 28, 2017 at 11:04:24 -0800:
> On Feb 28,  5:03pm, Daniel Shahaf wrote:
> }
> } > So here's my question ... why would you ever attempt to append to the
> } > options parameter, empty append or otherwise?
> } 
> } To set multiple options at once:
> } 
> }     local -a options_to_set=( printexitvalue on warncreateglobal off )
> }     options+=( $options_to_set )
> 
> My point is you don't need append for that.
> 
>     options=( $options_to_set )
> 
> will do exactly the same thing, because it's not possible to delete any
> of the hash keys even if you don't appear to be assigning them.

I noticed that they're equivalent, but I think it's more readable to use
+= when setting values of some options and = when setting values of all
options.  That's because using = without specifying all options violates
the following invariant of hashes:

    local -a a=(...)
    local -A hash=( $a )
    (( $#a == $#hash ))

I suppose that's an argument in favour of turning "using = without
specifying all options on the RHS" into a runtime error. :-)

Jokes aside, backwards compatibility argues that we should make neither
case an error.

Cheers,

Daniel



Messages sorted by: Reverse Date, Date, Thread, Author