On Thu, Jul 11, 2013 at 9:48 AM, Cedric Blancher
<[email protected]> wrote:
> On 10 July 2013 22:18, David Korn <[email protected]> wrote:
>> cc: [email protected]
>> Subject: Re: ksh93 returns "()" for "${a[@]}" if I clear an array with a=( )
>> --------
>>
>>> ksh93 returns "()" for "${a[@]}" if I clear an array with a=( )
>>
>> 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
> 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...) ?

----

Bye,
Roland

-- 
  __ .  . __
 (o.\ \/ /.o) [email protected]
  \__\/\/__/  MPEG specialist, C&&JAVA&&Sun&&Unix programmer
  /O /==\ O\  TEL +49 641 3992797
 (;O/ \/ \O;)
_______________________________________________
ast-users mailing list
[email protected]
http://lists.research.att.com/mailman/listinfo/ast-users

Reply via email to