zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: "typeset -p" and no_GLOBAL_EXPORT, other misc.
Date: Tue, 12 Mar 2024 11:32:41 -0700	[thread overview]
Message-ID: <CAH+w=7Z40c_8k1FHra0K9iQvih=4LZmS-pkx06o_CiDf0wTJJQ@mail.gmail.com> (raw)
In-Reply-To: <20240312084926.d6vbk75ozud7i2jm@chazelas.org>

On Tue, Mar 12, 2024 at 1:49 AM Stephane Chazelas <stephane@chazelas.org> wrote:
>
> IMO, typeset -g should only mean: don't make it local, do not
> instantiate a new variable in the current scope.

As I think I mentioned elsewhere, zsh's "typeset -g" (in the absence
of -p) only applies to newly instantiated parameters -- it will still
find parameters in the current (or enclosing) scope if they already
exist.  Which typically means it creates a parameter in the outermost
scope, but I suppose also answers some of my other questions, e.g., +p
-g should still find everything including locals and is not
necessarily equivalent to -p +g.

> bash-5.3$ f() { local i; integer i=2+2; echo "$i"; }
> bash-5.3$ f
>
> bash-5.3$ echo $i
> 4
>
> That "integer" changed the type of the global (outer-most) i
> variable instead of that of its caller.

Looks like "integer" et al. in bash actually search for the parameter
using the type (which corresponds to what zsh attempts to do when
using -p), rather searching for the parameter name and then altering
the type (which zsh without my patch sometimes does by accident).

Does it always use outermost scope or does it just use the "nearest"
integer (in this example) that it finds?

> In zsh, readonly var, when not emulating other shells is more
> like typeset -r:

It should in fact be exactly like "typeset -r", and export should be
exactly like "typeset +x".

> ksh93 does static scoping

As someone else pointed out elsewhere, this depends on whether you do
  foo() { ...; }
or
  function foo { ...; }
but really, I don't care, as we don't emulate this bit anyway.

Aside:  Shouldn't IGNORE_CLOSE_BRACES be set in ksh emulation?  It
currently is not.


  reply	other threads:[~2024-03-12 18:33 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-12  4:13 Bart Schaefer
2024-03-12  8:49 ` Stephane Chazelas
2024-03-12 18:32   ` Bart Schaefer [this message]
2024-03-12 20:06     ` Stephane Chazelas
2024-03-12 20:31       ` Bart Schaefer
2024-03-12 20:48         ` Stephane Chazelas
2024-03-12 21:02         ` Bart Schaefer
2024-03-12 20:26     ` Stephane Chazelas
2024-03-12 20:38       ` Bart Schaefer
2024-03-12 20:58         ` Stephane Chazelas
2024-03-12 21:03           ` Bart Schaefer
2024-03-13  0:52         ` {PATCH] (for real this time) " Bart Schaefer
2024-03-14  2:11         ` [PATCH] More "typeset -p" and GLOBAL_EXPORT Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAH+w=7Z40c_8k1FHra0K9iQvih=4LZmS-pkx06o_CiDf0wTJJQ@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).