zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Jun T <takimoto-j@kba.biglobe.ne.jp>
Cc: zsh-workers@zsh.org
Subject: Re: a few question about named reference
Date: Wed, 12 Jul 2023 23:12:38 -0700	[thread overview]
Message-ID: <CAH+w=7bT_i8K+znzeJHNGohqw8evVmgGxcrjkC6gNyR8Emq5tg@mail.gmail.com> (raw)
In-Reply-To: <083477A3-A5D3-49B1-BF6F-D148C6BCAA54@kba.biglobe.ne.jp>

On Wed, Jul 12, 2023 at 9:06 PM Jun T <takimoto-j@kba.biglobe.ne.jp> wrote:
>
> [1] what does 'typeset -n ref' do when a variable 'ref' already exists?

As of workers/51402, it does the same thing as
  ref=xx
  typeset -n ref

So ...

> (1a) removing a named reference
>
>        ... so  to  remove  a
>        named reference, use either `unset -n pname' or one of:
>               typeset -n pname
>               typeset +n pname
>        followed by
>               unset pname
>
> But:
> % typeset -n pname     # this does nothing
> % typeset -p pname
> typeset -n pname=i     # still points to i
[...]
>
> Just fix the document?

Yep, documentation dates from the previous patches.  Need to update.

> (1b) converting a scalar into named reference
>
> In the first post by Bart about the named reference (worker/51360⁩):
>
> > One difference from ksh93 is that you can't convert scalars into
> > namerefs
>
> But it seems we can convert a scalar into nameref:

That also changed in 51402, from the commit log:

    * Ksh-style "foo=bar; typeset -n foo" creates foo=bar reference

> [2] readonly named reference
>
> So we can't remove the readonly attribute (and will not be able
> to remove/unset it). Is this intentional?

Yes, that's how it works in ksh.

> [3] can named reference be in 'unset' state?
>
> It seems resolve_nameref() in params.c resets the PM_UNSET bit.
> I feel it would be simpler to ignore typesettounset when creating
> a nameref.

That will need to be looked at.  Thanks for noticing.


  reply	other threads:[~2023-07-13  6:13 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-13  4:05 Jun T
2023-07-13  6:12 ` Bart Schaefer [this message]
2023-07-16  5:09   ` Jun T
2023-07-16 17:15     ` 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=7bT_i8K+znzeJHNGohqw8evVmgGxcrjkC6gNyR8Emq5tg@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=takimoto-j@kba.biglobe.ne.jp \
    --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).