Irek Szczesniak
2013-09-12 16:31:22 UTC
On Thu, Jul 11, 2013 at 9:48 AM, Cedric Blancher
as an array so the intuitive feeling would be that a=() resets it with
an empty array. 2nd your interpretation assumes that the called
function knows the array data type to reset it - which becomes a pain
if you have hundreds of types defined and try to use a utility
function which should reset an array of any of these types.
I'd better go for: a=() means reset the variable if variable a is
either array or compound. If it isn't already a type of these make it
a compound variable. If variable a is of type integer or string throw
an error.
This should make things more predictable.
Right... I agree with Cedric. It makes IMO more sense that $ a=() #
declares "a" a compound variable if variable "a" wasn't declared yet
but if variable "a" was declared as an array then $ a=() # should
empty/clear the array and not re-declare it as compound variable (see
Cedrics argumentation about user-defined types vs. helper functions...
the current behaviour would require that we have to resort to
something extract the type of the variable and then use "eval" to
clear the array).
The alternative would be to add a new option ("-c") to clear a
variable, e.g. $ typeset -a ar ; ... ; unset -c ar # clears an array,
$ compound c ; ... ; unset -c c # does the same for a compound
variable etc.
(Slightly) offtopic: How can I clear a plain string array (e.g. $
typeset -a ar #) via the C API (without having to resort to
|sh_trap()| to do it...) ?
What happened to the unset -c proposal to "clear" a variable, e.g.cc: ast-users at research.att.com
--------
a=()
doesn't clear an array, it unsets a and creates an empty compound variable
(
)
typeset -a a=()
should clear an array.
This is not very intuitive. First variable a has already be declared--------
a=()
doesn't clear an array, it unsets a and creates an empty compound variable
(
)
typeset -a a=()
should clear an array.
as an array so the intuitive feeling would be that a=() resets it with
an empty array. 2nd your interpretation assumes that the called
function knows the array data type to reset it - which becomes a pain
if you have hundreds of types defined and try to use a utility
function which should reset an array of any of these types.
I'd better go for: a=() means reset the variable if variable a is
either array or compound. If it isn't already a type of these make it
a compound variable. If variable a is of type integer or string throw
an error.
This should make things more predictable.
declares "a" a compound variable if variable "a" wasn't declared yet
but if variable "a" was declared as an array then $ a=() # should
empty/clear the array and not re-declare it as compound variable (see
Cedrics argumentation about user-defined types vs. helper functions...
the current behaviour would require that we have to resort to
something extract the type of the variable and then use "eval" to
clear the array).
The alternative would be to add a new option ("-c") to clear a
variable, e.g. $ typeset -a ar ; ... ; unset -c ar # clears an array,
$ compound c ; ... ; unset -c c # does the same for a compound
variable etc.
(Slightly) offtopic: How can I clear a plain string array (e.g. $
typeset -a ar #) via the C API (without having to resort to
|sh_trap()| to do it...) ?
reset an array/type to its default values?
Technically we're more interested in a nv_clear_array() library
function to do the same via libshell API for our builtins, but a
generic unset(1) option would do it too.
Irek