Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm
Precedence: bulk
X-No-Archive: yes
List-Id: Zsh Workers List <zsh-workers.zsh.org>
List-Post: <mailto:zsh-workers@zsh.org>
List-Help: <mailto:zsh-workers-help@zsh.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au
X-Spam-Level: 
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM
	autolearn=ham autolearn_force=no version=3.4.0
Subject: Re: Printf builtin missing v flag support
To: zsh-workers@zsh.org
References: <068ca8f5-315b-444c-b281-5f183e1daa8c@email.android.com>
 <151231104858.ZM24513@torch.brasslantern.com>
From: Eric Cook <llua@gmx.com>
X-Enigmail-Draft-Status: N1110
Message-ID: <5686F643.1060707@gmx.com>
Date: Fri, 1 Jan 2016 16:57:23 -0500
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101
 Thunderbird/38.5.0
MIME-Version: 1.0
In-Reply-To: <151231104858.ZM24513@torch.brasslantern.com>
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
X-Provags-ID: V03:K0:cVaIUnnGQfmNYWDZ5N/e48kjmBIDVVo2d4ZhsMe0b+WvurZ+jy+
 EUpKKlWcnPTWyEgrwoxAtUx7qAfk9TLJCfFvhJEjOj/vb5zJ77bJFW7KCDog6gnQ7tWEAM9
 OrVStDOoy73TVZBXfvUyY/EzAk+i6J+EqSaiq12ca86oPk3sHQIC5einQuHx/UsUVVflIP7
 pYbi1UgvnydTkvdeyHXRg==
X-UI-Out-Filterresults: notjunk:1;V01:K0:MZOldKGWjBg=:a1MfqeBlBcCKMkmRb04nSG
 37JGLhKzgsKy1ZAz9jxtFZELFA2ni5gNEUcEn9g5AF2ZHLcsNCYLoCUrOVhE0cSlm7AdFrVBt
 NSKFnj6cGTkc/A0e5ODAgumOlOaQsUSobV4xuk4nZeIory+fu9dJ9ZEnJfXGUHM8pa4XlcEUH
 ZcCy+wKm2A3WTXZIj2lCMyaluUAtE2oqIlSHGq1yBOy5d513wbQt0dG/Y57s86FN0d/4nrEHq
 okNIyuzFhkZltDYr9hIWagKlJAxTaHRX2XZtSWxcuafyI3iF06J5L117KIf5+7dsqEEGsQR6v
 NQuZCks/0mrxd8Ulx65yC4HNRi06qpF5wjMTuKGOHQvGJ9NIN0OldnLKRNyvZaYvdvmvtj1kS
 E4C5upT2O8YUTTrjzzEpLI8Vunm5q09yDTy71eH/be3M/n/PZHKafNbFLoEd/yGARlVEckJ0V
 79xPPac3aZ0obgaAVum0tb9KP6tsG2DvEWmyxIXLmx9kZkjvMvYFHVZ9cRm2X2qGUnVjrtqfp
 PLoWIay1kuLf7B7+RHl4C24oIk75Xn8RoHn9mJSJ/jj9paAGGrddopMkMAq8jOxVpPzxnlh0W
 QSiiq24OH6t+iUodbZYnUt5SQNm8ugpUoJRwX4kquT0IfpOzJ4XeK9nFauQi+bbzmQoSW4BqO
 vgx4qrcirGXY4MnQz9WQjznUnHe0aH7jNgovNfccjhjufmP+0uaLW5nu93R9pPoXvspv97Ilh
 yXgh6P13Cg02zMLJfTIJqP8AFu7vXhfs1rp0MMYbJs4EQJEvaEJYg+1DPcDclFfo90hGhFuhU
 l9LUCpl
X-Seq: zsh-workers 37480

On 12/31/2015 01:48 PM, Bart Schaefer wrote:
> On Dec 31, 10:44am, Peter Stephenson wrote:
> }
> } The feature is obviously useful but the print implementation is
> } a nightmare of special cases making it hard to change without
> } considerable refactoring. That would probably be a Good Work, given
> } enough test cases to check it, but is going to have to wait for a
> } volunteer.
> }
> } I haven't checked whether -v is already in use in which case this is moot.
> 
> -v is not in use, and the print implementation has already been refactored
> to support the -z and -s options in printf, so this is actually rather
> easy.
> 
> I noticed that "print" uses metafy() on the aguments to -z and -s, but
> "printf" did not, so I added metafy() for those cases.  Somebody holler
> if this is wrong.
> 
> 

Could zsh error when an invalid parameter name is used?

% printf -v -- '%s' foo
-v%
% printf -v '%s' foo
-v%
% printf -v
-v%

$ printf -v -- '%s' foo
bash: printf: `--': not a valid identifier
$ printf -v '%s' foo
bash: printf: `%s': not a valid identifier
$ printf -v
bash: printf: -v: option requires an argument
printf: usage: printf [-v var] format [arguments]

bash's printf -v can also assign to array elements, which isn't possible currently.

% typeset -A foo; printf -v 'foo[bar]' baz; typeset -p foo
-vtypeset -A foo

% printf -v 'a[2+2]' foo; typeset -p a
foo=( )

$ typeset -A foo; printf -v 'foo[bar]' baz; typeset -p foo
declare -A foo='([bar]="baz" )'
$ printf -v 'a[2+2]' foo; typeset -p a
declare -a a='([4]="foo")'

