zsh-workers
 help / color / mirror / code / Atom feed
* [doogie@debian.org: Bug#163391: unset array[key] where key is non-existent doesn't fail]
@ 2002-10-05 17:31 Clint Adams
  2002-10-05 19:52 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Clint Adams @ 2002-10-05 17:31 UTC (permalink / raw)
  To: zsh-workers; +Cc: 163391-forwarded

I'm not sure to what "contract" he's referring, but SUSv3 says

  Unsetting a variable or function that was not previously set shall not
  be considered an error and does not cause the shell to abort.

and that unset should return a >0 exit status if any of the "name"
operands cannot be unset.

Of course, it knows nothing about associative arrays.

----- Forwarded message from Adam Heath <doogie@debian.org> -----

bash-2.05b$ zsh -c 'unset non_existant_var && echo error || echo
correct; unset "array[1]" && echo error || echo correct; declare -A
aarray; unset "aarray[foo]" && echo error || echo correct'
correct
correct
error

The contract for unset says that if the variable being unset doesn't exist, an
error is returned.  As shown above, variables and normal arrays behave as
expected, but associative arrays do not.

----- End forwarded message -----


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [doogie@debian.org: Bug#163391: unset array[key] where key is non-existent doesn't fail]
  2002-10-05 17:31 [doogie@debian.org: Bug#163391: unset array[key] where key is non-existent doesn't fail] Clint Adams
@ 2002-10-05 19:52 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2002-10-05 19:52 UTC (permalink / raw)
  To: Clint Adams, zsh-workers; +Cc: 163391-forwarded

On Oct 5,  1:31pm, Clint Adams wrote:
}
} I'm not sure to what "contract" he's referring, but SUSv3 says
} 
}   Unsetting a variable or function that was not previously set shall not
}   be considered an error and does not cause the shell to abort.
} 
} and that unset should return a >0 exit status if any of the "name"
} operands cannot be unset.
} 
} Of course, it knows nothing about associative arrays.

Exactly.  The variable "aarray" WAS previously set (by "declare -A").
The fact that a particular hash key was not assigned-to is irrelevant.

zsh -c 'typeset non_existant_var;
	unset non_existant_var && echo consistent || echo inconsistent'

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-10-05 19:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-05 17:31 [doogie@debian.org: Bug#163391: unset array[key] where key is non-existent doesn't fail] Clint Adams
2002-10-05 19:52 ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).