zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: [PATCH] Fix crash on unset-through-nameref
Date: Wed, 6 Mar 2024 11:37:42 -0800	[thread overview]
Message-ID: <CAH+w=7Y6VAq37y58ifgk4sWF5=8Xcyq-2U6QVr+YWJdHdVZe4w@mail.gmail.com> (raw)
In-Reply-To: <CAH+w=7YFADxa=JqYr1i1U=OmxpJsf5fs+uz1BFk1ExLPZc20TA@mail.gmail.com>

On Wed, Mar 6, 2024 at 11:17 AM Bart Schaefer <schaefer@brasslantern.com> wrote:
>
> assign() {
>   typeset -g $1
>   typeset -nu var=$1
>   local value=$2
>   var=$value
> }

Of course there's also no reason to write that specific function that
way.  You can simply do

assign() {
  unset $1
  typeset -g $1=$2
}

The reason for using a named reference would be when you're going do
more things with $var and $value than just assign them, such as
calling another function, or when you want to do something like

append() {
  typeset -nu var=$1
  local value=$2
  # Maybe do something else to $value ?  Then:
  var+=$value
}

Mostly because "typeset" doesn't understand += syntax.


  reply	other threads:[~2024-03-06 19:38 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-04  5:37 Bart Schaefer
2024-03-04  6:29 ` Stephane Chazelas
2024-03-04  8:39   ` Bart Schaefer
2024-03-04 19:34     ` Stephane Chazelas
2024-03-04 19:36       ` Stephane Chazelas
2024-03-04 23:50         ` Bart Schaefer
2024-03-05  8:36           ` Stephane Chazelas
2024-03-04 23:18       ` Bart Schaefer
2024-03-05  8:18         ` Stephane Chazelas
2024-03-05 18:42           ` Bart Schaefer
2024-03-05 19:38             ` Stephane Chazelas
2024-03-05 23:16               ` Bart Schaefer
2024-03-06 18:21                 ` Stephane Chazelas
2024-03-06 19:17                   ` Bart Schaefer
2024-03-06 19:37                     ` Bart Schaefer [this message]
2024-03-05 19:48             ` unset, POSIX and the export attribute (Was: [PATCH] Fix crash on unset-through-nameref) Stephane Chazelas
2024-03-05 19:51             ` [PATCH] Fix crash on unset-through-nameref Stephane Chazelas

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=7Y6VAq37y58ifgk4sWF5=8Xcyq-2U6QVr+YWJdHdVZe4w@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).