From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 10057 invoked from network); 12 Feb 2023 09:04:13 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 12 Feb 2023 09:04:13 -0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Message-ID:Date:Content-ID: Content-Type:MIME-Version:Subject:To:References:From:In-reply-to:cc:Reply-To: Content-Transfer-Encoding:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=qjfTgoomdWTYwh6OvmxKSeOfR+VTkX0S34Q6iZ9Udkc=; b=fJ2xn+7lkRzPsbSKts9/YKh5Wj 5lnSFtL7Grs5RyCL3KJIDMWiCz6MiuVl7UrDH+FoST9eyfanl49rqwzXknDZA+gmD2pbgze4+9Gb6 6iM85AqofEajQiBpeifW17hCEeTmBTT3YgqEr/qfkpMZp9ZmXb1bwRVfSORhFAz5tbWAzxiz8X+3O FDcb3I707wixmxXck+/SZyb+W7ri0MkImtx3emY8TdIohJKL2GmNe7D5EMArSSZIAm10Ue4TdtZ6K AKpJxhuN5IQ2jjgm9cDYbFj/zQU6a83WrplAUc/4WtC4CT+rMJ1dgJazYwifxzQOPIwjj2yuEnbIM sMpmvRKw==; Received: by zero.zsh.org with local id 1pR8HN-000Mh8-1Z; Sun, 12 Feb 2023 09:04:13 +0000 Received: by zero.zsh.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1pR8FI-000MJk-8h; Sun, 12 Feb 2023 09:02:04 +0000 Received: from [192.168.178.21] (helo=hydra) by mail.kiddle.eu with esmtp(Exim 4.95) (envelope-from ) id 1pR8FH-000OTd-S2; Sun, 12 Feb 2023 10:02:04 +0100 cc: Zsh hackers list In-reply-to: From: Oliver Kiddle References: <67689-1675827940.088548@BxvG.D9_b.7RzI> <12608-1675903622.800470@Xj82.e3y1.svhG> <66045-1675975796.128039@FBF_.0yMO.Y8fk> To: Bart Schaefer Subject: Re: [PATCH 1/3]: Add named references MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <94091.1676192523.1@hydra> Date: Sun, 12 Feb 2023 10:02:03 +0100 Message-ID: <94092-1676192523.865597@yGHQ.rexg.4E4Z> X-Seq: 51410 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: On 9 Feb, Bart Schaefer wrote (I've reordered this): > > This should be an error perhaps: > > > > typeset -n ref=arr[1][2] > > Why? ${ary[1][2]} isn't an error, it's the 2nd character of the first > word in $ary. Sorry, should have been clearer. Applying later subscripts is even better than an error but the following is not ideal: % arr=( one two three ) % typeset -n ref=arr[2][1] % echo $ref two[1] % ref=x % typeset -p arr typeset -a arr=( one x three ) % echo $ref x[1] % typeset -n ref=arr[1]whatever % echo $ref onewhatever > Yeah, I don't like the idea that a called function can arbitrarily > grab parameters from its caller just by sticking & in front. Caller > needs to do do something (even if only make "normal" use of dynamic > scope) to make the parameter "grabbable". Allowing such things as uplevel statements (Tcl), special syntax, or introspection modules (Python's inspect), is fairly normal for a scripting language. As I've mentioned, we already have the situation where the caller needs nothing to make a private grabable by a builtin: private -a var compadd -O var one two three And writing wrappers to e.g. compadd is useful. But I don't think we need to address references to privates in other scopes at this point before the other patches are even applied. May be better to consider whether there are other advantages in moving private to the main shell first as that may ease any implementation. > > > typeset -n ref > > > for ref in 'hash[(e)'${(k)^hash[(R)?*]}']'; do ... > > > > "just"!? > > Hah! Point was that it's do-able without "for"-context-sensitive > special subscript semantics. I think it would be strange for I can't think of a sensible way. Was just that it could be useful. Best long term solution might be to allow arrays of references. Bash does allow arrays of integers. > The others would all have to be special-cased individually. What is > $+ ? Do you mean $- ? Yes. Oliver